diff --git a/include/FSMGlobals.h b/include/FSMGlobals.h index a54361c..3df7f0b 100644 --- a/include/FSMGlobals.h +++ b/include/FSMGlobals.h @@ -39,7 +39,7 @@ typedef struct { const char* lastRememberedState = "DisplayPrideFlag"; //!< Name of the state that should be resumed upon reboot uint8_t menuMainPointerIdx = 0; //!< MenuMain: Index of the menu cursor - uint8_t prideFlagModeIdx = 0; //!< DisplayPrideFlag: Mode selector + uint8_t prideFlagModeIdx = 1; //!< DisplayPrideFlag: Mode selector uint8_t animationModeIdx = 0; //!< DisplayAnimation: Mode selector } FSMGlobals; diff --git a/include/FSMState.h b/include/FSMState.h index 8d09f34..b6fad3d 100644 --- a/include/FSMState.h +++ b/include/FSMState.h @@ -135,7 +135,7 @@ class FSMState { }; /** - * @brief Main state: Displays a pride flag + * @brief Displays pride flags */ struct DisplayPrideFlag : public FSMState { uint32_t tick = 0; @@ -150,10 +150,11 @@ struct DisplayPrideFlag : public FSMState { virtual void run() override; virtual std::unique_ptr touchEventFingerprintShortpress() override; + virtual std::unique_ptr touchEventFingerprintRelease() override; }; /** - * @brief Main state: Displays an animation + * @brief Displays animations */ struct DisplayAnimation : public FSMState { uint32_t tick = 0; @@ -176,35 +177,27 @@ struct DisplayAnimation : public FSMState { }; /** - * @brief Menu entry point + * @brief Accept and handle OTA updates */ -struct MenuMain : public FSMState { - uint8_t menucursor_idx = 0; - +struct OTAUpdate : public FSMState { virtual const char* getName() override; virtual void entry() override; + virtual void run() override; virtual void exit() override; - virtual std::unique_ptr touchEventFingerprintTouch() override; - virtual std::unique_ptr touchEventFingerprintRelease() override; virtual std::unique_ptr touchEventFingerprintShortpress() override; - virtual std::unique_ptr touchEventFingerprintLongpress() override; - - virtual std::unique_ptr touchEventNoseLongpress() override; }; /** - * @brief Sub-Menu: Pride flag selector + * @brief Menu entry point */ -struct MenuPrideFlagSelector : public FSMState { - std::unique_ptr prideFlagDisplayRunner; +struct MenuMain : public FSMState { + uint8_t menucursor_idx = 0; virtual const char* getName() override; - virtual const unsigned int getTickRateMs() override; virtual void entry() override; - virtual void run() override; virtual void exit() override; virtual std::unique_ptr touchEventFingerprintRelease() override; @@ -212,17 +205,4 @@ struct MenuPrideFlagSelector : public FSMState { virtual std::unique_ptr touchEventFingerprintLongpress() override; }; -/** - * @brief Sub-Menu: Accept OTA updates - */ -struct MenuOTAUpdate : public FSMState { - virtual const char* getName() override; - - virtual void entry() override; - virtual void run() override; - virtual void exit() override; - - virtual std::unique_ptr touchEventFingerprintShortpress() override; -}; - #endif /* FSM_STATE_H_ */ \ No newline at end of file diff --git a/src/FSM.cpp b/src/FSM.cpp index 578ce93..f2b920f 100644 --- a/src/FSM.cpp +++ b/src/FSM.cpp @@ -215,7 +215,7 @@ void FSM::restoreGlobals() { LOGF_INFO("(FSM) Restored FSM state data from NVS area: %s\r\n", this->NVS_NAMESPACE); this->globals->lastRememberedState = pref.getString("resumeState", "DisplayPrideFlag").c_str(); LOGF_DEBUG("(FSM) -> resumeState = %s\r\n", this->globals->lastRememberedState); - this->globals->prideFlagModeIdx = pref.getUInt("prideFlagMode", 0); + this->globals->prideFlagModeIdx = pref.getUInt("prideFlagMode", 1); LOGF_DEBUG("(FSM) -> prideFlagMode = %d\r\n", this->globals->prideFlagModeIdx); this->globals->animationModeIdx = pref.getUInt("animationMode", 0); LOGF_DEBUG("(FSM) -> animationMode = %d\r\n", this->globals->animationModeIdx); diff --git a/src/states/DisplayPrideFlag.cpp b/src/states/DisplayPrideFlag.cpp index 300a8e0..fcf988a 100644 --- a/src/states/DisplayPrideFlag.cpp +++ b/src/states/DisplayPrideFlag.cpp @@ -125,3 +125,11 @@ void DisplayPrideFlag::run() { std::unique_ptr DisplayPrideFlag::touchEventFingerprintShortpress() { return std::make_unique(); } + +std::unique_ptr DisplayPrideFlag::touchEventFingerprintRelease() { + this->globals->prideFlagModeIdx = (this->globals->prideFlagModeIdx + 1) % 13; + this->is_globals_dirty = true; + this->tick = 0; + + return nullptr; +} diff --git a/src/states/MenuMain.cpp b/src/states/MenuMain.cpp index 68a5d2d..a614f00 100644 --- a/src/states/MenuMain.cpp +++ b/src/states/MenuMain.cpp @@ -29,6 +29,12 @@ #include "FSMState.h" +/** + * @brief Number of registered menu items + */ +#define MENUMAIN_NUM_MENU_ITEMS 3 + + const char* MenuMain::getName() { return "MenuMain"; } @@ -43,12 +49,8 @@ void MenuMain::exit() { EFLed.clear(); } -std::unique_ptr MenuMain::touchEventFingerprintTouch() { - return nullptr; -} - std::unique_ptr MenuMain::touchEventFingerprintRelease() { - this->globals->menuMainPointerIdx = (this->globals->menuMainPointerIdx + 1) % 2; + this->globals->menuMainPointerIdx = (this->globals->menuMainPointerIdx + 1) % MENUMAIN_NUM_MENU_ITEMS; EFLed.setEFBarCursor(this->globals->menuMainPointerIdx, CRGB::Purple, CRGB::Black); return nullptr; } @@ -56,16 +58,13 @@ std::unique_ptr MenuMain::touchEventFingerprintRelease() { std::unique_ptr MenuMain::touchEventFingerprintShortpress() { LOGF_DEBUG("(MenuMain) menuMainPointerIdx = %d\r\n", this->globals->menuMainPointerIdx); switch (this->globals->menuMainPointerIdx) { - case 0: return std::make_unique(); + case 0: return std::make_unique(); case 1: return std::make_unique(); + case 2: return std::make_unique(); default: return nullptr; } } std::unique_ptr MenuMain::touchEventFingerprintLongpress() { - return std::make_unique(); -} - -std::unique_ptr MenuMain::touchEventNoseLongpress() { - return std::make_unique(); + return this->touchEventFingerprintShortpress(); } diff --git a/src/states/menu/MenuOTAUpdate.cpp b/src/states/OTAUpdate.cpp similarity index 87% rename from src/states/menu/MenuOTAUpdate.cpp rename to src/states/OTAUpdate.cpp index 2965558..123520d 100644 --- a/src/states/menu/MenuOTAUpdate.cpp +++ b/src/states/OTAUpdate.cpp @@ -33,11 +33,11 @@ #include "FSMState.h" -const char* MenuOTAUpdate::getName() { - return "MenuOTAUpdate"; +const char* OTAUpdate::getName() { + return "OTAUpdate"; } -void MenuOTAUpdate::entry() { +void OTAUpdate::entry() { // Connecto to wifi EFLed.setDragonNose(CRGB::Red); if (EFBoard.connectToWifi(WIFI_SSID, WIFI_PASSWORD)) { @@ -49,15 +49,15 @@ void MenuOTAUpdate::entry() { EFLed.setDragonMuzzle(CRGB::Green); } -void MenuOTAUpdate::run() { +void OTAUpdate::run() { ArduinoOTA.handle(); } -void MenuOTAUpdate::exit() { +void OTAUpdate::exit() { EFBoard.disableOTA(); EFBoard.disableWifi(); } -std::unique_ptr MenuOTAUpdate::touchEventFingerprintShortpress() { +std::unique_ptr OTAUpdate::touchEventFingerprintShortpress() { return std::make_unique(); } diff --git a/src/states/menu/MenuPrideFlagSelector.cpp b/src/states/menu/MenuPrideFlagSelector.cpp deleted file mode 100644 index 2f28854..0000000 --- a/src/states/menu/MenuPrideFlagSelector.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// MIT License -// -// Copyright 2024 Eurofurence e.V. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the “Software”), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. - -/** - * @author Honigeintopf - */ - -#include "FSMState.h" - -const char* MenuPrideFlagSelector::getName() { - return "MenuPrideFlagSelector"; -} - -const unsigned int MenuPrideFlagSelector::getTickRateMs() { - return 20; -} - -void MenuPrideFlagSelector::entry() { - // Construct DisplayPrideFlag state locally to get a preview of the current mode - this->prideFlagDisplayRunner = std::make_unique(); - this->prideFlagDisplayRunner->attachGlobals(this->globals); -} - -void MenuPrideFlagSelector::run() { - this->prideFlagDisplayRunner->run(); -} - -void MenuPrideFlagSelector::exit() { - this->prideFlagDisplayRunner.reset(); -} - -std::unique_ptr MenuPrideFlagSelector::touchEventFingerprintRelease() { - this->globals->prideFlagModeIdx = (this->globals->prideFlagModeIdx + 1) % 13; - this->is_globals_dirty = true; - - this->prideFlagDisplayRunner->entry(); - this->prideFlagDisplayRunner->switchdelay_ms = 1000; - - return nullptr; -} - -std::unique_ptr MenuPrideFlagSelector::touchEventFingerprintShortpress() { - return std::make_unique(); -} - -std::unique_ptr MenuPrideFlagSelector::touchEventFingerprintLongpress() { - return std::make_unique(); -}