diff --git a/include/FSMGlobals.h b/include/FSMGlobals.h index a5a5e51..7bc0acd 100644 --- a/include/FSMGlobals.h +++ b/include/FSMGlobals.h @@ -37,16 +37,17 @@ * FSM::persistGlobals() and FSM::restoreGlobals() respectively. */ typedef struct { - uint8_t resumeStateIdx = 0; //!< Index of the state that should be resumed upon reboot - uint8_t menuMainPointerIdx = 0; //!< MenuMain: Index of the menu cursor + uint8_t resumeStateIdx = 0; //!< Index of the state that should be resumed upon reboot + uint8_t menuMainPointerIdx = 0; //!< MenuMain: Index of the menu cursor + uint8_t ledBrightnessPercent = 40; //!< The current brightness percentage of the LEDs uint8_t prideFlagModeIdx = 1; //!< DisplayPrideFlag: Mode selector uint8_t animRainbowIdx = 0; //!< AnimateRainbow: Mode selector uint8_t animSnakeIdx = 0; //!< AnimateSnake: Mode selector uint8_t animHeartbeatHue = 0; //!< AnimateHeartbeat: Hue selector uint8_t animHeartbeatSpeed = 1; //!< AnimateHeartbeat: Speed selector + uint8_t animMatrixIdx = 0; //!< AnimateMatrix: Color selector - uint8_t ledBrightnessPercent = 40; //!< The global maximum brightness of the LEDs } FSMGlobals; #endif /* FSMGLOBALS_H_ */ diff --git a/include/FSMState.h b/include/FSMState.h index 423266e..dc3c8e2 100644 --- a/include/FSMState.h +++ b/include/FSMState.h @@ -193,6 +193,8 @@ struct AnimateMatrix : public FSMState { virtual void run() override; virtual std::unique_ptr touchEventFingerprintShortpress() override; + + std::unique_ptr touchEventFingerprintRelease(); }; /** diff --git a/src/FSM.cpp b/src/FSM.cpp index 9fdf13d..b8fbad0 100644 --- a/src/FSM.cpp +++ b/src/FSM.cpp @@ -228,6 +228,8 @@ void FSM::persistGlobals() { LOGF_DEBUG("(FSM) -> animHbHue = %d\r\n", this->globals->animHeartbeatHue); pref.putUInt("animHbSpeed", this->globals->animHeartbeatSpeed); LOGF_DEBUG("(FSM) -> animHbSpeed = %d\r\n", this->globals->animHeartbeatSpeed); + pref.putUInt("animMatrixIdx", this->globals->animMatrixIdx); + LOGF_DEBUG("(FSM) -> animMatrixIdx = %d\r\n", this->globals->animMatrixIdx); pref.putUInt("ledBrightPcent", this->globals->ledBrightnessPercent); LOGF_DEBUG("(FSM) -> ledBrightPcent = %d\r\n", this->globals->ledBrightnessPercent); pref.end(); @@ -250,6 +252,8 @@ void FSM::restoreGlobals() { LOGF_DEBUG("(FSM) -> animHbHue = %d\r\n", this->globals->animHeartbeatHue); this->globals->animHeartbeatSpeed= pref.getUInt("animHbSpeed", 1); LOGF_DEBUG("(FSM) -> animHbSpeed = %d\r\n", this->globals->animHeartbeatSpeed); + this->globals->animMatrixIdx= pref.getUInt("animMatrixIdx", 0); + LOGF_DEBUG("(FSM) -> animMatrixIdx = %d\r\n", this->globals->animMatrixIdx); this->globals->ledBrightnessPercent= pref.getUInt("ledBrightPcent", 40); LOGF_DEBUG("(FSM) -> ledBrightPcent = %d\r\n", this->globals->ledBrightnessPercent); pref.end(); diff --git a/src/states/AnimateMatrix.cpp b/src/states/AnimateMatrix.cpp index 3a58b96..cc47b35 100644 --- a/src/states/AnimateMatrix.cpp +++ b/src/states/AnimateMatrix.cpp @@ -29,6 +29,17 @@ #include "FSMState.h" +const int hue_list[] = { + 130, // Start with matrix, I mean Eurofurence, green <3 + 160, + 200, + 240, + 280, + 320, + 0, + 40, + 80, +}; const char* AnimateMatrix::getName() { return "AnimateMatrix"; @@ -47,25 +58,27 @@ void AnimateMatrix::entry() { } void AnimateMatrix::run() { - // Prepare base pattern + // map the 360 degree hue value to a byte + int mappedHue = map(hue_list[this->globals->animMatrixIdx], 0, 359, 0, 255); + std::vector dragon = { CRGB::Black, - CHSV(95, 255, 110), - CHSV(95, 255, 255), - CHSV(95, 255, 110), + CHSV(mappedHue, 255, 40), + CHSV(mappedHue, 255, 110), + CHSV(mappedHue, 255, 255), CRGB::Black, CRGB::Black }; std::vector bar = { - CHSV(95, 255, 110), - CHSV(95, 255, 255), - CHSV(95, 255, 110), + CHSV(mappedHue, 255, 50), + CHSV(mappedHue, 255, 110), + CHSV(mappedHue, 255, 255), CRGB::Black, CRGB::Black, - CHSV(95, 255, 110), - CHSV(95, 255, 255), - CHSV(95, 255, 110), + CHSV(mappedHue, 255, 70), + CHSV(mappedHue, 255, 100), + CHSV(mappedHue, 255, 200), CRGB::Black, CRGB::Black, CRGB::Black, @@ -85,3 +98,12 @@ void AnimateMatrix::run() { std::unique_ptr AnimateMatrix::touchEventFingerprintShortpress() { return std::make_unique(); } + +std::unique_ptr AnimateMatrix::touchEventFingerprintRelease() { + this->globals->animMatrixIdx = (this->globals->animMatrixIdx + 1) % 9; + this->is_globals_dirty = true; + this->tick = 0; + + return nullptr; +} +