From ec6140317c9a57cab5c8f8252381e7419b9310d4 Mon Sep 17 00:00:00 2001 From: Patrick Horlebein Date: Mon, 6 Apr 2020 17:38:24 +0200 Subject: [PATCH] Remove `secondFrameBuffer` and instead add `set_framebuffer` method --- workspace/TS100/Core/Inc/OLED.hpp | 4 +--- workspace/TS100/Core/Src/OLED.cpp | 30 +++++++++++++++--------------- workspace/TS100/Core/Src/gui.cpp | 3 ++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/workspace/TS100/Core/Inc/OLED.hpp b/workspace/TS100/Core/Inc/OLED.hpp index 2bbd23a2..3d5dfda8 100644 --- a/workspace/TS100/Core/Inc/OLED.hpp +++ b/workspace/TS100/Core/Inc/OLED.hpp @@ -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_ */ diff --git a/workspace/TS100/Core/Src/OLED.cpp b/workspace/TS100/Core/Src/OLED.cpp index 00e35974..2881e39b 100644 --- a/workspace/TS100/Core/Src/OLED.cpp +++ b/workspace/TS100/Core/Src/OLED.cpp @@ -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)]; diff --git a/workspace/TS100/Core/Src/gui.cpp b/workspace/TS100/Core/Src/gui.cpp index 99cdcd4f..f2a67f55 100644 --- a/workspace/TS100/Core/Src/gui.cpp +++ b/workspace/TS100/Core/Src/gui.cpp @@ -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();