Skip to content

Commit

Permalink
Transitions
Browse files Browse the repository at this point in the history
Update SolderingProfile.cpp

Hook in transistions
  • Loading branch information
Ralim committed Jul 20, 2023
1 parent ff317d9 commit c6b86ab
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 39 deletions.
74 changes: 39 additions & 35 deletions source/Core/Threads/GUIThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
}
}
5 changes: 3 additions & 2 deletions source/Core/Threads/OperatingModes/DebugMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions source/Core/Threads/OperatingModes/HomeScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion source/Core/Threads/OperatingModes/OperatingModes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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 {
Expand Down
6 changes: 5 additions & 1 deletion source/Core/Threads/OperatingModes/SettingsMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "OperatingModes.h"
#include "ScrollMessage.hpp"
#include "bflb_platform.h"

#define HELP_TEXT_TIMEOUT_TICKS (TICKS_SECOND * 3)
/*
Expand Down Expand Up @@ -138,6 +137,7 @@ OperatingMode gui_SettingsMenu(const ButtonState buttons, guiContext *cxt) {
currentMenu[currentScreen].incrementHandler();
} else {
(*subEntry) += 1;
cxt->transitionMode = TransitionAnimation::Right;
}
} else {
callIncrementHandler();
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions source/Core/Threads/OperatingModes/Soldering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -175,4 +178,5 @@ OperatingMode gui_solderingMode(const ButtonState buttons, guiContext *cxt) {
} else {
basicSolderingStatus(cxt->scratch_state.state2);
}
return OperatingMode::Soldering; // Stay put
}
2 changes: 2 additions & 0 deletions source/Core/Threads/OperatingModes/SolderingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -207,4 +208,5 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx
} else {
setStatusLED(LED_HOT);
}
return OperatingMode::SolderingProfile;
}
1 change: 1 addition & 0 deletions source/Core/Threads/OperatingModes/TemperatureAdjust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit c6b86ab

Please sign in to comment.