1
0
forked from me/IronOS

Remove secondFrameBuffer and instead add set_framebuffer method

This commit is contained in:
Patrick Horlebein
2020-04-06 17:38:24 +02:00
parent 81abd5eeac
commit ec6140317c
3 changed files with 18 additions and 19 deletions

View File

@@ -101,8 +101,7 @@ public:
static void drawHeatSymbol(uint8_t state);
static void presentSecondScreenBufferAnimatedBack();
static void presentSecondScreenBufferAnimated();
static void use_first_buffer();
static void use_second_buffer();
static void set_framebuffer(uint8_t *buffer);
private:
static void drawChar(char c); // Draw a character to a specific location
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
@@ -114,7 +113,6 @@ private:
static int16_t cursor_x, cursor_y;
static uint8_t displayOffset;
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
static uint8_t secondFrameBuffer[OLED_WIDTH * 2]; // The second frame buffer
};
#endif /* OLED_HPP_ */

View File

@@ -24,7 +24,6 @@ uint8_t OLED::fontWidth, OLED::fontHeight;
int16_t OLED::cursor_x, OLED::cursor_y;
uint8_t OLED::displayOffset;
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2]; // The second frame buffer
/*Setup params for the OLED screen*/
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
@@ -86,14 +85,15 @@ void OLED::initialize() {
sizeof(OLED_Setup_Array));
}
void OLED::use_first_buffer() {
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
}
void OLED::use_second_buffer() {
firstStripPtr = &secondFrameBuffer[0];
secondStripPtr = &secondFrameBuffer[OLED_WIDTH];
void OLED::set_framebuffer(uint8_t *buffer) {
if (buffer == NULL) {
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
return;
}
firstStripPtr = &buffer[0];
secondStripPtr = &buffer[OLED_WIDTH];
}
/*
@@ -118,7 +118,9 @@ void OLED::drawChar(char c) {
}
void OLED::presentSecondScreenBufferAnimatedBack() {
OLED::use_first_buffer();
uint8_t *firstBackStripPtr = &firstStripPtr[0];
uint8_t *secondBackStripPtr = &secondStripPtr[0];
set_framebuffer(NULL);
uint32_t totalDuration = 50;
@@ -138,8 +140,6 @@ void OLED::presentSecondScreenBufferAnimatedBack() {
offset = progress;
uint8_t *firstBackStripPtr = &secondFrameBuffer[0];
uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH];
for (uint8_t i = 0; i < progress; i++) {
firstStripPtr[i] = firstBackStripPtr[(i - progress) + OLED_WIDTH];
@@ -152,7 +152,9 @@ void OLED::presentSecondScreenBufferAnimatedBack() {
}
void OLED::presentSecondScreenBufferAnimated() {
OLED::use_first_buffer();
uint8_t *firstBackStripPtr = &firstStripPtr[0];
uint8_t *secondBackStripPtr = &secondStripPtr[0];
set_framebuffer(NULL);
uint32_t totalDuration = 50;
@@ -172,8 +174,6 @@ void OLED::presentSecondScreenBufferAnimated() {
offset = progress;
uint8_t *firstBackStripPtr = &secondFrameBuffer[0];
uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH];
for (uint8_t i = OLED_WIDTH - progress; i < OLED_WIDTH; i++) {
firstStripPtr[i] = firstBackStripPtr[i - (OLED_WIDTH - progress)];

View File

@@ -825,7 +825,8 @@ void gui_Menu(const menuitem *menu) {
ButtonState lastButtonState = BUTTON_NONE;
if (menu[currentScreen].draw.func != NULL) {
OLED::use_second_buffer();
uint8_t secondFrameBuffer[OLED_WIDTH * 2];
OLED::set_framebuffer(secondFrameBuffer);
OLED::setFont(0);
OLED::setCursor(0, 0);
OLED::clearScreen();