From 4d1cfcf2e648ddf836602bf8b7fcb16aa1b40c9f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 20 Jul 2023 21:19:39 +1000 Subject: [PATCH] Transitions Update SolderingProfile.cpp Hook in transistions --- source/Core/Threads/GUIThread.cpp | 74 ++++++++++--------- .../Core/Threads/OperatingModes/DebugMenu.cpp | 5 +- .../Threads/OperatingModes/HomeScreen.cpp | 4 + .../Threads/OperatingModes/OperatingModes.h | 8 +- .../Threads/OperatingModes/SettingsMenu.cpp | 6 +- .../Core/Threads/OperatingModes/Soldering.cpp | 4 + .../OperatingModes/SolderingProfile.cpp | 2 + .../OperatingModes/TemperatureAdjust.cpp | 1 + 8 files changed, 65 insertions(+), 39 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 1bffaa60..31a29095 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -18,7 +18,6 @@ extern "C" { #include "Settings.h" #include "TipThermoModel.h" #include "Translation.h" -#include "bflb_platform.h" #include "cmsis_os.h" #include "configuration.h" #include "history.hpp" @@ -40,31 +39,29 @@ OperatingMode currentOperatingMode = OperatingMode::InitialisationDone; // Curre guiContext context; // Context passed to functions to aid in state during render passes OperatingMode handle_post_init_state(); - -void guiRenderLoop(void) { +OperatingMode guiHandleDraw(void) { OLED::clearScreen(); // Clear ready for render pass // Read button state ButtonState buttons = getButtonState(); // Enforce screen on if buttons pressed, movement, hot tip etc - if (buttons != BUTTON_NONE) { - OLED::setDisplayState(OLED::DisplayState::ON); - } else { - // Buttons are none; check if we can sleep display - uint32_t tipTemp = TipThermoModel::getTipInC(); - if ((tipTemp < 50) && getSettingValue(SettingsOptions::Sensitivity) - && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { - OLED::setDisplayState(OLED::DisplayState::OFF); - setStatusLED(LED_OFF); - } else { - OLED::setDisplayState(OLED::DisplayState::ON); - if (tipTemp > 55) { - setStatusLED(LED_COOLING_STILL_HOT); - } else { - setStatusLED(LED_STANDBY); - } - } - } - MSG("Run GUI %d - %d\r\n", (int)currentOperatingMode, (int)buttons); + // if (buttons != BUTTON_NONE) { + // OLED::setDisplayState(OLED::DisplayState::ON); + // } else { + // // Buttons are none; check if we can sleep display + // uint32_t tipTemp = TipThermoModel::getTipInC(); + // if ((tipTemp < 50) && getSettingValue(SettingsOptions::Sensitivity) + // && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { + // OLED::setDisplayState(OLED::DisplayState::OFF); + // setStatusLED(LED_OFF); + // } else { + // OLED::setDisplayState(OLED::DisplayState::ON); + // if (tipTemp > 55) { + // setStatusLED(LED_COOLING_STILL_HOT); + // } else { + // setStatusLED(LED_STANDBY); + // } + // } + // } // Dispatch button state to gui mode OperatingMode newMode = currentOperatingMode; switch (currentOperatingMode) { @@ -116,36 +113,43 @@ void guiRenderLoop(void) { case OperatingMode::ThermalRunaway: break; }; - // Update state holders + return newMode; +} +void guiRenderLoop(void) { + OperatingMode newMode = guiHandleDraw(); // This does the screen drawing + + // Post draw we handle any state transitions + if (newMode != currentOperatingMode) { context.viewEnterTime = xTaskGetTickCount(); context.previousMode = currentOperatingMode; memset(&context.scratch_state, 0, sizeof(context.scratch_state)); currentOperatingMode = newMode; - // If the transition marker is set, we need to make the next draw occur to the secondary buffer so we have something to transition to - if (context.transitionMode != TransitionAnimation::None) { - OLED::refresh(); - OLED::useSecondaryFramebuffer(true); - return; // Exit early to avoid refresh with new framebuffer - } - } else if (context.transitionMode != TransitionAnimation::None) { - // We haven't changed mode but transition is set, so we are at the other side of a transition - // We now want to transition from old contents (main buffer) to new contents (secondary buffer) + } + // If the transition marker is set, we need to make the next draw occur to the secondary buffer so we have something to transition to + if (context.transitionMode != TransitionAnimation::None) { + OLED::useSecondaryFramebuffer(true); + // Now we need to fill the secondary buffer with the _next_ frame to transistion to + guiHandleDraw(); + OLED::useSecondaryFramebuffer(false); + // Now dispatch the transition switch (context.transitionMode) { case TransitionAnimation::Down: + OLED::transitionScrollDown(); break; case TransitionAnimation::Left: + OLED::transitionSecondaryFramebuffer(false); break; case TransitionAnimation::Right: + OLED::transitionSecondaryFramebuffer(true); break; case TransitionAnimation::None: default: break; // Do nothing on unknown } - OLED::useSecondaryFramebuffer(false); + context.transitionMode = TransitionAnimation::None; // Clear transition flag } - MSG("Post GUI %d - %d\r\n", (int)currentOperatingMode, (int)buttons); // Render done, draw it out OLED::refresh(); } @@ -211,6 +215,6 @@ void startGUITask(void const *argument) { for (;;) { guiRenderLoop(); resetWatchdog(); - vTaskDelayUntil(&startRender, TICKS_100MS / 2); // Try and maintain 20fps ish update rate, way to fast but if we can its nice + vTaskDelayUntil(&startRender, TICKS_100MS * 4 / 10); // Try and maintain 20-25fps ish update rate, way to fast but if we can its nice } } diff --git a/source/Core/Threads/OperatingModes/DebugMenu.cpp b/source/Core/Threads/OperatingModes/DebugMenu.cpp index 79ef9d78..54db74de 100644 --- a/source/Core/Threads/OperatingModes/DebugMenu.cpp +++ b/source/Core/Threads/OperatingModes/DebugMenu.cpp @@ -86,9 +86,10 @@ OperatingMode showDebugMenu(const ButtonState buttons, guiContext *cxt) { break; } - if (buttons == BUTTON_B_SHORT) + if (buttons == BUTTON_B_SHORT) { + cxt->transitionMode = TransitionAnimation::Up; return OperatingMode::InitialisationDone; - else if (buttons == BUTTON_F_SHORT) { + } else if (buttons == BUTTON_F_SHORT) { cxt->scratch_state.state1++; #ifdef HALL_SENSOR cxt->scratch_state.state1 = cxt->scratch_state.state1 % 17; diff --git a/source/Core/Threads/OperatingModes/HomeScreen.cpp b/source/Core/Threads/OperatingModes/HomeScreen.cpp index 47ee5009..f34f02eb 100644 --- a/source/Core/Threads/OperatingModes/HomeScreen.cpp +++ b/source/Core/Threads/OperatingModes/HomeScreen.cpp @@ -34,9 +34,11 @@ OperatingMode handleHomeButtons(const ButtonState buttons, guiContext *cxt) { break; case BUTTON_B_LONG: + cxt->transitionMode = TransitionAnimation::Down; return OperatingMode::DebugMenuReadout; break; case BUTTON_F_LONG: + cxt->transitionMode = TransitionAnimation::Left; #ifdef PROFILE_SUPPORT if (!isTipDisconnected()) { return OperatingMode::SolderingProfile; @@ -46,11 +48,13 @@ OperatingMode handleHomeButtons(const ButtonState buttons, guiContext *cxt) { #endif break; case BUTTON_F_SHORT: + cxt->transitionMode = TransitionAnimation::Left; if (!isTipDisconnected()) { return OperatingMode::Soldering; } break; case BUTTON_B_SHORT: + cxt->transitionMode = TransitionAnimation::Right; return OperatingMode::SettingsMenu; break; default: diff --git a/source/Core/Threads/OperatingModes/OperatingModes.h b/source/Core/Threads/OperatingModes/OperatingModes.h index 736be866..f499b0cc 100644 --- a/source/Core/Threads/OperatingModes/OperatingModes.h +++ b/source/Core/Threads/OperatingModes/OperatingModes.h @@ -41,7 +41,13 @@ enum class OperatingMode { ThermalRunaway, // Thermal Runaway warning state. }; -enum class TransitionAnimation { None = 0, Right, Left, Down }; +enum class TransitionAnimation { + None = 0, + Right = 1, + Left = 2, + Down = 3, + Up = 4, +}; // Generic context struct used for gui functions to be able to retain state struct guiContext { diff --git a/source/Core/Threads/OperatingModes/SettingsMenu.cpp b/source/Core/Threads/OperatingModes/SettingsMenu.cpp index 6ac5dc01..610885e0 100644 --- a/source/Core/Threads/OperatingModes/SettingsMenu.cpp +++ b/source/Core/Threads/OperatingModes/SettingsMenu.cpp @@ -1,6 +1,5 @@ #include "OperatingModes.h" #include "ScrollMessage.hpp" -#include "bflb_platform.h" #define HELP_TEXT_TIMEOUT_TICKS (TICKS_SECOND * 3) /* @@ -138,6 +137,7 @@ OperatingMode gui_SettingsMenu(const ButtonState buttons, guiContext *cxt) { currentMenu[currentScreen].incrementHandler(); } else { (*subEntry) += 1; + cxt->transitionMode = TransitionAnimation::Right; } } else { callIncrementHandler(); @@ -152,6 +152,7 @@ OperatingMode gui_SettingsMenu(const ButtonState buttons, guiContext *cxt) { // Scroll down if (currentScreen < (*currentMenuLength) - 1) { // We can increment freely + cxt->transitionMode = TransitionAnimation::Down; if (*subEntry == 0) { (*mainEntry) += 1; } else { @@ -161,11 +162,14 @@ OperatingMode gui_SettingsMenu(const ButtonState buttons, guiContext *cxt) { // We are at an end somewhere, increment as appropriate if (*subEntry == 0) { // This is end of the list + cxt->transitionMode = TransitionAnimation::Left; return OperatingMode::HomeScreen; } else { (*subEntry) = 0; (*mainEntry) += 1; } + // When we exit a list we want to animate to the left + cxt->transitionMode = TransitionAnimation::Left; } } break; diff --git a/source/Core/Threads/OperatingModes/Soldering.cpp b/source/Core/Threads/OperatingModes/Soldering.cpp index 5604af6c..b38b0585 100644 --- a/source/Core/Threads/OperatingModes/Soldering.cpp +++ b/source/Core/Threads/OperatingModes/Soldering.cpp @@ -30,6 +30,7 @@ OperatingMode handleSolderingButtons(const ButtonState buttons, guiContext *cxt) break; case BUTTON_BOTH: case BUTTON_B_LONG: + cxt->transitionMode = TransitionAnimation::Right; return OperatingMode::HomeScreen; case BUTTON_F_LONG: // if boost mode is enabled turn it on @@ -39,6 +40,7 @@ OperatingMode handleSolderingButtons(const ButtonState buttons, guiContext *cxt) break; case BUTTON_F_SHORT: case BUTTON_B_SHORT: { + cxt->transitionMode = TransitionAnimation::Left; return OperatingMode::TemperatureAdjust; case BUTTON_BOTH_LONG: if (getSettingValue(SettingsOptions::LockingMode) != 0) { @@ -80,6 +82,7 @@ OperatingMode gui_solderingMode(const ButtonState buttons, guiContext *cxt) { // Check if we should bail due to undervoltage for example if (checkExitSoldering()) { setBuzzer(false); + cxt->transitionMode = TransitionAnimation::Right; return OperatingMode::HomeScreen; } #ifdef NO_SLEEP_MODE @@ -175,4 +178,5 @@ OperatingMode gui_solderingMode(const ButtonState buttons, guiContext *cxt) { } else { basicSolderingStatus(cxt->scratch_state.state2); } + return OperatingMode::Soldering; // Stay put } diff --git a/source/Core/Threads/OperatingModes/SolderingProfile.cpp b/source/Core/Threads/OperatingModes/SolderingProfile.cpp index 83cc065d..d18dc21d 100644 --- a/source/Core/Threads/OperatingModes/SolderingProfile.cpp +++ b/source/Core/Threads/OperatingModes/SolderingProfile.cpp @@ -22,6 +22,7 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx switch (buttons) { case BUTTON_BOTH: case BUTTON_B_LONG: + cxt->transitionMode = TransitionAnimation::Right; return OperatingMode::HomeScreen; // exit on back long hold case BUTTON_F_LONG: case BUTTON_F_SHORT: @@ -207,4 +208,5 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx } else { setStatusLED(LED_HOT); } + return OperatingMode::SolderingProfile; } diff --git a/source/Core/Threads/OperatingModes/TemperatureAdjust.cpp b/source/Core/Threads/OperatingModes/TemperatureAdjust.cpp index 25b60f46..4a8961d7 100644 --- a/source/Core/Threads/OperatingModes/TemperatureAdjust.cpp +++ b/source/Core/Threads/OperatingModes/TemperatureAdjust.cpp @@ -77,6 +77,7 @@ OperatingMode gui_solderingTempAdjust(const ButtonState buttons, guiContext *cxt setSettingValue(SettingsOptions::SolderingTemp, (uint16_t)newTemp); } if (xTaskGetTickCount() - cxt->viewEnterTime > (TICKS_SECOND * 2)) { + cxt->transitionMode = TransitionAnimation::Right; return cxt->previousMode; // exit if user just doesn't press anything for a bit } if (OLED::getRotation()) {