From 3d33a6ea57e1d39c016872c8be36a36f20e0ef70 Mon Sep 17 00:00:00 2001 From: Patrick Horlebein Date: Fri, 17 Apr 2020 09:46:01 +0200 Subject: [PATCH] Fix whitespaces --- workspace/TS100/Core/Inc/OLED.hpp | 4 +- workspace/TS100/Core/Src/OLED.cpp | 96 +++++++++++++++---------------- workspace/TS100/Core/Src/gui.cpp | 72 +++++++++++------------ 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/workspace/TS100/Core/Inc/OLED.hpp b/workspace/TS100/Core/Inc/OLED.hpp index 5beb156d..e6077494 100644 --- a/workspace/TS100/Core/Inc/OLED.hpp +++ b/workspace/TS100/Core/Inc/OLED.hpp @@ -101,8 +101,8 @@ 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 transitionToContents(uint8_t *framebuffer, bool forwardNavigation); + 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 diff --git a/workspace/TS100/Core/Src/OLED.cpp b/workspace/TS100/Core/Src/OLED.cpp index 37e55762..5893556c 100644 --- a/workspace/TS100/Core/Src/OLED.cpp +++ b/workspace/TS100/Core/Src/OLED.cpp @@ -63,11 +63,11 @@ const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80, 0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 }; static uint8_t easeInOutTiming(uint8_t t) { - return t * t * (300 - 2 * t) / 10000; + return t * t * (300 - 2 * t) / 10000; } static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) { - return a + t * (b - a) / 100; + return a + t * (b - a) / 100; } void OLED::initialize() { @@ -94,14 +94,14 @@ void OLED::initialize() { } 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]; + if (buffer == NULL) { + firstStripPtr = &screenBuffer[FRAMEBUFFER_START]; + secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH]; + return; + } + + firstStripPtr = &buffer[0]; + secondStripPtr = &buffer[OLED_WIDTH]; } /* @@ -153,44 +153,44 @@ void OLED::drawScrollIndicator(uint8_t y, uint8_t height) { * 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]; - - uint32_t totalDuration = 50; // 500ms - uint32_t duration = 0; - uint32_t start = xTaskGetTickCount(); - uint8_t offset = 0; - - while (duration <= totalDuration) { - duration = xTaskGetTickCount() - start; - uint8_t progress = duration * 100 / totalDuration; - progress = easeInOutTiming(progress); - progress = lerp(0, OLED_WIDTH, progress); - if (progress > OLED_WIDTH) { - progress = OLED_WIDTH; - } - - // When forward, current contents move to the left out. - // Otherwise the contents move to the right out. - uint8_t oldStart = forwardNavigation ? 0 : progress; - uint8_t oldPrevious = forwardNavigation ? progress - offset : offset; - - // Content from the second framebuffer moves in from the right (forward) - // or from the left (not forward). - uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0; - uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress; - - offset = progress; - - memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress); - memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress); - - memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress); - memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress); - - refresh(); - osDelay(40); - } + uint8_t *firstBackStripPtr = &framebuffer[0]; + uint8_t *secondBackStripPtr = &framebuffer[OLED_WIDTH]; + + uint32_t totalDuration = 50; // 500ms + uint32_t duration = 0; + uint32_t start = xTaskGetTickCount(); + uint8_t offset = 0; + + while (duration <= totalDuration) { + duration = xTaskGetTickCount() - start; + uint8_t progress = duration * 100 / totalDuration; + progress = easeInOutTiming(progress); + progress = lerp(0, OLED_WIDTH, progress); + if (progress > OLED_WIDTH) { + progress = OLED_WIDTH; + } + + // When forward, current contents move to the left out. + // Otherwise the contents move to the right out. + uint8_t oldStart = forwardNavigation ? 0 : progress; + uint8_t oldPrevious = forwardNavigation ? progress - offset : offset; + + // Content from the second framebuffer moves in from the right (forward) + // or from the left (not forward). + uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0; + uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress; + + offset = progress; + + memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress); + memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress); + + memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress); + memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress); + + refresh(); + osDelay(40); + } } void OLED::setRotation(bool leftHanded) { diff --git a/workspace/TS100/Core/Src/gui.cpp b/workspace/TS100/Core/Src/gui.cpp index 4a5221f3..019ed102 100644 --- a/workspace/TS100/Core/Src/gui.cpp +++ b/workspace/TS100/Core/Src/gui.cpp @@ -826,29 +826,29 @@ void gui_Menu(const menuitem *menu) { int16_t lastOffset = -1; bool lcdRefresh = true; ButtonState lastButtonState = BUTTON_NONE; - static bool enterGUIMenu = true; - enterGUIMenu = true; - uint8_t scrollContentSize = 0; - + static bool enterGUIMenu = true; + enterGUIMenu = true; + uint8_t scrollContentSize = 0; + for (uint8_t i = 0; menu[i].draw.func != NULL; i++) { scrollContentSize += 1; } - - // Animated menu opening. - if (menu[currentScreen].draw.func != NULL) { - // This menu is drawn in a secondary framebuffer. - // 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::setFont(0); - OLED::setCursor(0, 0); - OLED::clearScreen(); - menu[currentScreen].draw.func(); - OLED::set_framebuffer(NULL); - OLED::transitionToContents(secondaryFrameBuffer, true); - } + + // Animated menu opening. + if (menu[currentScreen].draw.func != NULL) { + // This menu is drawn in a secondary framebuffer. + // 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::setFont(0); + OLED::setCursor(0, 0); + OLED::clearScreen(); + menu[currentScreen].draw.func(); + OLED::set_framebuffer(NULL); + OLED::transitionToContents(secondaryFrameBuffer, true); + } while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) { OLED::setFont(0); @@ -900,24 +900,24 @@ void gui_Menu(const menuitem *menu) { case BUTTON_F_SHORT: // increment if (descriptionStart == 0) { - if (menu[currentScreen].incrementHandler.func != NULL) { - enterGUIMenu = false; + if (menu[currentScreen].incrementHandler.func != NULL) { + enterGUIMenu = false; menu[currentScreen].incrementHandler.func(); - - if (enterGUIMenu) { - uint8_t secondaryFrameBuffer[OLED_WIDTH * 2]; - OLED::set_framebuffer(secondaryFrameBuffer); - OLED::setFont(0); - OLED::setCursor(0, 0); - OLED::clearScreen(); - menu[currentScreen].draw.func(); - OLED::set_framebuffer(NULL); - OLED::transitionToContents(secondaryFrameBuffer, false); - } - enterGUIMenu = true; - } else { + + if (enterGUIMenu) { + uint8_t secondaryFrameBuffer[OLED_WIDTH * 2]; + OLED::set_framebuffer(secondaryFrameBuffer); + OLED::setFont(0); + OLED::setCursor(0, 0); + OLED::clearScreen(); + menu[currentScreen].draw.func(); + OLED::set_framebuffer(NULL); + OLED::transitionToContents(secondaryFrameBuffer, false); + } + enterGUIMenu = true; + } else { earlyExit = true; - } + } } else descriptionStart = 0; break;