UP 模拟器

This commit is contained in:
JiXieShi
2024-06-22 19:26:54 +08:00
parent eb2101c4d0
commit 678c8067b8
3 changed files with 20 additions and 18 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ void Refresh_Call(OLED_T *dev) {
uint8_t oledbuf[8][128] = {0}; uint8_t oledbuf[8][128] = {0};
void Test_OLED() { void Test_OLED() {
SIM_OLED_INIT(0xFFFFFF, 0x0, 10, true); SIM_OLED_INIT(128, 64, 0xFFFFFF, 0x0, 10, 1);
OLED_T oled = { OLED_T oled = {
.height=64, .height=64,
.width=128, .width=128,
+14 -14
View File
@@ -3,10 +3,12 @@
#include <conio.h> #include <conio.h>
static uint32_t pixelColor, backgroundColor; static uint32_t pixelColor, backgroundColor;
static int scaleFactor; static int scaleFactor, w, h;
static bool border; 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; pixelColor = pixcolor;
backgroundColor = backcolor; backgroundColor = backcolor;
scaleFactor = scale; scaleFactor = scale;
@@ -14,10 +16,10 @@ void SIM_OLED_INIT(uint32_t pixcolor, uint32_t backcolor, int scale, bool b) {
} }
void SIM_OLED_START() { void SIM_OLED_START() {
initgraph(WIDTH, HEIGHT); initgraph(w, h);
setbkcolor(backgroundColor); // 设置背景色为黑色 setbkcolor(backgroundColor);
setfillcolor(pixelColor); setfillcolor(pixelColor);
cleardevice(); // 清空屏幕 cleardevice();
} }
void SIM_OLED_STOP() { void SIM_OLED_STOP() {
@@ -25,13 +27,11 @@ void SIM_OLED_STOP() {
closegraph(); closegraph();
} }
void drawOledPixel(int oledX, int oledY, int blockSize) { void drawOledPixel(int oledX, int oledY) {
int startX = oledX * blockSize; int startX = oledX * scaleFactor;
int startY = oledY * blockSize; int startY = oledY * scaleFactor;
if (border) if (border) fillrectangle(startX + 1, startY + 1, startX + scaleFactor - 1, startY + scaleFactor - 1);
fillrectangle(startX, startY, startX + blockSize, startY + blockSize); else solidrectangle(startX, startY, startX + scaleFactor, startY + scaleFactor);
if (!border)
solidrectangle(startX, startY, startX + blockSize, startY + blockSize);
} }
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit) #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++) { for (int i = 0; i < 8; i++) {
uint8_t bit = GET_BIT(byteData, i); uint8_t bit = GET_BIT(byteData, i);
if (bit) if (bit)
drawOledPixel(x, y * 8 + (i), scaleFactor); // 这里假设 OLED 像素点大小为一个bit,对应的 EasyX 像素块大小为 10x10 drawOledPixel(x, y * 8 + (i));
} }
} }
} }
+5 -3
View File
@@ -11,14 +11,16 @@ extern "C" {
/** /**
* @brief 初始化模拟 OLED 显示 * @brief 初始化模拟 OLED 显示
* @param width: [输入] 显示宽度
* @param height: [输入] 显示高度
* @param pixcolor: [输入] 像素颜色 * @param pixcolor: [输入] 像素颜色
* @param backcolor: [输入] 背景颜色 * @param backcolor: [输入] 背景颜色
* @param scale: [输入] 显示缩放比例 * @param scale: [输入] 显示缩放比例
* @param border: [输入] 是否显示边框 * @param b: [输入] 是否显示边框
* @return void * @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 显示 * @brief 开始模拟 OLED 显示