Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Prideflag state simplification and default state setup #13

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/FSMGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 9 additions & 29 deletions include/FSMState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -150,10 +150,11 @@ struct DisplayPrideFlag : public FSMState {
virtual void run() override;

virtual std::unique_ptr<FSMState> touchEventFingerprintShortpress() override;
virtual std::unique_ptr<FSMState> touchEventFingerprintRelease() override;
};

/**
* @brief Main state: Displays an animation
* @brief Displays animations
*/
struct DisplayAnimation : public FSMState {
uint32_t tick = 0;
Expand All @@ -176,53 +177,32 @@ 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<FSMState> touchEventFingerprintTouch() override;
virtual std::unique_ptr<FSMState> touchEventFingerprintRelease() override;
virtual std::unique_ptr<FSMState> touchEventFingerprintShortpress() override;
virtual std::unique_ptr<FSMState> touchEventFingerprintLongpress() override;

virtual std::unique_ptr<FSMState> touchEventNoseLongpress() override;
};

/**
* @brief Sub-Menu: Pride flag selector
* @brief Menu entry point
*/
struct MenuPrideFlagSelector : public FSMState {
std::unique_ptr<DisplayPrideFlag> 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<FSMState> touchEventFingerprintRelease() override;
virtual std::unique_ptr<FSMState> touchEventFingerprintShortpress() override;
virtual std::unique_ptr<FSMState> 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<FSMState> touchEventFingerprintShortpress() override;
};

#endif /* FSM_STATE_H_ */
2 changes: 1 addition & 1 deletion src/FSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/states/DisplayPrideFlag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ void DisplayPrideFlag::run() {
std::unique_ptr<FSMState> DisplayPrideFlag::touchEventFingerprintShortpress() {
return std::make_unique<MenuMain>();
}

std::unique_ptr<FSMState> DisplayPrideFlag::touchEventFingerprintRelease() {
this->globals->prideFlagModeIdx = (this->globals->prideFlagModeIdx + 1) % 13;
this->is_globals_dirty = true;
this->tick = 0;

return nullptr;
}
21 changes: 10 additions & 11 deletions src/states/MenuMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -43,29 +49,22 @@ void MenuMain::exit() {
EFLed.clear();
}

std::unique_ptr<FSMState> MenuMain::touchEventFingerprintTouch() {
return nullptr;
}

std::unique_ptr<FSMState> 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;
}

std::unique_ptr<FSMState> MenuMain::touchEventFingerprintShortpress() {
LOGF_DEBUG("(MenuMain) menuMainPointerIdx = %d\r\n", this->globals->menuMainPointerIdx);
switch (this->globals->menuMainPointerIdx) {
case 0: return std::make_unique<MenuPrideFlagSelector>();
case 0: return std::make_unique<DisplayPrideFlag>();
case 1: return std::make_unique<DisplayAnimation>();
case 2: return std::make_unique<OTAUpdate>();
default: return nullptr;
}
}

std::unique_ptr<FSMState> MenuMain::touchEventFingerprintLongpress() {
return std::make_unique<DisplayPrideFlag>();
}

std::unique_ptr<FSMState> MenuMain::touchEventNoseLongpress() {
return std::make_unique<MenuOTAUpdate>();
return this->touchEventFingerprintShortpress();
}
12 changes: 6 additions & 6 deletions src/states/menu/MenuOTAUpdate.cpp → src/states/OTAUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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<FSMState> MenuOTAUpdate::touchEventFingerprintShortpress() {
std::unique_ptr<FSMState> OTAUpdate::touchEventFingerprintShortpress() {
return std::make_unique<MenuMain>();
}
67 changes: 0 additions & 67 deletions src/states/menu/MenuPrideFlagSelector.cpp

This file was deleted.

Loading