UP 模拟器
parent
eb2101c4d0
commit
678c8067b8
|
@ -23,7 +23,7 @@ void Refresh_Call(OLED_T *dev) {
|
|||
uint8_t oledbuf[8][128] = {0};
|
||||
|
||||
void Test_OLED() {
|
||||
SIM_OLED_INIT(0xFFFFFF, 0x0, 10, true);
|
||||
SIM_OLED_INIT(128, 64, 0xFFFFFF, 0x0, 10, 1);
|
||||
OLED_T oled = {
|
||||
.height=64,
|
||||
.width=128,
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
#include <conio.h>
|
||||
|
||||
static uint32_t pixelColor, backgroundColor;
|
||||
static int scaleFactor;
|
||||
static bool border;
|
||||
static int scaleFactor, w, h;
|
||||
uint8_t border;
|
||||
|
||||
void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool b) {
|
||||
void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b) {
|
||||
w = width * scale;
|
||||
h = height * scale;
|
||||
pixelColor = pixcolor;
|
||||
backgroundColor = backcolor;
|
||||
scaleFactor = scale;
|
||||
|
@ -14,10 +16,10 @@ void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool b) {
|
|||
}
|
||||
|
||||
void SIM_OLED_START() {
|
||||
initgraph(WIDTH, HEIGHT);
|
||||
setbkcolor(backgroundColor); // 设置背景色为黑色
|
||||
initgraph(w, h);
|
||||
setbkcolor(backgroundColor);
|
||||
setfillcolor(pixelColor);
|
||||
cleardevice(); // 清空屏幕
|
||||
cleardevice();
|
||||
}
|
||||
|
||||
void SIM_OLED_STOP() {
|
||||
|
@ -25,13 +27,11 @@ void SIM_OLED_STOP() {
|
|||
closegraph();
|
||||
}
|
||||
|
||||
void drawOledPixel(int oledX, int oledY, int blockSize) {
|
||||
int startX = oledX * blockSize;
|
||||
int startY = oledY * blockSize;
|
||||
if (border)
|
||||
fillrectangle(startX, startY, startX + blockSize, startY + blockSize);
|
||||
if (!border)
|
||||
solidrectangle(startX, startY, startX + blockSize, startY + blockSize);
|
||||
void drawOledPixel(int oledX, int oledY) {
|
||||
int startX = oledX * scaleFactor;
|
||||
int startY = oledY * scaleFactor;
|
||||
if (border) fillrectangle(startX + 1, startY + 1, startX + scaleFactor - 1, startY + scaleFactor - 1);
|
||||
else solidrectangle(startX, startY, startX + scaleFactor, startY + scaleFactor);
|
||||
}
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
@ -44,7 +44,7 @@ void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
|||
for (int i = 0; i < 8; i++) {
|
||||
uint8_t bit = GET_BIT(byteData, i);
|
||||
if (bit)
|
||||
drawOledPixel(x, y * 8 + (i), scaleFactor); // 这里假设 OLED 像素点大小为一个bit,对应的 EasyX 像素块大小为 10x10
|
||||
drawOledPixel(x, y * 8 + (i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,16 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* @brief 初始化模拟 OLED 显示
|
||||
* @param width: [输入] 显示宽度
|
||||
* @param height: [输入] 显示高度
|
||||
* @param pixcolor: [输入] 像素颜色
|
||||
* @param backcolor: [输入] 背景颜色
|
||||
* @param scale: [输入] 显示缩放比例
|
||||
* @param border: [输入] 是否显示边框
|
||||
* @param b: [输入] 是否显示边框
|
||||
* @return void
|
||||
* @example SIM_OLED_INIT(0xFFFF00, 0x000000, 2, true);
|
||||
* @example SIM_OLED_INIT(128, 64, 0xFFFF00, 0x000000, 10, 1);
|
||||
**/
|
||||
void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool border);
|
||||
void SIM_OLED_INIT(int width, int height, uint32_t pixcolor, uint32_t backcolor, int scale, uint8_t b);
|
||||
|
||||
/**
|
||||
* @brief 开始模拟 OLED 显示
|
||||
|
|
Loading…
Reference in New Issue