UP 模拟器

main
JiXieShi 2024-06-22 19:26:54 +08:00
parent eb2101c4d0
commit 678c8067b8
3 changed files with 20 additions and 18 deletions

View File

@ -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,

View File

@ -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));
}
}
}

View File

@ -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