Add secondary framebuffer, instead of allocating on stack
This commit is contained in:
@@ -101,10 +101,11 @@ public:
|
||||
bool clear);
|
||||
static void drawHeatSymbol(uint8_t state);
|
||||
static void drawScrollIndicator(uint8_t p, uint8_t h); // Draws a scrolling position indicator
|
||||
static void transitionToContents(uint8_t *framebuffer, bool forwardNavigation);
|
||||
static void set_framebuffer(uint8_t *buffer);
|
||||
static void transitionSecondaryFramebuffer(bool forwardNavigation);
|
||||
static void useSecondaryFramebuffer(bool useSecondary);
|
||||
private:
|
||||
static void drawChar(char c); // Draw a character to a specific location
|
||||
static void setFramebuffer(uint8_t *buffer);
|
||||
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
|
||||
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
static uint8_t* secondStripPtr; //Pointers to the strips
|
||||
@@ -114,6 +115,7 @@ 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];
|
||||
};
|
||||
|
||||
#endif /* OLED_HPP_ */
|
||||
|
||||
@@ -24,6 +24,7 @@ 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];
|
||||
|
||||
/*Setup params for the OLED screen*/
|
||||
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
|
||||
@@ -93,7 +94,7 @@ void OLED::initialize() {
|
||||
sizeof(OLED_Setup_Array));
|
||||
}
|
||||
|
||||
void OLED::set_framebuffer(uint8_t *buffer) {
|
||||
void OLED::setFramebuffer(uint8_t *buffer) {
|
||||
if (buffer == NULL) {
|
||||
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
@@ -146,15 +147,14 @@ void OLED::drawScrollIndicator(uint8_t y, uint8_t height) {
|
||||
|
||||
/**
|
||||
* Plays a transition animation between two framebuffers.
|
||||
* @param framebuffer Second framebuffer to use for animation.
|
||||
* @param forward Direction of the navigation animation.
|
||||
* @param forwardNavigation Direction of the navigation animation.
|
||||
*
|
||||
* If forward is true, this displays a forward navigation to the second framebuffer contents.
|
||||
* Otherwise a rewinding navigation animation is shown to the second framebuffer contents.
|
||||
*/
|
||||
void OLED::transitionToContents(uint8_t *framebuffer, bool forwardNavigation) {
|
||||
uint8_t *firstBackStripPtr = &framebuffer[0];
|
||||
uint8_t *secondBackStripPtr = &framebuffer[OLED_WIDTH];
|
||||
void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
|
||||
uint8_t *firstBackStripPtr = &secondFrameBuffer[0];
|
||||
uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH];
|
||||
|
||||
uint32_t totalDuration = 50; // 500ms
|
||||
uint32_t duration = 0;
|
||||
@@ -193,6 +193,14 @@ void OLED::transitionToContents(uint8_t *framebuffer, bool forwardNavigation) {
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::useSecondaryFramebuffer(bool useSecondary) {
|
||||
if (useSecondary) {
|
||||
setFramebuffer(secondFrameBuffer);
|
||||
} else {
|
||||
setFramebuffer(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::setRotation(bool leftHanded) {
|
||||
#ifdef MODEL_TS80
|
||||
leftHanded = !leftHanded;
|
||||
|
||||
@@ -840,14 +840,13 @@ void gui_Menu(const menuitem *menu) {
|
||||
// Then we play a transition from the current primary
|
||||
// framebuffer to the new buffer.
|
||||
// The extra buffer is discarded at the end of the transition.
|
||||
uint8_t secondaryFrameBuffer[OLED_WIDTH * 2];
|
||||
OLED::set_framebuffer(secondaryFrameBuffer);
|
||||
OLED::useSecondaryFramebuffer(true);
|
||||
OLED::setFont(0);
|
||||
OLED::setCursor(0, 0);
|
||||
OLED::clearScreen();
|
||||
menu[currentScreen].draw.func();
|
||||
OLED::set_framebuffer(NULL);
|
||||
OLED::transitionToContents(secondaryFrameBuffer, true);
|
||||
OLED::useSecondaryFramebuffer(false);
|
||||
OLED::transitionSecondaryFramebuffer(true);
|
||||
}
|
||||
|
||||
while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) {
|
||||
@@ -905,14 +904,13 @@ void gui_Menu(const menuitem *menu) {
|
||||
menu[currentScreen].incrementHandler.func();
|
||||
|
||||
if (enterGUIMenu) {
|
||||
uint8_t secondaryFrameBuffer[OLED_WIDTH * 2];
|
||||
OLED::set_framebuffer(secondaryFrameBuffer);
|
||||
OLED::useSecondaryFramebuffer(true);
|
||||
OLED::setFont(0);
|
||||
OLED::setCursor(0, 0);
|
||||
OLED::clearScreen();
|
||||
menu[currentScreen].draw.func();
|
||||
OLED::set_framebuffer(NULL);
|
||||
OLED::transitionToContents(secondaryFrameBuffer, false);
|
||||
OLED::useSecondaryFramebuffer(false);
|
||||
OLED::transitionSecondaryFramebuffer(false);
|
||||
}
|
||||
enterGUIMenu = true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user