55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include "sim_oled.h"
|
|
#include "graphics.h"
|
|
#include <conio.h>
|
|
|
|
static uint32_t pixelColor, backgroundColor;
|
|
static int scaleFactor, w, h;
|
|
uint8_t border;
|
|
|
|
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
|
|
|
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;
|
|
border = b;
|
|
}
|
|
|
|
void SIM_OLED_START() {
|
|
initgraph(w, h);
|
|
setbkcolor(backgroundColor);
|
|
setfillcolor(pixelColor);
|
|
cleardevice();
|
|
}
|
|
|
|
void SIM_OLED_STOP() {
|
|
getch();
|
|
closegraph();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) {
|
|
cleardevice();
|
|
for (int y = 0; y < height; y++) {
|
|
for (int x = 0; x < width; x++) {
|
|
uint8_t byteData = buf[y * width + x];
|
|
for (int i = 0; i < 8; i++) {
|
|
uint8_t bit = GET_BIT(byteData, i);
|
|
if (bit)drawOledPixel(x, y * 8 + (i));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|