From 33edf6ba760a4fc79bbd8107a7534684930c6cee Mon Sep 17 00:00:00 2001 From: jonnieZG Date: Sun, 11 Mar 2018 03:12:49 +0100 Subject: [PATCH] Description scroll speed parametrized + smooth scroll in userConfirmation (#221) * Enabled DOUBLE line for Croatian + translation fix Enabled DOUBLE line Menu for Croatian. A minor translation fix. * Added Double line menus for Croatian Added Double line menus for Croatian. For some reason they were not included in the previous pull request, even though I made them (most probably it was by my mistake). * Added "Power: " translation for Croatian * Menu desciption scroll sped up 3x * Slow scroll * Additional HR translation fix * EOL fixed * Fixed flickering - update only when required * Parametrized description scrolling speed * Synchronized Translation.c with original Ralim master * Removed unnecessary check * lcd.refresh() in description scroll called only when required * Smooth scrolling also implemented in userConfirmation() method * Variable messageSpeedFactor renamed to messageSpeedFactor * Variable renamed --- .../TS100/.settings/language.settings.xml | 4 +-- workspace/TS100/inc/Font.h | 3 ++ workspace/TS100/inc/OLED.hpp | 1 + workspace/TS100/src/gui.cpp | 32 +++++++++++++------ workspace/TS100/src/main.cpp | 32 +++++++++++++------ 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/workspace/TS100/.settings/language.settings.xml b/workspace/TS100/.settings/language.settings.xml index 81ca6911..a6bfbc25 100644 --- a/workspace/TS100/.settings/language.settings.xml +++ b/workspace/TS100/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/workspace/TS100/inc/Font.h b/workspace/TS100/inc/Font.h index 81a845a1..e49d42c3 100644 --- a/workspace/TS100/inc/Font.h +++ b/workspace/TS100/inc/Font.h @@ -10,6 +10,9 @@ #ifndef FONT_H_ #define FONT_H_ #include "Translation.h" + +#define FONT_12_WIDTH 12 + /* * Remember screen is LSB at the top, MSB at the bottom of the strip! */ diff --git a/workspace/TS100/inc/OLED.hpp b/workspace/TS100/inc/OLED.hpp index c1f6ee95..003607fc 100644 --- a/workspace/TS100/inc/OLED.hpp +++ b/workspace/TS100/inc/OLED.hpp @@ -21,6 +21,7 @@ extern "C" { } #endif #define DEVICEADDR_OLED (0x3c<<1) +#define OLED_WIDTH 96 class OLED { public: diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp index ddc3cbb5..87562c5b 100644 --- a/workspace/TS100/src/gui.cpp +++ b/workspace/TS100/src/gui.cpp @@ -102,19 +102,30 @@ static void printShortDescription(uint32_t shortDescIndex, } static int userConfirmation(const char* message) { - uint8_t maxOffset = strlen(message) + 7; - uint32_t messageStart = xTaskGetTickCount(); + uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7); + uint32_t messageStart = HAL_GetTick(); lcd.setFont(0); lcd.setCursor(0, 0); + int16_t lastOffset = -1; + bool lcdRefresh = true; + + // TODO Scrolling speed factor can be moved to User Interface settings + uint16_t scrollingSpeedFactor = 4; // lower the value - higher the speed for (;;) { - int16_t messageOffset = (((xTaskGetTickCount() - messageStart) / 15) - % maxOffset); + int16_t messageOffset = (int) ((HAL_GetTick() - messageStart) + / (float) scrollingSpeedFactor + 0.5) % messageWidth; - lcd.clearScreen(); - lcd.setCursor(12 * (7 - messageOffset), 0); - lcd.print(message); + if (lastOffset != messageOffset) { + lcd.clearScreen(); + + //^ Rolling offset based on time + lcd.setCursor((OLED_WIDTH - messageOffset), 0); + lcd.print(message); + lastOffset = messageOffset; + lcdRefresh = true; + } ButtonState buttons = getButtonState(); switch (buttons) { @@ -132,8 +143,11 @@ static int userConfirmation(const char* message) { return 0; } - lcd.refresh(); - osDelay(50); + if (lcdRefresh) { + lcd.refresh(); + osDelay(20); + lcdRefresh = false; + } } return 0; } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 41268deb..9ae01505 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -21,7 +21,6 @@ uint8_t PCBVersion = 0; uint16_t currentlyActiveTemperatureTarget = 0; uint32_t lastMovementTime = 0; uint32_t lastButtonTime = 0; -int16_t lastOffset = 0; // FreeRTOS variables osThreadId GUITaskHandle; @@ -332,6 +331,12 @@ static void gui_settingsMenu() { uint32_t autoRepeatTimer = 0; bool earlyExit = false; uint32_t descriptionStart = 0; + int16_t lastOffset = -1; + bool lcdRefresh = true; + + // TODO Scrolling speed factor can be moved to User Interface settings + uint16_t scrollingSpeedFactor = 4; // lower the value - higher the speed + while ((settingsMenu[currentScreen].incrementHandler.func != NULL) && earlyExit == false) { lcd.setFont(0); @@ -341,25 +346,29 @@ static void gui_settingsMenu() { lcd.clearScreen(); settingsMenu[currentScreen].draw.func(); - lastOffset = 0; + lastOffset = -1; + lcdRefresh = true; } else { // Draw description // draw string starting from descriptionOffset - int16_t maxOffset = strlen(settingsMenu[currentScreen].description) - + 7; + int16_t descriptionWidth = FONT_12_WIDTH + * (strlen(settingsMenu[currentScreen].description) + 7); if (descriptionStart == 0) descriptionStart = HAL_GetTick(); - int16_t descriptionOffset = ((((HAL_GetTick() - descriptionStart) - / 20) % (maxOffset * 2))) * 6; + int16_t descriptionOffset = + (int) ((HAL_GetTick() - descriptionStart) + / (float) scrollingSpeedFactor + 0.5) + % descriptionWidth; - if (lastOffset == 0 || lastOffset!=descriptionOffset) { + if (lastOffset != descriptionOffset) { lcd.clearScreen(); //^ Rolling offset based on time - lcd.setCursor(((7 * 12) - descriptionOffset), 0); + lcd.setCursor((OLED_WIDTH - descriptionOffset), 0); lcd.print(settingsMenu[currentScreen].description); lastOffset = descriptionOffset; + lcdRefresh = true; } } @@ -403,8 +412,11 @@ static void gui_settingsMenu() { break; } - lcd.refresh(); // update the LCD - osDelay(20); + if (lcdRefresh) { + lcd.refresh(); // update the LCD + osDelay(20); + lcdRefresh = false; + } } saveSettings();