diff --git a/components/esp-gui-lib b/components/esp-gui-lib index 8c450b8..65a8c98 160000 --- a/components/esp-gui-lib +++ b/components/esp-gui-lib @@ -1 +1 @@ -Subproject commit 8c450b8116d2aa1c982843a0b6144f626b721301 +Subproject commit 65a8c98530c37d209bd7e40c9d509b9e7407edeb diff --git a/config_allfeatures.cmake b/config_allfeatures.cmake index 2526881..7ba4ece 100644 --- a/config_allfeatures.cmake +++ b/config_allfeatures.cmake @@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_6WIRESW_IN3=18 -DPINS_DPAD_6WIRESW_IN4=19 -DPINS_DPAD_6WIRESW_IN5=26 - -# -DDPAD_5WIRESW_UP=1 -# -DDPAD_5WIRESW_DOWN=5 -# -DDPAD_5WIRESW_CONFIRM=2 -# -DDPAD_5WIRESW_BACK=6 -# -DDPAD_5WIRESW_PROFILE0=4 -# -DDPAD_5WIRESW_PROFILE1=0 -# -DDPAD_5WIRESW_PROFILE2=7 -# -DDPAD_5WIRESW_PROFILE3=3 -# -DDPAD_5WIRESW_DEBUG - - -DDPAD_6WIRESW_UP=1 - -DDPAD_6WIRESW_DOWN=5 - -DDPAD_6WIRESW_CONFIRM=2 - -DDPAD_6WIRESW_BACK=6 - -DDPAD_6WIRESW_PROFILE0=4 - -DDPAD_6WIRESW_PROFILE1=0 - -DDPAD_6WIRESW_PROFILE2=7 - -DDPAD_6WIRESW_PROFILE3=3 - -DDPAD_6WIRESW_BLINK_LEFT=8 - -DDPAD_6WIRESW_BLINK_RIGHT=9 -# -DDPAD_6WIRESW_DEBUG -DFEATURE_GSCHISSENE_DIODE - -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_comred.cmake b/config_comred.cmake index dbc51d7..3def8b2 100644 --- a/config_comred.cmake +++ b/config_comred.cmake @@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_6WIRESW_IN3=18 -DPINS_DPAD_6WIRESW_IN4=19 -DPINS_DPAD_6WIRESW_IN5=26 - -# -DDPAD_5WIRESW_UP=1 -# -DDPAD_5WIRESW_DOWN=5 -# -DDPAD_5WIRESW_CONFIRM=2 -# -DDPAD_5WIRESW_BACK=6 -# -DDPAD_5WIRESW_PROFILE0=4 -# -DDPAD_5WIRESW_PROFILE1=0 -# -DDPAD_5WIRESW_PROFILE2=7 -# -DDPAD_5WIRESW_PROFILE3=3 -# -DDPAD_5WIRESW_DEBUG - - -DDPAD_6WIRESW_UP=1 - -DDPAD_6WIRESW_DOWN=5 - -DDPAD_6WIRESW_CONFIRM=2 - -DDPAD_6WIRESW_BACK=6 - -DDPAD_6WIRESW_PROFILE0=4 - -DDPAD_6WIRESW_PROFILE1=0 - -DDPAD_6WIRESW_PROFILE2=7 - -DDPAD_6WIRESW_PROFILE3=3 - -DDPAD_6WIRESW_BLINK_LEFT=8 - -DDPAD_6WIRESW_BLINK_RIGHT=9 -# -DDPAD_6WIRESW_DEBUG -DFEATURE_GSCHISSENE_DIODE - -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index 5372cac..f68a5bb 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -48,19 +48,6 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_5WIRESW_IN1=27 -DPINS_DPAD_5WIRESW_IN2=32 -DPINS_DPAD_5WIRESW_IN3=33 - -DDPAD_5WIRESW_UP=2 - -DDPAD_5WIRESW_DOWN=11 - -DDPAD_5WIRESW_CONFIRM=5 - -DDPAD_5WIRESW_BACK=8 - -DDPAD_5WIRESW_PROFILE0=4 - -DDPAD_5WIRESW_PROFILE1=1 - -DDPAD_5WIRESW_PROFILE2=10 - -DDPAD_5WIRESW_PROFILE3=7 - -DDPAD_5WIRESW_BLINK_LEFT=9 - -DDPAD_5WIRESW_BLINK_RIGHT=0 - -DDPAD_5WIRESW_QUICKACTION_DOWN=3 - -DDPAD_5WIRESW_QUICKACTION_UP=6 -# -DDPAD_5WIRESW_DEBUG -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_greyhash.cmake b/config_greyhash.cmake index 76582e3..0582c50 100644 --- a/config_greyhash.cmake +++ b/config_greyhash.cmake @@ -48,15 +48,6 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_5WIRESW_IN2=27 -DPINS_DPAD_5WIRESW_IN3=18 -DPINS_DPAD_5WIRESW_IN4=19 - -DDPAD_5WIRESW_UP=1 - -DDPAD_5WIRESW_DOWN=5 - -DDPAD_5WIRESW_CONFIRM=2 - -DDPAD_5WIRESW_BACK=6 - -DDPAD_5WIRESW_PROFILE0=4 - -DDPAD_5WIRESW_PROFILE1=0 - -DDPAD_5WIRESW_PROFILE2=7 - -DDPAD_5WIRESW_PROFILE3=3 -# -DDPAD_5WIRESW_DEBUG # -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_mick.cmake b/config_mick.cmake index 1380aff..8a8ae57 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -48,15 +48,6 @@ set(BOBBYCAR_BUILDFLAGS # -DPINS_DPAD_5WIRESW_IN2=27 # -DPINS_DPAD_5WIRESW_IN3=18 # -DPINS_DPAD_5WIRESW_IN4=19 -# -DDPAD_5WIRESW_UP=1 -# -DDPAD_5WIRESW_DOWN=5 -# -DDPAD_5WIRESW_CONFIRM=2 -# -DDPAD_5WIRESW_BACK=6 -# -DDPAD_5WIRESW_PROFILE0=4 -# -DDPAD_5WIRESW_PROFILE1=0 -# -DDPAD_5WIRESW_PROFILE2=7 -# -DDPAD_5WIRESW_PROFILE3=3 -# -DDPAD_5WIRESW_DEBUG -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_nofeatures.cmake b/config_nofeatures.cmake index e9a61cd..ed8b295 100644 --- a/config_nofeatures.cmake +++ b/config_nofeatures.cmake @@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_6WIRESW_IN3=18 -DPINS_DPAD_6WIRESW_IN4=19 -DPINS_DPAD_6WIRESW_IN5=26 - -# -DDPAD_5WIRESW_UP=1 -# -DDPAD_5WIRESW_DOWN=5 -# -DDPAD_5WIRESW_CONFIRM=2 -# -DDPAD_5WIRESW_BACK=6 -# -DDPAD_5WIRESW_PROFILE0=4 -# -DDPAD_5WIRESW_PROFILE1=0 -# -DDPAD_5WIRESW_PROFILE2=7 -# -DDPAD_5WIRESW_PROFILE3=3 -# -DDPAD_5WIRESW_DEBUG - - -DDPAD_6WIRESW_UP=1 - -DDPAD_6WIRESW_DOWN=5 - -DDPAD_6WIRESW_CONFIRM=2 - -DDPAD_6WIRESW_BACK=6 - -DDPAD_6WIRESW_PROFILE0=4 - -DDPAD_6WIRESW_PROFILE1=0 - -DDPAD_6WIRESW_PROFILE2=7 - -DDPAD_6WIRESW_PROFILE3=3 - -DDPAD_6WIRESW_BLINK_LEFT=8 - -DDPAD_6WIRESW_BLINK_RIGHT=9 -# -DDPAD_6WIRESW_DEBUG # -DFEATURE_GSCHISSENE_DIODE - # -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/config_peter.cmake b/config_peter.cmake index 260d561..5529f87 100644 --- a/config_peter.cmake +++ b/config_peter.cmake @@ -48,19 +48,6 @@ set(BOBBYCAR_BUILDFLAGS -DPINS_DPAD_5WIRESW_IN1=4 -DPINS_DPAD_5WIRESW_IN2=5 -DPINS_DPAD_5WIRESW_IN3=27 - -DDPAD_5WIRESW_UP=4 - -DDPAD_5WIRESW_DOWN=7 - -DDPAD_5WIRESW_CONFIRM=1 - -DDPAD_5WIRESW_BACK=10 - -DDPAD_5WIRESW_PROFILE0=11 - -DDPAD_5WIRESW_PROFILE1=8 - -DDPAD_5WIRESW_PROFILE2=5 - -DDPAD_5WIRESW_PROFILE3=2 - -DDPAD_5WIRESW_BLINK_LEFT=9 - -DDPAD_5WIRESW_BLINK_RIGHT=0 - -DDPAD_5WIRESW_QUICKACTION_DOWN=3 - -DDPAD_5WIRESW_QUICKACTION_UP=6 - # -DDPAD_5WIRESW_DEBUG -DFEATURE_BLE # -DFEATURE_BLUETOOTH # -DFEATURE_BMS diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index caffdb1..25ea2b4 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -11,7 +11,6 @@ set(headers bobbycheckbox.h bobbyerrorhandler.h buildserver.h - buttons.h can.h changevaluedisplay_bluetoothmode.h changevaluedisplay_controlmode.h @@ -110,11 +109,8 @@ set(headers displays/bobbymenudisplay.h displays/bobbypopupdisplay.h displays/bobbysplitgraphdisplay.h - displays/calibratedisplay.h + displays/buttoncalibratedisplay.h displays/calibratevoltagedisplay.h - displays/dpad5wire2outdebugdisplay.h - displays/dpad5wiredebugdisplay.h - displays/dpad6wiredebugdisplay.h displays/gameoflifedisplay.h displays/gametrakcalibratedisplay.h displays/ledstripcolorsdisplay.h @@ -185,6 +181,7 @@ set(headers displays/menus/wifistasettingsmenu.h displays/metersdisplay.h displays/pingpongdisplay.h + displays/potiscalibratedisplay.h displays/poweroffdisplay.h displays/powersupplydisplay.h displays/qrcodedebug.h @@ -228,7 +225,6 @@ set(headers modes/tempomatmode.h texthelpers/networktexthelpers.h texthelpers/wifiaptexthelpers.h - texthelpers/wifistaconfigtexthelpers.h texthelpers/wifistatexthelpers.h widgets/doubleprogressbar.h ) @@ -244,7 +240,6 @@ set(sources bobbybuttons.cpp bobbyerrorhandler.cpp buildserver.cpp - buttons.cpp can.cpp changevaluedisplay_bluetoothmode.cpp changevaluedisplay_controlmode.cpp @@ -340,11 +335,8 @@ set(sources displays/bobbymenudisplay.cpp displays/bobbypopupdisplay.cpp displays/bobbysplitgraphdisplay.cpp - displays/calibratedisplay.cpp + displays/buttoncalibratedisplay.cpp displays/calibratevoltagedisplay.cpp - displays/dpad5wire2outdebugdisplay.cpp - displays/dpad5wiredebugdisplay.cpp - displays/dpad6wiredebugdisplay.cpp displays/gameoflifedisplay.cpp displays/gametrakcalibratedisplay.cpp displays/ledstripcolorsdisplay.cpp @@ -413,6 +405,7 @@ set(sources displays/menus/wifistasettingsmenu.cpp displays/metersdisplay.cpp displays/pingpongdisplay.cpp + displays/potiscalibratedisplay.cpp displays/poweroffdisplay.cpp displays/powersupplydisplay.cpp displays/qrcodedebug.cpp @@ -456,7 +449,6 @@ set(sources modes/tempomatmode.cpp texthelpers/networktexthelpers.cpp texthelpers/wifiaptexthelpers.cpp - texthelpers/wifistaconfigtexthelpers.cpp texthelpers/wifistatexthelpers.cpp widgets/doubleprogressbar.cpp ) diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index a4e925c..736ea58 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -14,6 +14,9 @@ struct AutoConnectBmsAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.autoConnectBms; } }; #endif +// Bluetooth +struct BluetoothNameAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.bluetoothName; } }; + // Buzzer struct ReverseBeepAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeep; } }; struct ReverseBeepFreq0Accessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.reverseBeepFreq0; } }; @@ -61,6 +64,7 @@ struct TimezoneOffsetAccessor : public NewSettingsChronoAdaptorAccessor { ConfigWrapper &getConfig() const override { return configs.timeDst; } }; #ifdef FEATURE_NTP struct TimeServerEnabledAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeServerEnabled; } }; +struct TimeServerAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeServer; } }; struct TimeSyncModeAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncMode; } }; //struct TimeSyncIntervalAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncInterval; } }; struct TimeSyncIntervalAccessor : public NewSettingsChronoAdaptorAccessor { ConfigWrapper &getConfig() const override { return configs.timeSyncInterval; } }; diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h index 9f705c5..3dd39ad 100644 --- a/main/actions/ledstripanimationactions.h +++ b/main/actions/ledstripanimationactions.h @@ -1,11 +1,14 @@ #pragma once +// 3rdparty lib includes #include "actioninterface.h" + +// local includes #include "ledstrip.h" -// #include "ledstripdefines.h" +#include "ledstripdefines.h" #ifdef FEATURE_LEDSTRIP -template +template class LedStripSetAnimationAction : public virtual espgui::ActionInterface { public: diff --git a/main/bobbybuttons.cpp b/main/bobbybuttons.cpp index 8a4b5cd..8b35a19 100644 --- a/main/bobbybuttons.cpp +++ b/main/bobbybuttons.cpp @@ -1,7 +1,20 @@ #include "bobbybuttons.h" +// esp-idf includes +#include + // local includes #include "newsettings.h" +#include "settingsutils.h" +#include "modes/defaultmode.h" +#ifdef FEATURE_LEDSTRIP +#include "ledstripdefines.h" +#include "ledstrip.h" +#endif + +namespace { +constexpr const char TAG[] = "BUTTONS"; +} // namespace [[nodiscard]] std::optional translateRawButton(uint8_t button) { @@ -35,6 +48,8 @@ if (configs.dpadMappingDown2.value == button) return Button(BobbyButton::Down2); + ESP_LOGW(TAG, "unknown raw button %hhu", button); + return std::nullopt; } @@ -42,14 +57,64 @@ void buttonPressedCommon(espgui::Button button) { switch (BobbyButton(button)) { - case BobbyButton::Profile0: /* TODO */ break; - case BobbyButton::Profile1: /* TODO */ break; - case BobbyButton::Profile2: /* TODO */ break; - case BobbyButton::Profile3: /* TODO */ break; - case BobbyButton::Left2: /* TODO */ break; - case BobbyButton::Right2: /* TODO */ break; - case BobbyButton::Up2: /* TODO */ break; - case BobbyButton::Down2: /* TODO */ break; + case BobbyButton::Profile0: + settingsutils::switchProfile(0); + break; + case BobbyButton::Profile1: + settingsutils::switchProfile(1); + break; + case BobbyButton::Profile2: + settingsutils::switchProfile(2); + break; + case BobbyButton::Profile3: + settingsutils::switchProfile(3); + break; + case BobbyButton::Left2: +#ifdef FEATURE_LEDSTRIP + if (blinkAnimation == LEDSTRIP_OVERWRITE_NONE) //transition from off to left + { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; + } + else if (blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT) // transition to warning + { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; + } + else // transition to off + { + blinkAnimation = LEDSTRIP_OVERWRITE_NONE; + } +#endif + break; + case BobbyButton::Right2: +#ifdef FEATURE_LEDSTRIP + if (blinkAnimation == LEDSTRIP_OVERWRITE_NONE) //transition from off to right + { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; + } + else if (blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT) // transition to warning + { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; + } + else // transition to off + { + blinkAnimation = LEDSTRIP_OVERWRITE_NONE; + } +#endif + break; + case BobbyButton::Up2: + if (settings.handbremse.enable) + { + using namespace handbremse; + if (stateWish == StateWish::brake || angezogen) + stateWish = StateWish::release; + else + stateWish = StateWish::brake; + wishTimer = espchrono::millis_clock::now(); + } + break; + case BobbyButton::Down2: + /* TODO */ + break; default:; } } diff --git a/main/buttons.cpp b/main/buttons.cpp deleted file mode 100644 index 9abc31a..0000000 --- a/main/buttons.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include "buttons.h" -#include "modes/defaultmode.h" - -using namespace std::chrono_literals; - -int rotated{}; -bool requestFullRedraw{}; - -bool confirmButtonPressed{}; -bool confirmButtonLongPressed{}; -bool backButtonPressed{}; -bool backButtonLongPressed{}; - -bool profileButtonDisabled{}; - -std::optional upPressedSince; -int upPressRepeat{}; -std::optional downPressedSince; -int downPressRepeat{}; - -void InputDispatcher::init() -{ - -} - -void InputDispatcher::update() -{ - if (upPressedSince && espchrono::ago(*upPressedSince) > (upPressRepeat > 2 ? 50ms : 400ms)) - { - upPressedSince = espchrono::millis_clock::now(); - upPressRepeat++; - rotated -= 1; - } - - if (downPressedSince && espchrono::ago(*downPressedSince) > (downPressRepeat > 2 ? 50ms : 400ms)) - { - downPressedSince = espchrono::millis_clock::now(); - downPressRepeat++; - rotated += 1; - } -} - -void InputDispatcher::rotate(int offset) -{ - rotated += offset; -} - -void InputDispatcher::upButton(bool pressed) -{ - if (pressed) - { - upPressedSince = espchrono::millis_clock::now(); - upPressRepeat = 0; - rotated -= 1; - } - else - { - upPressedSince = std::nullopt; - } -} - -void InputDispatcher::downButton(bool pressed) -{ - if (pressed) - { - downPressedSince = espchrono::millis_clock::now(); - downPressRepeat = 0; - rotated += 1; - } - else - { - downPressedSince = std::nullopt; - } -} - -void InputDispatcher::confirmButton(bool pressed) -{ - static espchrono::millis_clock::time_point pressBegin{}; - - const auto now = espchrono::millis_clock::now(); - - if (pressed) - pressBegin = now; - else - { - const auto duration = now - pressBegin; - - if (duration < 500ms) - confirmButtonPressed = true; - else if (duration < 2000ms) - confirmButtonLongPressed = true; - else - requestFullRedraw = true; - - pressBegin = {}; - } -} - -void InputDispatcher::backButton(bool pressed) -{ - static espchrono::millis_clock::time_point pressBegin{}; - - const auto now = espchrono::millis_clock::now(); - - if (pressed) - pressBegin = now; - else - { - const auto duration = now - pressBegin; - - if (duration < 500ms) - backButtonPressed = true; - else - backButtonLongPressed = true; - - pressBegin = {}; - } -} - -void InputDispatcher::profileButton(uint8_t index, bool pressed) -{ - if (!pressed) - return; - - if (profileButtonDisabled) - return; - - settingsutils::switchProfile(index); -} - -#ifdef SWITCH_BLINK -void InputDispatcher::blinkRightButton(bool pressed) -#else -void InputDispatcher::blinkLeftButton(bool pressed) -#endif -{ - if(!pressed)return; - -#ifdef FEATURE_LEDSTRIP - if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to left - blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; - } - else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT){ // transition to warning - blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; - } - else{ // transition to off - blinkAnimation = LEDSTRIP_OVERWRITE_NONE; - } -#endif -} - -#ifndef SWITCH_BLINK -void InputDispatcher::blinkRightButton(bool pressed) -#else -void InputDispatcher::blinkLeftButton(bool pressed) -#endif -{ - if(!pressed)return; -#ifdef FEATURE_LEDSTRIP - if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to right - blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; - } - else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT){ // transition to warning - blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; - } - else{ // transition to off - blinkAnimation = LEDSTRIP_OVERWRITE_NONE; - } -#endif -} - -void InputDispatcher::quickActionButtonDown(bool pressed) -{ - using namespace handbremse; - - if(!pressed)return; - - if (settings.handbremse.enable) - { - if (stateWish == StateWish::brake || angezogen) - stateWish = StateWish::release; - else - stateWish = StateWish::brake; - wishTimer = espchrono::millis_clock::now(); - } -} - -void InputDispatcher::quickActionButtonUp(bool pressed) -{ - -} diff --git a/main/buttons.h b/main/buttons.h deleted file mode 100644 index 90eb642..0000000 --- a/main/buttons.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -// system includes -#include - -// 3rdparty lib includes -#include - -// local includes -#include "settingsutils.h" -#include "ledstripdefines.h" - -#ifdef FEATURE_LEDSTRIP -#include "ledstrip.h" -#endif - -extern int rotated; -extern bool requestFullRedraw; - -extern bool confirmButtonPressed; -extern bool confirmButtonLongPressed; -extern bool backButtonPressed; -extern bool backButtonLongPressed; - -extern bool profileButtonDisabled; - -extern std::optional upPressedSince; -extern int upPressRepeat; -extern std::optional downPressedSince; -extern int downPressRepeat; - -class InputDispatcher -{ -public: - static void init(); - - static void update(); - - static void rotate(int offset); - - static void upButton(bool pressed); - - static void downButton(bool pressed); - - static void confirmButton(bool pressed); - - static void backButton(bool pressed); - - static void profileButton(uint8_t index, bool pressed); - - static void blinkLeftButton(bool pressed); - - static void blinkRightButton(bool pressed); - - static void quickActionButtonDown(bool pressed); - - static void quickActionButtonUp(bool pressed); -}; diff --git a/main/debuginputhandler.cpp b/main/debuginputhandler.cpp index 89bbeb9..76ceaf2 100644 --- a/main/debuginputhandler.cpp +++ b/main/debuginputhandler.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include // local includes #include "globals.h" @@ -22,6 +24,9 @@ constexpr const char * const TAG = "DEBUG"; uint8_t consoleControlCharsReceived{}; bool uart0Initialized{}; + +void handleNormalChar(char c); +void handleSpecialChar(char c); } // namespace void initDebugInput() @@ -70,112 +75,140 @@ void handleDebugInput() else consoleControlCharsReceived = 0; break; - case 'i': - case 'I': - consoleControlCharsReceived = 0; - espgui::tft.init(); - break; - case 'p': - case 'P': - { - consoleControlCharsReceived = 0; - const auto firstPower = controllers.front.command.poweroff; - for (Controller &controller : controllers) - controller.command.poweroff = !firstPower; - break; - } - case 'l': - case 'L': - { - consoleControlCharsReceived = 0; - const auto firstLed = controllers.front.command.led; - for (Controller &controller : controllers) - controller.command.led = !firstLed; - break; - } - case 'r': - case 'R': - consoleControlCharsReceived = 0; - loadSettings(); - break; - case 's': - case 'S': - consoleControlCharsReceived = 0; - saveSettings(); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - consoleControlCharsReceived = 0; - for (Controller &controller : controllers) - controller.command.buzzer.freq = c-'0'; - break; - case 'z': - case 'Z': - consoleControlCharsReceived = 0; - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Left2)); - espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Left2)); - } - break; - case 'u': - case 'U': - consoleControlCharsReceived = 0; - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Right2)); - espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Right2)); - } - break; default: consoleControlCharsReceived = 0; + handleNormalChar(c); } } else { consoleControlCharsReceived = 0; - switch (c) - { - case 'A': // Up arrow pressed - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button::Up); - espgui::currentDisplay->buttonReleased(espgui::Button::Up); - } - break; - case 'B': // Down arrow pressed - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button::Down); - espgui::currentDisplay->buttonReleased(espgui::Button::Down); - } - break; - case 'C': // Right arrow pressed - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button::Right); - espgui::currentDisplay->buttonReleased(espgui::Button::Right); - } - break; - case 'D': // Left arrow pressed - if (espgui::currentDisplay) - { - espgui::currentDisplay->buttonPressed(espgui::Button::Left); - espgui::currentDisplay->buttonReleased(espgui::Button::Left); - } - break; - default: - ESP_LOGI(TAG, "unknown control char received: %hhx", c); - } + handleSpecialChar(c); } } } } + +namespace { +void handleNormalChar(char c) +{ + if (auto display = espgui::currentDisplay ? espgui::currentDisplay->asChangeValueDisplayString() : nullptr) + { + switch (c) + { + case ' ' ... '~': + display->setShownValue(display->shownValue() + c); + break; + case 8: + if (auto val = display->shownValue(); !val.empty()) + { + val.pop_back(); + display->setShownValue(std::move(val)); + } + break; + default: + ESP_LOGW(TAG, "unknown char %hhx %c", c, c); + } + } + else + { + switch (c) + { + case 'i': + case 'I': + espgui::tft.init(); + break; + case 'p': + case 'P': + { + const auto firstPower = controllers.front.command.poweroff; + for (Controller &controller : controllers) + controller.command.poweroff = !firstPower; + break; + } + case 'l': + case 'L': + { + const auto firstLed = controllers.front.command.led; + for (Controller &controller : controllers) + controller.command.led = !firstLed; + break; + } + case 'r': + case 'R': + loadSettings(); + break; + case 's': + case 'S': + saveSettings(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + for (Controller &controller : controllers) + controller.command.buzzer.freq = c-'0'; + break; + case 'z': + case 'Z': + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Left2)); + espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Left2)); + } + break; + case 'u': + case 'U': + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Right2)); + espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Right2)); + } + break; + } + } +} + +void handleSpecialChar(char c) +{ + switch (c) + { + case 'A': // Up arrow pressed + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button::Up); + espgui::currentDisplay->buttonReleased(espgui::Button::Up); + } + break; + case 'B': // Down arrow pressed + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button::Down); + espgui::currentDisplay->buttonReleased(espgui::Button::Down); + } + break; + case 'C': // Right arrow pressed + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button::Right); + espgui::currentDisplay->buttonReleased(espgui::Button::Right); + } + break; + case 'D': // Left arrow pressed + if (espgui::currentDisplay) + { + espgui::currentDisplay->buttonPressed(espgui::Button::Left); + espgui::currentDisplay->buttonReleased(espgui::Button::Left); + } + break; + default: + ESP_LOGI(TAG, "unknown control char received: %hhx", c); + } +} +} // namespace diff --git a/main/displays/buttoncalibratedisplay.cpp b/main/displays/buttoncalibratedisplay.cpp new file mode 100644 index 0000000..676a4bf --- /dev/null +++ b/main/displays/buttoncalibratedisplay.cpp @@ -0,0 +1,199 @@ +#include "buttoncalibratedisplay.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "newsettings.h" +#include "displays/menus/boardcomputerhardwaresettingsmenu.h" +#include "bobbyerrorhandler.h" + +namespace { +constexpr const char TAG[] = "BUTTON"; +} // namespace + +std::string ButtonCalibrateDisplay::text() const +{ + return "Button calibrate"; +} + +void ButtonCalibrateDisplay::start() +{ + Base::start(); + + m_oldMode = currentMode; + currentMode = &m_mode; + m_lastButton = std::nullopt; + m_status = WaitingLeft; + + m_finished = false; +} + +void ButtonCalibrateDisplay::initScreen() +{ + Base::initScreen(); + + m_labelInstruction.start(); + m_labelLeft.start(); + m_labelRight.start(); + m_labelUp.start(); + m_labelDown.start(); + m_labelEnd.start(); +} + +void ButtonCalibrateDisplay::update() +{ + Base::update(); + + if (m_finished) + { + m_finished = false; + + if (auto result = configs.write_config(configs.dpadMappingLeft, m_leftButton); !result) + { + BobbyErrorHandler{}.errorOccured(std::move(result).error()); + return; + } + if (auto result = configs.write_config(configs.dpadMappingRight, m_rightButton); !result) + { + BobbyErrorHandler{}.errorOccured(std::move(result).error()); + return; + } + if (auto result = configs.write_config(configs.dpadMappingUp, m_upButton); !result) + { + BobbyErrorHandler{}.errorOccured(std::move(result).error()); + return; + } + if (auto result = configs.write_config(configs.dpadMappingDown, m_downButton); !result) + { + BobbyErrorHandler{}.errorOccured(std::move(result).error()); + return; + } + + espgui::switchScreen(); + } +} + +void ButtonCalibrateDisplay::redraw() +{ + Base::redraw(); + + espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK); + + switch (m_status) + { + case WaitingLeft: + if (m_lastButton) + m_labelInstruction.redraw("Press LEFT again"); + else + m_labelInstruction.redraw("Press LEFT"); + break; + case WaitingRight: + if (m_lastButton) + m_labelInstruction.redraw("Press RIGHT again"); + else + m_labelInstruction.redraw("Press RIGHT"); + break; + case WaitingUp: + if (m_lastButton) + m_labelInstruction.redraw("Press UP again"); + else + m_labelInstruction.redraw("Press UP"); + break; + case WaitingDown: + if (m_lastButton) + m_labelInstruction.redraw("Press DOWN again"); + else + m_labelInstruction.redraw("Press DOWN"); + break; + case Finished: + m_labelInstruction.redraw("Finished"); + break; + } + + m_labelLeft.redraw(m_status > WaitingLeft ? fmt::format("Left: {}", m_leftButton) : std::string{}); + m_labelRight.redraw(m_status > WaitingRight ? fmt::format("Right: {}", m_rightButton) : std::string{}); + m_labelUp.redraw(m_status > WaitingUp ? fmt::format("Up: {}", m_upButton) : std::string{}); + m_labelDown.redraw(m_status > WaitingDown ? fmt::format("Down: {}", m_downButton) : std::string{}); + + m_labelEnd.redraw(m_status == Finished ? "Press RIGHT to save" : ""); +} + +void ButtonCalibrateDisplay::stop() +{ + Base::stop(); + + if (currentMode == &m_mode) + { + // to avoid crash after deconstruction + m_mode.stop(); + lastMode = nullptr; + + currentMode = m_oldMode; + } +} + +void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button) +{ + //Base::rawButtonPressed(button); + + if (m_status == Finished) + { + if (button == m_rightButton) + { + ESP_LOGI(TAG, "correct button"); + m_finished = true; + } + else + ESP_LOGI(TAG, "wrong button"); + } + else if (!m_lastButton || *m_lastButton != button) + m_lastButton = button; + else + { + switch (m_status) + { + case WaitingLeft: + m_leftButton = button; + m_lastButton = std::nullopt; + m_status = WaitingRight; + break; + case WaitingRight: + m_rightButton = button; + m_lastButton = std::nullopt; + m_status = WaitingUp; + break; + case WaitingUp: + m_upButton = button; + m_lastButton = std::nullopt; + m_status = WaitingDown; + break; + case WaitingDown: + m_downButton = button; + m_lastButton = std::nullopt; + m_status = Finished; + break; + case Finished:; + } + } +} + +void ButtonCalibrateDisplay::rawButtonReleased(uint8_t button) +{ + //Base::rawButtonReleased(button); +} + +void ButtonCalibrateDisplay::buttonPressed(espgui::Button button) +{ + //Base::buttonPressed(button); +} + +void ButtonCalibrateDisplay::buttonReleased(espgui::Button button) +{ + //Base::buttonReleased(button); +} diff --git a/main/displays/buttoncalibratedisplay.h b/main/displays/buttoncalibratedisplay.h new file mode 100644 index 0000000..135eac0 --- /dev/null +++ b/main/displays/buttoncalibratedisplay.h @@ -0,0 +1,53 @@ +#pragma once + +// 3rdparty lib includes +#include +#include + +// local includes +#include "globals.h" +#include "modeinterface.h" +#include "modes/ignoreinputmode.h" + +class ButtonCalibrateDisplay : public espgui::DisplayWithTitle +{ + using Base = espgui::DisplayWithTitle; + +public: + ButtonCalibrateDisplay() = default; + explicit ButtonCalibrateDisplay(bool bootup) : m_bootup{bootup} {} + + std::string text() const override; + void start() override; + void initScreen() override; + void update() override; + void redraw() override; + void stop() override; + + void rawButtonPressed(uint8_t button) override; + void rawButtonReleased(uint8_t button) override; + void buttonPressed(espgui::Button button) override; + void buttonReleased(espgui::Button button) override; + +private: + const bool m_bootup{false}; + ModeInterface *m_oldMode; + IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque}; + + std::optional m_lastButton; + + enum { WaitingLeft, WaitingRight, WaitingUp, WaitingDown, Finished } m_status; + + espgui::Label m_labelInstruction{25, 72}; + + espgui::Label m_labelLeft{25, 100}; + espgui::Label m_labelRight{25, 125}; + espgui::Label m_labelUp{25, 150}; + espgui::Label m_labelDown{25, 175}; + + espgui::Label m_labelEnd{25, 225}; + + uint8_t m_leftButton, m_rightButton, m_upButton, m_downButton; + + bool m_finished; +}; diff --git a/main/displays/dpad5wire2outdebugdisplay.cpp b/main/displays/dpad5wire2outdebugdisplay.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/displays/dpad5wire2outdebugdisplay.h b/main/displays/dpad5wire2outdebugdisplay.h deleted file mode 100644 index 67776f5..0000000 --- a/main/displays/dpad5wire2outdebugdisplay.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -#include "display.h" -#include "globals.h" -#include "widgets/label.h" -#include "dpad5wire_2out.h" - -namespace { -#ifdef FEATURE_DPAD_5WIRESW_2OUT -class DPad5Wire2OutDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack -{ -public: - void initScreen() override; - void redraw() override; - -private: - Label m_labelRaw{0, 50}; - Label m_labelUp{175, 75}; - Label m_labelDown{175, 100}; - Label m_labelBack{175, 125}; - Label m_labelConfirm{175, 150}; - Label m_labelProfile0{175, 175}; - Label m_labelProfile1{175, 200}; - Label m_labelProfile2{175, 225}; - Label m_labelProfile3{175, 250}; - Label m_labelGas{175, 275}; - Label m_labelBrems{175, 300}; -}; - -void DPad5Wire2OutDebugDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString("DPad 5wire debug", 5, 5); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.drawString("UP:", 30, 75); - tft.drawString("DOWN:", 30, 100); - tft.drawString("CONFIRM:", 30, 125); - tft.drawString("BACK:", 30, 150); - tft.drawString("PROFILE0:", 30, 175); - tft.drawString("PROFILE1:", 30, 200); - tft.drawString("PROFILE2:", 30, 225); - tft.drawString("PROFILE3:", 30, 250); - tft.drawString("GAS:", 30, 275); - tft.drawString("BREMS:", 30, 300); - - m_labelRaw.start(); - m_labelUp.start(); - m_labelDown.start(); - m_labelBack.start(); - m_labelConfirm.start(); - m_labelProfile0.start(); - m_labelProfile1.start(); - m_labelProfile2.start(); - m_labelProfile3.start(); - m_labelGas.start(); - m_labelBrems.start(); -} - -void DPad5Wire2OutDebugDisplay::redraw() -{ - m_labelRaw.redraw(std::string{} + - (std::get<0>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<1>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<2>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<3>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<4>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<5>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<6>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<7>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<8>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<9>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<10>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' + - (std::get<11>(dpad5wire_2out::lastState) ? '1' : '0')); - - m_labelUp.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelDown.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelBack.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelConfirm.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelProfile0.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelProfile1.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelProfile2.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelProfile3.redraw(std::get(dpad5wire_2out::lastState) ? "1" : "0"); - m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?"); - m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?"); -} -#endif -} diff --git a/main/displays/dpad5wiredebugdisplay.cpp b/main/displays/dpad5wiredebugdisplay.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/displays/dpad5wiredebugdisplay.h b/main/displays/dpad5wiredebugdisplay.h deleted file mode 100644 index c0137be..0000000 --- a/main/displays/dpad5wiredebugdisplay.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include "display.h" -#include "globals.h" -#include "widgets/label.h" -#include "dpad5wire.h" - -namespace { -#ifdef FEATURE_DPAD_5WIRESW -class DPad5WireDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack -{ -public: - void initScreen() override; - void redraw() override; - -private: - Label m_labelRaw{30, 50}; - Label m_labelUp{175, 75}; - Label m_labelDown{175, 100}; - Label m_labelBack{175, 125}; - Label m_labelConfirm{175, 150}; - Label m_labelProfile0{175, 175}; - Label m_labelProfile1{175, 200}; - Label m_labelProfile2{175, 225}; - Label m_labelProfile3{175, 250}; - Label m_labelGas{175, 275}; - Label m_labelBrems{175, 300}; -}; - -void DPad5WireDebugDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString("DPad 5wire debug", 5, 5); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.drawString("UP:", 30, 75); - tft.drawString("DOWN:", 30, 100); - tft.drawString("CONFIRM:", 30, 125); - tft.drawString("BACK:", 30, 150); - tft.drawString("PROFILE0:", 30, 175); - tft.drawString("PROFILE1:", 30, 200); - tft.drawString("PROFILE2:", 30, 225); - tft.drawString("PROFILE3:", 30, 250); - tft.drawString("GAS:", 30, 275); - tft.drawString("BREMS:", 30, 300); - - m_labelRaw.start(); - m_labelUp.start(); - m_labelDown.start(); - m_labelBack.start(); - m_labelConfirm.start(); - m_labelProfile0.start(); - m_labelProfile1.start(); - m_labelProfile2.start(); - m_labelProfile3.start(); - m_labelGas.start(); - m_labelBrems.start(); -} - -void DPad5WireDebugDisplay::redraw() -{ - m_labelRaw.redraw(std::string{} + - (std::get<0>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<1>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<2>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<3>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<4>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<5>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<6>(dpad5wire::lastState) ? '1' : '0') + ' ' + - (std::get<7>(dpad5wire::lastState) ? '1' : '0')); - - m_labelUp.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelDown.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelBack.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelConfirm.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelProfile0.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelProfile1.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelProfile2.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelProfile3.redraw(std::get(dpad5wire::lastState) ? "1" : "0"); - m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?"); - m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?"); -} -#endif -} diff --git a/main/displays/dpad6wiredebugdisplay.cpp b/main/displays/dpad6wiredebugdisplay.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/displays/dpad6wiredebugdisplay.h b/main/displays/dpad6wiredebugdisplay.h deleted file mode 100644 index 783651c..0000000 --- a/main/displays/dpad6wiredebugdisplay.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -#include "display.h" -#include "globals.h" -#include "widgets/label.h" -#include "dpad6wire.h" - -namespace { -#ifdef FEATURE_DPAD_6WIRESW -class DPad6WireDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack -{ -public: - void initScreen() override; - void redraw() override; - -private: - Label m_labelRaw{0, 50}; - Label m_labelUp{175, 75}; - Label m_labelDown{175, 100}; - Label m_labelBack{175, 125}; - Label m_labelConfirm{175, 150}; - Label m_labelProfile0{175, 175}; - Label m_labelProfile1{175, 200}; - Label m_labelProfile2{175, 225}; - Label m_labelProfile3{175, 250}; - Label m_labelGas{175, 275}; - Label m_labelBrems{175, 300}; -}; - -void DPad6WireDebugDisplay::initScreen() -{ - tft.fillScreen(TFT_BLACK); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW); - - tft.drawString("DPad 5wire debug", 5, 5); - - tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.drawString("UP:", 30, 75); - tft.drawString("DOWN:", 30, 100); - tft.drawString("CONFIRM:", 30, 125); - tft.drawString("BACK:", 30, 150); - tft.drawString("PROFILE0:", 30, 175); - tft.drawString("PROFILE1:", 30, 200); - tft.drawString("PROFILE2:", 30, 225); - tft.drawString("PROFILE3:", 30, 250); - tft.drawString("GAS:", 30, 275); - tft.drawString("BREMS:", 30, 300); - - m_labelRaw.start(); - m_labelUp.start(); - m_labelDown.start(); - m_labelBack.start(); - m_labelConfirm.start(); - m_labelProfile0.start(); - m_labelProfile1.start(); - m_labelProfile2.start(); - m_labelProfile3.start(); - m_labelGas.start(); - m_labelBrems.start(); -} - -void DPad6WireDebugDisplay::redraw() -{ - m_labelRaw.redraw(std::string{} + - (std::get<0>(dpad6wire::lastState) ? 'Z' : '0') + ' ' + - (std::get<1>(dpad6wire::lastState) ? '1' : '0') + ' ' + - (std::get<2>(dpad6wire::lastState) ? '2' : '0') + ' ' + - (std::get<3>(dpad6wire::lastState) ? '3' : '0') + ' ' + - (std::get<4>(dpad6wire::lastState) ? '4' : '0') + ' ' + - (std::get<5>(dpad6wire::lastState) ? '5' : '0') + ' ' + - (std::get<6>(dpad6wire::lastState) ? '6' : '0') + ' ' + - (std::get<7>(dpad6wire::lastState) ? '7' : '0') + ' ' + - (std::get<8>(dpad6wire::lastState) ? '8' : '0') + ' ' + - (std::get<9>(dpad6wire::lastState) ? '9' : '0')); - - m_labelUp.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelDown.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelBack.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelConfirm.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelProfile0.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelProfile1.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelProfile2.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelProfile3.redraw(std::get(dpad6wire::lastState) ? "1" : "0"); - m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?"); - m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?"); -} -#endif -} diff --git a/main/displays/lockscreen.cpp b/main/displays/lockscreen.cpp index 5990a20..1006073 100644 --- a/main/displays/lockscreen.cpp +++ b/main/displays/lockscreen.cpp @@ -8,7 +8,7 @@ #include "globals.h" #include "utils.h" #include "displays/menus/mainmenu.h" -#include "displays/calibratedisplay.h" +#include "displays/potiscalibratedisplay.h" #include "bobbybuttons.h" #ifdef LOCKSCREEN_PLUGIN #include "ledstripdefines.h" @@ -88,7 +88,7 @@ void Lockscreen::redraw() if (m_numbers == settings.lockscreen.pin) { if (!gas || !brems || *gas > 200.f || *brems > 200.f) - espgui::switchScreen(true); + espgui::switchScreen(true); else espgui::switchScreen(); #ifdef LOCKSCREEN_PLUGIN diff --git a/main/displays/menus/blesettingsmenu.cpp b/main/displays/menus/blesettingsmenu.cpp index 37d6d41..237e3e4 100644 --- a/main/displays/menus/blesettingsmenu.cpp +++ b/main/displays/menus/blesettingsmenu.cpp @@ -1,11 +1,15 @@ #include "blesettingsmenu.h" // 3rdparty lib includes -#include "actions/dummyaction.h" -#include "actions/switchscreenaction.h" -#include "icons/back.h" +#include +#include +#include +#include +#include +#include // local includes +#include "displays/bobbychangevaluedisplay.h" #include "accessors/settingsaccessors.h" #include "bletexthelpers.h" #include "displays/menus/settingsmenu.h" @@ -14,16 +18,27 @@ #ifdef FEATURE_BLE namespace { constexpr char TEXT_BLESETTINGS[] = "BLE settings"; -constexpr char TEXT_BLEENABLED[] = "BLE enabled"; +constexpr char TEXT_ENABLED[] = "Enabled"; +constexpr char TEXT_NAME[] = "Name"; +constexpr char TEXT_NAME_FORMATTED[] = "Name: &s"; constexpr char TEXT_BACK[] = "Back"; + +using ApSsidChangeScreen = espgui::makeComponent< + BobbyChangeValueDisplay, + espgui::StaticText, + BluetoothNameAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; } // namespace BleSettingsMenu::BleSettingsMenu() { using namespace espgui; - constructMenuItem, BobbyCheckbox, BleEnabledAccessor>>(); + constructMenuItem, BobbyCheckbox, BleEnabledAccessor>>(); constructMenuItem>(); constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } diff --git a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp index 9eb3e4d..0ae86cb 100644 --- a/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp +++ b/main/displays/menus/boardcomputerhardwaresettingsmenu.cpp @@ -14,14 +14,16 @@ #include "icons/lock.h" #include "accessors/settingsaccessors.h" #include "displays/menus/lockscreensettingsmenu.h" -#include "displays/calibratedisplay.h" +#include "displays/potiscalibratedisplay.h" #include "displays/menus/timersmenu.h" #include "displays/menus/settingsmenu.h" +#include "displays/buttoncalibratedisplay.h" namespace { constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings"; +constexpr char TEXT_BUTTONCALIBRATE[] = "Button Calibrate"; constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings"; -constexpr char TEXT_CALIBRATE[] = "Calibrate"; +constexpr char TEXT_POTISCALIBRATE[] = "Potis Calibrate"; constexpr char TEXT_SAMPLECOUNT[] = "sampleCount"; constexpr char TEXT_GASMIN[] = "gasMin"; constexpr char TEXT_GASMAX[] = "gasMax"; @@ -171,9 +173,10 @@ using namespace espgui; BoardcomputerHardwareSettingsMenu::BoardcomputerHardwareSettingsMenu() { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::lock>>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, DummyAction>>(); constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); diff --git a/main/displays/menus/timesettingsmenu.cpp b/main/displays/menus/timesettingsmenu.cpp index 1a44506..5a37766 100644 --- a/main/displays/menus/timesettingsmenu.cpp +++ b/main/displays/menus/timesettingsmenu.cpp @@ -8,6 +8,7 @@ #include "changevaluedisplay.h" #include "changevaluedisplay_daylightsavingmode.h" #include "changevaluedisplay_sntp_sync_mode_t.h" +#include "changevaluedisplay_string.h" #include "actions/switchscreenaction.h" #include "actions/dummyaction.h" #include "icons/back.h" @@ -69,6 +70,14 @@ using DaylightSavingModeChangeDisplay = espgui::makeComponent< >; #ifdef FEATURE_NTP +using TimeServerChangeDisplay = espgui::makeComponent< + BobbyChangeValueDisplay, + espgui::StaticText, + TimeServerAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + using TimeSyncModeChangeDisplay = espgui::makeComponent< BobbyChangeValueDisplay, espgui::StaticText, @@ -96,17 +105,16 @@ public: #endif } // namespace -using namespace espgui; - TimeSettingsMenu::TimeSettingsMenu() { + using namespace espgui; constructMenuItem, DummyAction>>(); constructMenuItem, DummyAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); #ifdef FEATURE_NTP constructMenuItem, BobbyCheckbox, TimeServerEnabledAccessor>>(); - constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem>(); @@ -121,5 +129,5 @@ std::string TimeSettingsMenu::text() const void TimeSettingsMenu::back() { - switchScreen(); + espgui::switchScreen(); } diff --git a/main/displays/menus/wifiapsettingsmenu.cpp b/main/displays/menus/wifiapsettingsmenu.cpp index 3dffe9c..f9884fa 100644 --- a/main/displays/menus/wifiapsettingsmenu.cpp +++ b/main/displays/menus/wifiapsettingsmenu.cpp @@ -16,6 +16,7 @@ #include "displays/bobbychangevaluedisplay.h" #include "changevaluedisplay.h" #include "changevaluedisplay_string.h" +#include "changevaluedisplay_ip_address_t.h" #include "changevaluedisplay_wifi_auth_mode_t.h" #include "wifiapclientsmenu.h" #include "networksettingsmenu.h" @@ -33,17 +34,17 @@ constexpr char TEXT_DISABLEWHENONLINE[] = "Disable when online"; constexpr char TEXT_BACK[] = "Back"; constexpr char TEXT_SSID[] = "AP SSID"; -constexpr char TEXT_SSID_FORMATTED[] = "&sssid: &2"; +constexpr char TEXT_SSID_FORMATTED[] = "&sssid: "; constexpr char TEXT_KEY[] = "AP Key"; -constexpr char TEXT_KEY_FORMATTED[] = "&skey: &2"; +constexpr char TEXT_KEY_FORMATTED[] = "&skey: "; constexpr char TEXT_IP[] = "AP IP"; -constexpr char TEXT_IP_FORMATTED[] = "&sIP: &f&2"; +constexpr char TEXT_IP_FORMATTED[] = "&sIP: &f"; constexpr char TEXT_MASK[] = "AP Mask"; -constexpr char TEXT_MASK_FORMATTED[] = "&sMask: &f&2"; +constexpr char TEXT_MASK_FORMATTED[] = "&sMask: &f"; constexpr char TEXT_CHANNEL[] = "AP Channel"; -constexpr char TEXT_CHANNEL_FORMATTED[] = "&sChannel: &f&2"; +constexpr char TEXT_CHANNEL_FORMATTED[] = "&sChannel: &f"; constexpr char TEXT_AUTHMODE[] = "AP Authmode"; -constexpr char TEXT_AUTHMODE_FORMATTED[] = "&sAuthmode: &2"; +constexpr char TEXT_AUTHMODE_FORMATTED[] = "&sAuthmode: "; class WifiApClientsAction : public virtual ActionInterface { @@ -67,6 +68,22 @@ using ApKeyChangeScreen = espgui::makeComponent< espgui::BackActionInterface> >; +using ApIpChangeScreen = espgui::makeComponent< + BobbyChangeValueDisplay, + espgui::StaticText, + WifiApIpAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + +using ApMaskChangeScreen = espgui::makeComponent< + BobbyChangeValueDisplay, + espgui::StaticText, + WifiApMaskAccessor, + espgui::ConfirmActionInterface>, + espgui::BackActionInterface> +>; + using ApChannelChangeScreen = espgui::makeComponent< BobbyChangeValueDisplay, espgui::StaticText, @@ -87,17 +104,17 @@ using ApAuthmodeChangeScreen = espgui::makeComponent< WifiApSettingsMenu::WifiApSettingsMenu() { constructMenuItem, BobbyCheckbox, WifiApEnabledAccessor>>(); - //constructMenuItem, BobbyCheckbox, WifiApDisableWhenOnlineAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); + //constructMenuItem, BobbyCheckbox, WifiApDisableWhenOnlineAccessor>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } std::string WifiApSettingsMenu::text() const diff --git a/main/displays/menus/wifistaconfigentrymenu.cpp b/main/displays/menus/wifistaconfigentrymenu.cpp index ae0d271..ccdd01d 100644 --- a/main/displays/menus/wifistaconfigentrymenu.cpp +++ b/main/displays/menus/wifistaconfigentrymenu.cpp @@ -6,22 +6,96 @@ #include #include #include +#include +#include +#include +#include // local includes -#include "texthelpers/wifistaconfigtexthelpers.h" +#include "displays/bobbychangevaluedisplay.h" #include "accessors/wifistaconfigaccessors.h" #include "wifistaconfigsmenu.h" #include "newsettings.h" #include "bobbycheckbox.h" -using namespace espgui; - namespace { +constexpr char TEXT_SSID_TITLE[] = "WiFi {} SSID"; +constexpr char TEXT_SSID_FORMATTED[] = "&sSSID: &f"; +constexpr char TEXT_KEY_TITLE[] = "WiFi {} Key"; +constexpr char TEXT_KEY_FORMATTED[] = "&sKey: &f"; constexpr char TEXT_USESTATICIP[] = "Use Static Ip"; +constexpr char TEXT_STATICIP_TITLE[] = "WiFi {} Static Ip"; +constexpr char TEXT_STATICIP_FORMATTED[] = "&sStatic Ip: &f"; +constexpr char TEXT_STATICMASK_TITLE[] = "WiFi {} Static Mask"; +constexpr char TEXT_STATICMASK_FORMATTED[] = "&sStatic Mask: &f"; +constexpr char TEXT_STATICGW_TITLE[] = "WiFi {} Static Gw"; +constexpr char TEXT_STATICGW_FORMATTED[] = "&sStatic Gw: &f"; constexpr char TEXT_USESTATICDNS[] = "Use Static Dns"; +constexpr char TEXT_STATICDNS0_TITLE[] = "WiFi {} Static Dns0"; +constexpr char TEXT_STATICDNS0_FORMATTED[] = "&sStatic Dns0: &f"; +constexpr char TEXT_STATICDNS1_TITLE[] = "WiFi {} Static Dns1"; +constexpr char TEXT_STATICDNS1_FORMATTED[] = "&sStatic Dns1: &f"; +constexpr char TEXT_STATICDNS2_TITLE[] = "WiFi {} Static Dns2"; +constexpr char TEXT_STATICDNS2_FORMATTED[] = "&sStatic Dns2: &f"; constexpr char TEXT_DELETECONFIG[] = "Delete config"; constexpr char TEXT_BACK[] = "Back"; +template +class StaChangeScreen : + public BobbyChangeValueDisplay, + public Taccessor +{ +public: + explicit StaChangeScreen(int index) : Taccessor{index}, m_index{index} {} + std::string text() const override { return fmt::format(Ttitle, m_index + 1); } + void confirm() override { espgui::switchScreen(m_index); } + void back() override { espgui::switchScreen(m_index); } + +private: + const int m_index; +}; + +template +class StaChangeMenuItem : + public espgui::MenuItem, + public espgui::TextWithValueHelper +{ +public: + explicit StaChangeMenuItem(int index) : + espgui::TextWithValueHelper{index}, + m_index{index} + {} + + void triggered() override { espgui::switchScreen(m_index); } + +private: + const int m_index; +}; + +using StaSsidChangeScreen = StaChangeScreen; +using StaSsidMenuItem = StaChangeMenuItem; + +using StaKeyChangeScreen = StaChangeScreen; +using StaKeyMenuItem = StaChangeMenuItem; + +using StaStaticIpChangeScreen = StaChangeScreen; +using StaStaticIpMenuItem = StaChangeMenuItem; + +using StaStaticMaskChangeScreen = StaChangeScreen; +using StaStaticMaskMenuItem = StaChangeMenuItem; + +using StaStaticGwChangeScreen = StaChangeScreen; +using StaStaticGwMenuItem = StaChangeMenuItem; + +using StaStaticDns0ChangeScreen = StaChangeScreen; +using StaStaticDns0MenuItem = StaChangeMenuItem; + +using StaStaticDns1ChangeScreen = StaChangeScreen; +using StaStaticDns1MenuItem = StaChangeMenuItem; + +using StaStaticDns2ChangeScreen = StaChangeScreen; +using StaStaticDns2MenuItem = StaChangeMenuItem; + class ClearConfigAction : public virtual espgui::ActionInterface { public: @@ -37,16 +111,17 @@ private: WifiStaConfigEntryMenu::WifiStaConfigEntryMenu(int index) : m_index{index} { - constructMenuItem>(index); - constructMenuItem>(index); + using namespace espgui; + constructMenuItem(index); + constructMenuItem(index); constructMenuItem, BobbyCheckbox>>(index); - constructMenuItem>(index); - constructMenuItem>(index); - constructMenuItem>(index); + constructMenuItem(index); + constructMenuItem(index); + constructMenuItem(index); constructMenuItem, BobbyCheckbox>>(index); - constructMenuItem>(index); - constructMenuItem>(index); - constructMenuItem>(index); + constructMenuItem(index); + constructMenuItem(index); + constructMenuItem(index); constructMenuItem>>(index); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } @@ -58,7 +133,7 @@ std::string WifiStaConfigEntryMenu::text() const void WifiStaConfigEntryMenu::back() { - switchScreen(); + espgui::switchScreen(); } namespace { diff --git a/main/displays/calibratedisplay.cpp b/main/displays/potiscalibratedisplay.cpp similarity index 93% rename from main/displays/calibratedisplay.cpp rename to main/displays/potiscalibratedisplay.cpp index ee7cd7a..5d78723 100644 --- a/main/displays/calibratedisplay.cpp +++ b/main/displays/potiscalibratedisplay.cpp @@ -1,4 +1,4 @@ -#include "calibratedisplay.h" +#include "potiscalibratedisplay.h" // 3rdparty lib includes #include @@ -9,22 +9,19 @@ #include "displays/statusdisplay.h" #include "displays/menus/boardcomputerhardwaresettingsmenu.h" #include "newsettings.h" +#include "utils.h" +#include "globals.h" namespace { -constexpr char TEXT_CALIBRATE[] = "Calibrate"; +constexpr char TEXT_CALIBRATE[] = "Potis Calibrate"; } // namespace -CalibrateDisplay::CalibrateDisplay(bool bootup) : - m_bootup{bootup} -{ -} - -std::string CalibrateDisplay::text() const +std::string PotisCalibrateDisplay::text() const { return TEXT_CALIBRATE; } -void CalibrateDisplay::start() +void PotisCalibrateDisplay::start() { Base::start(); @@ -37,7 +34,7 @@ void CalibrateDisplay::start() m_brems = std::nullopt; } -void CalibrateDisplay::initScreen() +void PotisCalibrateDisplay::initScreen() { Base::initScreen(); @@ -56,7 +53,7 @@ void CalibrateDisplay::initScreen() m_renderedButton = -1; } -void CalibrateDisplay::update() +void PotisCalibrateDisplay::update() { Base::update(); @@ -71,7 +68,7 @@ void CalibrateDisplay::update() m_brems = std::nullopt; } -void CalibrateDisplay::redraw() +void PotisCalibrateDisplay::redraw() { Base::redraw(); @@ -159,7 +156,7 @@ void CalibrateDisplay::redraw() m_renderedButton = m_selectedButton; } -void CalibrateDisplay::stop() +void PotisCalibrateDisplay::stop() { Base::stop(); @@ -173,7 +170,7 @@ void CalibrateDisplay::stop() } } -void CalibrateDisplay::buttonPressed(espgui::Button button) +void PotisCalibrateDisplay::buttonPressed(espgui::Button button) { Base::buttonPressed(button); @@ -277,7 +274,7 @@ void CalibrateDisplay::buttonPressed(espgui::Button button) } } -void CalibrateDisplay::copyFromSettings() +void PotisCalibrateDisplay::copyFromSettings() { m_gasMin = configs.gasMin.value; m_gasMax = configs.gasMax.value; @@ -285,7 +282,7 @@ void CalibrateDisplay::copyFromSettings() m_bremsMax = configs.bremsMax.value; } -void CalibrateDisplay::copyToSettings() +void PotisCalibrateDisplay::copyToSettings() { configs.write_config(configs.gasMin, m_gasMin); configs.write_config(configs.gasMax, m_gasMax); diff --git a/main/displays/calibratedisplay.h b/main/displays/potiscalibratedisplay.h similarity index 90% rename from main/displays/calibratedisplay.h rename to main/displays/potiscalibratedisplay.h index 96e8f3c..e53ae83 100644 --- a/main/displays/calibratedisplay.h +++ b/main/displays/potiscalibratedisplay.h @@ -13,17 +13,16 @@ // local includes #include "bobbydisplaywithtitle.h" -#include "globals.h" -#include "utils.h" +#include "modeinterface.h" #include "modes/ignoreinputmode.h" -class CalibrateDisplay : public BobbyDisplayWithTitle +class PotisCalibrateDisplay : public BobbyDisplayWithTitle { using Base = BobbyDisplayWithTitle; public: - CalibrateDisplay() = default; - explicit CalibrateDisplay(bool bootup); + PotisCalibrateDisplay() = default; + explicit PotisCalibrateDisplay(bool bootup) : m_bootup{bootup} {} std::string text() const override; void start() override; diff --git a/main/dpad.h b/main/dpad.h index 5fbe662..8f31f27 100644 --- a/main/dpad.h +++ b/main/dpad.h @@ -1,13 +1,19 @@ #pragma once +// system includes #include +// Arduino includes #include +// 3rdparty lib includes #include +#include -#include "buttons.h" +// local includes #include "types.h" +#include "newsettings.h" +#include "bobbybuttons.h" namespace { namespace dpad diff --git a/main/dpad3wire.h b/main/dpad3wire.h index c2403d7..c01978a 100644 --- a/main/dpad3wire.h +++ b/main/dpad3wire.h @@ -6,12 +6,14 @@ // 3rdparty lib includes #include #include +#include // local includes #include "dpad.h" -#include "buttons.h" #include "types.h" #include "globals.h" +#include "newsettings.h" +#include "bobbybuttons.h" namespace { namespace dpad3wire diff --git a/main/dpad5wire.cpp b/main/dpad5wire.cpp index e69de29..b37c7d2 100644 --- a/main/dpad5wire.cpp +++ b/main/dpad5wire.cpp @@ -0,0 +1,122 @@ +#include "dpad5wire.h" + +// system includes +#include + +// Arduino includes +#include + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "types.h" +#include "globals.h" +#include "newsettings.h" +#include "bobbybuttons.h" + +namespace { +template +class Helper +{ +public: + static constexpr auto OutPin = OUT; + static constexpr auto In1Pin = IN1; + static constexpr auto In2Pin = IN2; + static constexpr auto In3Pin = IN3; + static constexpr auto In4Pin = IN4; + + void begin(); + + std::array read(); +}; + +template +void Helper::begin() +{ + pinMode(OUT, OUTPUT); +} + +template +std::array Helper::read() +{ + std::array result; + + digitalWrite(OUT, LOW); + + pinMode(IN1, INPUT_PULLUP); + pinMode(IN2, INPUT_PULLUP); + pinMode(IN3, INPUT_PULLUP); + pinMode(IN4, INPUT_PULLUP); + + vPortYield(); + + result[0] = digitalRead(IN1)==LOW; + result[1] = digitalRead(IN2)==LOW; + result[2] = digitalRead(IN3)==LOW; + result[3] = digitalRead(IN4)==LOW; + + digitalWrite(OUT, HIGH); + + pinMode(IN1, INPUT_PULLDOWN); + pinMode(IN2, INPUT_PULLDOWN); + pinMode(IN3, INPUT_PULLDOWN); + pinMode(IN4, INPUT_PULLDOWN); + + vPortYield(); + + result[4] = digitalRead(IN1); + result[5] = digitalRead(IN2); + result[6] = digitalRead(IN3); + result[7] = digitalRead(IN4); + + return result; +} + +#ifdef FEATURE_DPAD_5WIRESW +Helper helper; +std::array lastState; +std::array debounce; +#endif +} // namespace + +#ifdef FEATURE_DPAD_5WIRESW +namespace dpad5wire { +void init() +{ + helper.begin(); + std::fill(std::begin(lastState), std::end(lastState), false); + std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now()); +} + +void update() +{ + const auto newState = helper.read(); + +#ifdef DPAD_5WIRESW_DEBUG + lastState = newState; + return; +#endif + + const auto now = espchrono::millis_clock::now(); + + const std::chrono::milliseconds dpadDebounce{settings.boardcomputerHardware.dpadDebounce}; + + for (auto i = 0; i < 8; i++) + if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce) + { + lastState[i] = newState[i]; + if (espgui::currentDisplay) + { + if (newState[i]) + espgui::currentDisplay->rawButtonPressed(i); + else + espgui::currentDisplay->rawButtonReleased(i); + } + debounce[i] = now; + } +} +} // namespace dpad5wire +#endif diff --git a/main/dpad5wire.h b/main/dpad5wire.h index 1296e8c..f28c3b5 100644 --- a/main/dpad5wire.h +++ b/main/dpad5wire.h @@ -1,188 +1,8 @@ #pragma once -// system includes -#include - -// Arduino includes -#include - -// 3rdparty lib includes -#include -#include - -// local includes -#include "buttons.h" -#include "types.h" -#include "globals.h" - -namespace { -namespace dpad5wire { #ifdef FEATURE_DPAD_5WIRESW -class State : public std::array -{ -public: - State() : std::array{false, false, false, false, false, false, false, false} {} - State(const std::array &other) : std::array{} {} - - State &operator=(const std::array &other) - { - std::array::operator=(other); - return *this; - } - - State &operator=(const State &other) - { - std::array::operator=(other); - return *this; - } - - bool &up{this->at(DPAD_5WIRESW_UP)}; - bool &down{this->at(DPAD_5WIRESW_DOWN)}; - bool &confirm{this->at(DPAD_5WIRESW_CONFIRM)}; - bool &back{this->at(DPAD_5WIRESW_BACK)}; - bool &profile0{this->at(DPAD_5WIRESW_PROFILE0)}; - bool &profile1{this->at(DPAD_5WIRESW_PROFILE1)}; - bool &profile2{this->at(DPAD_5WIRESW_PROFILE2)}; - bool &profile3{this->at(DPAD_5WIRESW_PROFILE3)}; -}; - -template -class Helper -{ -public: - static constexpr auto OutPin = OUT; - static constexpr auto In1Pin = IN1; - static constexpr auto In2Pin = IN2; - static constexpr auto In3Pin = IN3; - static constexpr auto In4Pin = IN4; - - void begin(); - - State read(); -}; - -template -void Helper::begin() -{ - pinMode(OUT, OUTPUT); -} - -template -State Helper::read() -{ - State result; - - digitalWrite(OUT, LOW); - - pinMode(IN1, INPUT_PULLUP); - pinMode(IN2, INPUT_PULLUP); - pinMode(IN3, INPUT_PULLUP); - pinMode(IN4, INPUT_PULLUP); - - vPortYield(); - - result[0] = digitalRead(IN1)==LOW; - result[1] = digitalRead(IN2)==LOW; - result[2] = digitalRead(IN3)==LOW; - result[3] = digitalRead(IN4)==LOW; - - digitalWrite(OUT, HIGH); - - pinMode(IN1, INPUT_PULLDOWN); - pinMode(IN2, INPUT_PULLDOWN); - pinMode(IN3, INPUT_PULLDOWN); - pinMode(IN4, INPUT_PULLDOWN); - - vPortYield(); - - result[4] = digitalRead(IN1); - result[5] = digitalRead(IN2); - result[6] = digitalRead(IN3); - result[7] = digitalRead(IN4); - - return result; -} - -Helper helper; -State lastState; -espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3; - -void init() -{ - helper.begin(); - debounceUp = debounceDown = debounceConfirm = debounceBack = debounceProfile0 = debounceProfile1 = debounceProfile2 = debounceProfile3 = espchrono::millis_clock::now(); -} - -void update() -{ - const auto newState = helper.read(); - -#ifdef DPAD_5WIRESW_DEBUG - lastState = newState; - return; -#endif - - const auto now = espchrono::millis_clock::now(); - - const std::chrono::milliseconds dpadDebounce{settings.boardcomputerHardware.dpadDebounce}; - - if (lastState.up != newState.up && now - debounceUp > dpadDebounce) - { - lastState.up = newState.up; - InputDispatcher::upButton(newState.up); - debounceUp = now; - } - - if (lastState.down != newState.down && now - debounceDown > dpadDebounce) - { - lastState.down = newState.down; - InputDispatcher::downButton(newState.down); - debounceDown = now; - } - - if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce) - { - lastState.confirm = newState.confirm; - InputDispatcher::confirmButton(newState.confirm); - debounceConfirm = now; - } - - if (lastState.back != newState.back && now - debounceBack > dpadDebounce) - { - lastState.back = newState.back; - InputDispatcher::backButton(newState.back); - debounceBack = now; - } - - if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce) - { - lastState.profile0 = newState.profile0; - InputDispatcher::profileButton(0, newState.profile0); - debounceProfile0 = now; - } - - if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce) - { - lastState.profile1 = newState.profile1; - InputDispatcher::profileButton(1, newState.profile1); - debounceProfile1 = now; - } - - if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce) - { - lastState.profile2 = newState.profile2; - InputDispatcher::profileButton(2, newState.profile2); - debounceProfile2 = now; - } - - if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce) - { - lastState.profile3 = newState.profile3; - InputDispatcher::profileButton(3, newState.profile3); - debounceProfile3 = now; - } -} -#endif - +namespace dpad5wire { +void init(); +void update(); } // namespace dpad5wire -} // namespace +#endif diff --git a/main/dpad5wire_2out.cpp b/main/dpad5wire_2out.cpp index e69de29..880a245 100644 --- a/main/dpad5wire_2out.cpp +++ b/main/dpad5wire_2out.cpp @@ -0,0 +1,145 @@ +#include "dpad5wire_2out.h" + +// system includes +#include + +// Arduino includes +#include + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "types.h" +#include "globals.h" +#include "newsettings.h" +#include "bobbybuttons.h" + +namespace { +template +class Helper +{ +public: + static constexpr auto OutPin = OUT; + static constexpr auto In1Pin = IN1; + static constexpr auto In2Pin = IN2; + static constexpr auto In3Pin = IN3; + static constexpr auto In4Pin = IN4; + + void begin(); + + std::array read(); +}; + +template +void Helper::begin() +{ +} + +template +std::array Helper::read() +{ + std::array result; + + pinMode(OUT1, OUTPUT); + pinMode(OUT2, INPUT); + + digitalWrite(OUT1, LOW); + + pinMode(IN1, INPUT_PULLUP); + pinMode(IN2, INPUT_PULLUP); + pinMode(IN3, INPUT_PULLUP); + + vPortYield(); + + result[0] = digitalRead(IN1)==LOW; + result[1] = digitalRead(IN2)==LOW; + result[2] = digitalRead(IN3)==LOW; + + digitalWrite(OUT1, HIGH); + + pinMode(IN1, INPUT_PULLDOWN); + pinMode(IN2, INPUT_PULLDOWN); + pinMode(IN3, INPUT_PULLDOWN); + + vPortYield(); + + result[3] = digitalRead(IN1); + result[4] = digitalRead(IN2); + result[5] = digitalRead(IN3); + + pinMode(OUT1, INPUT); + pinMode(OUT2, OUTPUT); + + digitalWrite(OUT2, LOW); + + pinMode(IN1, INPUT_PULLUP); + pinMode(IN2, INPUT_PULLUP); + pinMode(IN3, INPUT_PULLUP); + + vPortYield(); + + result[6] = digitalRead(IN1)==LOW; + result[7] = digitalRead(IN2)==LOW; + result[8] = digitalRead(IN3)==LOW; + + digitalWrite(OUT2, HIGH); + + pinMode(IN1, INPUT_PULLDOWN); + pinMode(IN2, INPUT_PULLDOWN); + pinMode(IN3, INPUT_PULLDOWN); + + vPortYield(); + + result[9] = digitalRead(IN1); + result[10] = digitalRead(IN2); + result[11] = digitalRead(IN3); + + return result; +} + +#ifdef FEATURE_DPAD_5WIRESW_2OUT +Helper helper; +std::array lastState; +std::array debounce; +#endif +} // namespace + +#ifdef FEATURE_DPAD_5WIRESW_2OUT + +namespace dpad5wire_2out { +void init() +{ + helper.begin(); + std::fill(std::begin(lastState), std::end(lastState), false); + std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now()); +} + +void update() +{ + const auto newState = helper.read(); + + const auto now = espchrono::millis_clock::now(); + + const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value}; + + for (auto i = 0; i < 12; i++) + if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce) + { + lastState[i] = newState[i]; + if (espgui::currentDisplay) + { + if (newState[i]) + espgui::currentDisplay->rawButtonPressed(i); + else + espgui::currentDisplay->rawButtonReleased(i); + } + debounce[i] = now; + } +} + +} // namespace dpad5wire_2out + +#endif diff --git a/main/dpad5wire_2out.h b/main/dpad5wire_2out.h index db41d9d..1a9c555 100644 --- a/main/dpad5wire_2out.h +++ b/main/dpad5wire_2out.h @@ -1,260 +1,8 @@ #pragma once -// system includes -#include - -// Arduino includes -#include - -// 3rdparty lib includes -#include -#include - -// local includes -#include "buttons.h" -#include "types.h" -#include "globals.h" -#include "newsettings.h" - -namespace { -namespace dpad5wire_2out { - #ifdef FEATURE_DPAD_5WIRESW_2OUT -class State : public std::array -{ -public: - State() : std::array{false, false, false, false, false, false, false, false, false, false, false, false} {} - State(const std::array &other) : std::array{} {} - - State &operator=(const std::array &other) - { - std::array::operator=(other); - return *this; - } - - State &operator=(const State &other) - { - std::array::operator=(other); - return *this; - } - - bool &up{this->at(DPAD_5WIRESW_UP)}; - bool &down{this->at(DPAD_5WIRESW_DOWN)}; - bool &confirm{this->at(DPAD_5WIRESW_CONFIRM)}; - bool &back{this->at(DPAD_5WIRESW_BACK)}; - bool &profile0{this->at(DPAD_5WIRESW_PROFILE0)}; - bool &profile1{this->at(DPAD_5WIRESW_PROFILE1)}; - bool &profile2{this->at(DPAD_5WIRESW_PROFILE2)}; - bool &profile3{this->at(DPAD_5WIRESW_PROFILE3)}; - - bool &blink_left{this->at(DPAD_5WIRESW_BLINK_LEFT)}; - bool &blink_right{this->at(DPAD_5WIRESW_BLINK_RIGHT)}; - bool &quickaction_down{this->at(DPAD_5WIRESW_QUICKACTION_DOWN)}; - bool &quickaction_up{this->at(DPAD_5WIRESW_QUICKACTION_UP)}; -}; - -template -class Helper -{ -public: - static constexpr auto OutPin = OUT; - static constexpr auto In1Pin = IN1; - static constexpr auto In2Pin = IN2; - static constexpr auto In3Pin = IN3; - static constexpr auto In4Pin = IN4; - - void begin(); - - State read(); -}; - -template -void Helper::begin() -{ -} - -template -State Helper::read() -{ - State result; - - pinMode(OUT1, OUTPUT); - pinMode(OUT2, INPUT); - - digitalWrite(OUT1, LOW); - - pinMode(IN1, INPUT_PULLUP); - pinMode(IN2, INPUT_PULLUP); - pinMode(IN3, INPUT_PULLUP); - - vPortYield(); - - result[0] = digitalRead(IN1)==LOW; - result[1] = digitalRead(IN2)==LOW; - result[2] = digitalRead(IN3)==LOW; - - digitalWrite(OUT1, HIGH); - - pinMode(IN1, INPUT_PULLDOWN); - pinMode(IN2, INPUT_PULLDOWN); - pinMode(IN3, INPUT_PULLDOWN); - - vPortYield(); - - result[3] = digitalRead(IN1); - result[4] = digitalRead(IN2); - result[5] = digitalRead(IN3); - - pinMode(OUT1, INPUT); - pinMode(OUT2, OUTPUT); - - digitalWrite(OUT2, LOW); - - pinMode(IN1, INPUT_PULLUP); - pinMode(IN2, INPUT_PULLUP); - pinMode(IN3, INPUT_PULLUP); - - vPortYield(); - - result[6] = digitalRead(IN1)==LOW; - result[7] = digitalRead(IN2)==LOW; - result[8] = digitalRead(IN3)==LOW; - - digitalWrite(OUT2, HIGH); - - pinMode(IN1, INPUT_PULLDOWN); - pinMode(IN2, INPUT_PULLDOWN); - pinMode(IN3, INPUT_PULLDOWN); - - vPortYield(); - - result[9] = digitalRead(IN1); - result[10] = digitalRead(IN2); - result[11] = digitalRead(IN3); - - return result; -} - -Helper helper; -State lastState; -espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3, debounceBlinkLeft, debounceBlinkRight, debounceQuickactionDown, debounceQuickactionUp; - -void init() -{ - helper.begin(); - debounceUp = - debounceDown = - debounceConfirm = - debounceBack = - debounceProfile0 = - debounceProfile1 = - debounceProfile2 = - debounceProfile3 = - debounceBlinkLeft= - debounceBlinkRight = - debounceQuickactionDown = - debounceQuickactionUp = - espchrono::millis_clock::now(); -} - -void update() -{ - const auto newState = helper.read(); - -#ifdef DPAD_5WIRESW_DEBUG - lastState = newState; - return; -#endif - - const auto now = espchrono::millis_clock::now(); - - const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value}; - - if (lastState.up != newState.up && now - debounceUp > dpadDebounce) - { - lastState.up = newState.up; - InputDispatcher::upButton(newState.up); - debounceUp = now; - } - - if (lastState.down != newState.down && now - debounceDown > dpadDebounce) - { - lastState.down = newState.down; - InputDispatcher::downButton(newState.down); - debounceDown = now; - } - - if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce) - { - lastState.confirm = newState.confirm; - InputDispatcher::confirmButton(newState.confirm); - debounceConfirm = now; - } - - if (lastState.back != newState.back && now - debounceBack > dpadDebounce) - { - lastState.back = newState.back; - InputDispatcher::backButton(newState.back); - debounceBack = now; - } - - if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce) - { - lastState.profile0 = newState.profile0; - InputDispatcher::profileButton(0, newState.profile0); - debounceProfile0 = now; - } - - if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce) - { - lastState.profile1 = newState.profile1; - InputDispatcher::profileButton(1, newState.profile1); - debounceProfile1 = now; - } - - if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce) - { - lastState.profile2 = newState.profile2; - InputDispatcher::profileButton(2, newState.profile2); - debounceProfile2 = now; - } - - if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce) - { - lastState.profile3 = newState.profile3; - InputDispatcher::profileButton(3, newState.profile3); - debounceProfile3 = now; - } - - if (lastState.blink_left != newState.blink_left && now - debounceBlinkLeft > dpadDebounce) - { - lastState.blink_left = newState.blink_left; - InputDispatcher::blinkLeftButton(newState.blink_left); - debounceBlinkLeft = now; - } - - if (lastState.blink_right != newState.blink_right && now - debounceBlinkRight > dpadDebounce) - { - lastState.blink_right = newState.blink_right; - InputDispatcher::blinkRightButton(newState.blink_right); - debounceBlinkRight = now; - } - - if (lastState.quickaction_down != newState.quickaction_down && now - debounceQuickactionDown > dpadDebounce) - { - lastState.quickaction_down = newState.quickaction_down; - InputDispatcher::quickActionButtonDown(newState.quickaction_down); - debounceQuickactionDown = now; - } - - if (lastState.quickaction_up != newState.quickaction_up && now - debounceQuickactionUp > dpadDebounce) - { - lastState.quickaction_up = newState.quickaction_up; - InputDispatcher::quickActionButtonUp(newState.quickaction_up); - debounceQuickactionUp = now; - } -} -#endif - +namespace dpad5wire_2out { +void init(); +void update(); } // namespace dpad5wire_2out -} // namespace +#endif diff --git a/main/dpad6wire.cpp b/main/dpad6wire.cpp index e69de29..a52a4c7 100644 --- a/main/dpad6wire.cpp +++ b/main/dpad6wire.cpp @@ -0,0 +1,134 @@ +#include "dpad6wire.h" + +// system includes +#include + +// Arduino includes +#include + +// 3rdparty lib includes +#include +#include +#include + +// local includes +#include "types.h" +#include "globals.h" +#include "newsettings.h" +#include "bobbybuttons.h" + +namespace { +template +class Helper +{ +public: + static constexpr auto OutPin = OUT; + static constexpr auto In1Pin = IN1; + static constexpr auto In2Pin = IN2; + static constexpr auto In3Pin = IN3; + static constexpr auto In4Pin = IN4; + static constexpr auto In5Pin = IN5; + + void begin(); + + std::array read(); +}; + +template +void Helper::begin() +{ + pinMode(OUT, OUTPUT); +} + +template +std::array Helper::read() +{ + std::array result; + + digitalWrite(OUT, LOW); + + pinMode(IN1, INPUT_PULLUP); + pinMode(IN2, INPUT_PULLUP); + pinMode(IN3, INPUT_PULLUP); + pinMode(IN4, INPUT_PULLUP); + pinMode(IN5, INPUT_PULLUP); + + vPortYield(); + + result[0] = digitalRead(IN1)==LOW; + result[1] = digitalRead(IN2)==LOW; + result[2] = digitalRead(IN3)==LOW; + result[3] = digitalRead(IN4)==LOW; + result[8] = digitalRead(IN5)==LOW; + + digitalWrite(OUT, HIGH); + + pinMode(IN1, INPUT_PULLDOWN); + pinMode(IN2, INPUT_PULLDOWN); + pinMode(IN3, INPUT_PULLDOWN); + pinMode(IN4, INPUT_PULLDOWN); + pinMode(IN5, INPUT_PULLDOWN); + + vPortYield(); + + result[4] = digitalRead(IN1); + result[5] = digitalRead(IN2); + result[6] = digitalRead(IN3); + result[7] = digitalRead(IN4); + result[9] = digitalRead(IN5); + +#ifdef FEATURE_GSCHISSENE_DIODE + if (result[8] && result[9]) result[9] = 0; +#endif + + return result; +} + +#ifdef FEATURE_DPAD_6WIRESW +Helper helper; +std::array lastState; +std::array debounce; +#endif +} // namespace + +#ifdef FEATURE_DPAD_6WIRESW +namespace dpad6wire { + +void init() +{ + helper.begin(); + std::fill(std::begin(lastState), std::end(lastState), false); + std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now()); +} + +void update() +{ + const auto newState = helper.read(); + +#ifdef DPAD_6WIRESW_DEBUG + lastState = newState; + return; +#endif + + const auto now = espchrono::millis_clock::now(); + + const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value}; + + for (auto i = 0; i < 10; i++) + if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce) + { + lastState[i] = newState[i]; + if (espgui::currentDisplay) + { + if (newState[i]) + espgui::currentDisplay->rawButtonPressed(i); + else + espgui::currentDisplay->rawButtonReleased(i); + } + debounce[i] = now; + } +} + +} // namespace dpad6wire + +#endif diff --git a/main/dpad6wire.h b/main/dpad6wire.h index 643095b..c5ed317 100644 --- a/main/dpad6wire.h +++ b/main/dpad6wire.h @@ -1,214 +1,8 @@ #pragma once -// system includes -#include -// Arduino includes -#include - -// 3rdparty lib includes -#include -#include - -// local includes -#include "buttons.h" -#include "types.h" -#include "globals.h" -#include "newsettings.h" - -namespace { -namespace dpad6wire { #ifdef FEATURE_DPAD_6WIRESW -class State : public std::array -{ -public: - State() : std::array{false, false, false, false, false, false, false, false, false, false} {} - State(const std::array &other) : std::array{} {} - - State &operator=(const std::array &other) - { - std::array::operator=(other); - return *this; - } - - State &operator=(const State &other) - { - std::array::operator=(other); - return *this; - } - - bool &up{this->at(DPAD_6WIRESW_UP)}; - bool &down{this->at(DPAD_6WIRESW_DOWN)}; - bool &confirm{this->at(DPAD_6WIRESW_CONFIRM)}; - bool &back{this->at(DPAD_6WIRESW_BACK)}; - bool &profile0{this->at(DPAD_6WIRESW_PROFILE0)}; - bool &profile1{this->at(DPAD_6WIRESW_PROFILE1)}; - bool &profile2{this->at(DPAD_6WIRESW_PROFILE2)}; - bool &profile3{this->at(DPAD_6WIRESW_PROFILE3)}; - - bool &blink_left{this->at(DPAD_6WIRESW_BLINK_LEFT)}; - bool &blink_right{this->at(DPAD_6WIRESW_BLINK_RIGHT)}; -}; - -template -class Helper -{ -public: - static constexpr auto OutPin = OUT; - static constexpr auto In1Pin = IN1; - static constexpr auto In2Pin = IN2; - static constexpr auto In3Pin = IN3; - static constexpr auto In4Pin = IN4; - static constexpr auto In5Pin = IN5; - - void begin(); - - State read(); -}; - -template -void Helper::begin() -{ - pinMode(OUT, OUTPUT); -} - -template -State Helper::read() -{ - State result; - - digitalWrite(OUT, LOW); - - pinMode(IN1, INPUT_PULLUP); - pinMode(IN2, INPUT_PULLUP); - pinMode(IN3, INPUT_PULLUP); - pinMode(IN4, INPUT_PULLUP); - pinMode(IN5, INPUT_PULLUP); - - vPortYield(); - - result[0] = digitalRead(IN1)==LOW; - result[1] = digitalRead(IN2)==LOW; - result[2] = digitalRead(IN3)==LOW; - result[3] = digitalRead(IN4)==LOW; - result[8] = digitalRead(IN5)==LOW; - - digitalWrite(OUT, HIGH); - - pinMode(IN1, INPUT_PULLDOWN); - pinMode(IN2, INPUT_PULLDOWN); - pinMode(IN3, INPUT_PULLDOWN); - pinMode(IN4, INPUT_PULLDOWN); - pinMode(IN5, INPUT_PULLDOWN); - - vPortYield(); - - result[4] = digitalRead(IN1); - result[5] = digitalRead(IN2); - result[6] = digitalRead(IN3); - result[7] = digitalRead(IN4); - result[9] = digitalRead(IN5); - -#ifdef FEATURE_GSCHISSENE_DIODE - if (result[8] && result[9]) result[9] = 0; -#endif - - return result; -} - -Helper helper; -State lastState; -espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3, debounceBlinkLeft, debounceBlinkRight; - -void init() -{ - helper.begin(); - debounceUp = debounceDown = debounceConfirm = debounceBack = debounceProfile0 = debounceProfile1 = debounceProfile2 = debounceProfile3 = debounceBlinkLeft = debounceBlinkRight = espchrono::millis_clock::now(); -} - -void update() -{ - const auto newState = helper.read(); - -#ifdef DPAD_6WIRESW_DEBUG - lastState = newState; - return; -#endif - - const auto now = espchrono::millis_clock::now(); - - const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value}; - - if (lastState.up != newState.up && now - debounceUp > dpadDebounce) - { - lastState.up = newState.up; - InputDispatcher::upButton(newState.up); - debounceUp = now; - } - - if (lastState.down != newState.down && now - debounceDown > dpadDebounce) - { - lastState.down = newState.down; - InputDispatcher::downButton(newState.down); - debounceDown = now; - } - - if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce) - { - lastState.confirm = newState.confirm; - InputDispatcher::confirmButton(newState.confirm); - debounceConfirm = now; - } - - if (lastState.back != newState.back && now - debounceBack > dpadDebounce) - { - lastState.back = newState.back; - InputDispatcher::backButton(newState.back); - debounceBack = now; - } - - if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce) - { - lastState.profile0 = newState.profile0; - InputDispatcher::profileButton(0, newState.profile0); - debounceProfile0 = now; - } - - if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce) - { - lastState.profile1 = newState.profile1; - InputDispatcher::profileButton(1, newState.profile1); - debounceProfile1 = now; - } - - if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce) - { - lastState.profile2 = newState.profile2; - InputDispatcher::profileButton(2, newState.profile2); - debounceProfile2 = now; - } - - if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce) - { - lastState.profile3 = newState.profile3; - InputDispatcher::profileButton(3, newState.profile3); - debounceProfile3 = now; - } - - if (lastState.blink_left != newState.blink_left && now - debounceBlinkLeft > dpadDebounce) - { - lastState.blink_left = newState.blink_left; - InputDispatcher::blinkLeftButton(newState.blink_left); - debounceBlinkLeft = now; - } - - if (lastState.blink_right != newState.blink_right && now - debounceBlinkRight > dpadDebounce) - { - lastState.blink_right = newState.blink_right; - InputDispatcher::blinkRightButton(newState.blink_right); - debounceBlinkRight = now; - } -} -#endif - +namespace dpad6wire { +void init(); +void update(); } // namespace dpad6wire -} // namespace +#endif diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index ace5d5f..dca4196 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -18,12 +18,12 @@ std::vector leds; uint8_t gHue = 0; uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; -uint16_t animation_type = LedstripAnimation::DefaultRainbow; +LedstripAnimation animation_type = LedstripAnimation::DefaultRainbow; void initLedStrip() { - animation_type = settings.ledstrip.animationType; + animation_type = LedstripAnimation(settings.ledstrip.animationType); leds.resize(settings.ledstrip.ledsCount); FastLED.addLeds(&*std::begin(leds), leds.size()) .setCorrection(TypicalSMD5050); diff --git a/main/ledstrip.h b/main/ledstrip.h index 2041841..ed1e446 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -6,6 +6,9 @@ // 3rdparty lib includes #include +// local includes +#include "ledstripdefines.h" + #ifdef FEATURE_LEDSTRIP enum Bobbycar_Side { @@ -32,7 +35,7 @@ extern std::vector leds; extern uint8_t gHue; extern uint16_t blinkAnimation; -extern uint16_t animation_type; +extern LedstripAnimation animation_type; void showDefaultLedstrip(); void showAnimation(); diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index 5582ca9..2713e4b 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -14,7 +14,8 @@ #endif #define LEDSTRIP_OVERWRITE_BLINKBOTH 3 -enum LedstripAnimation : uint16_t { +enum LedstripAnimation : uint8_t +{ DefaultRainbow, BetterRainbow, SpeedSync, diff --git a/main/main.cpp b/main/main.cpp index d9d2d41..99a41e6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -23,7 +23,8 @@ using namespace std::chrono_literals; #include "modes/defaultmode.h" #include "displays/statusdisplay.h" #include "displays/lockscreen.h" -#include "displays/calibratedisplay.h" +#include "displays/potiscalibratedisplay.h" +#include "displays/buttoncalibratedisplay.h" #include "newsettings.h" #include "taskmanager.h" @@ -71,28 +72,26 @@ extern "C" void app_main() bootLabel.redraw("switchScreen"); -#if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG) - switchScreen(); -#elif defined(FEATURE_DPAD_5WIRESW_2OUT) && defined(DPAD_5WIRESW_DEBUG) - switchScreen(); -#elif defined(FEATURE_DPAD_6WIRESW) && defined(DPAD_6WIRESW_DEBUG) - switchScreen(); -#else - - if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked) + if (configs.dpadMappingLeft.value == INPUT_MAPPING_NONE || + configs.dpadMappingRight.value == INPUT_MAPPING_NONE || + configs.dpadMappingUp.value == INPUT_MAPPING_NONE || + configs.dpadMappingDown.value == INPUT_MAPPING_NONE) + { + espgui::switchScreen(true); + } + else if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked) { espgui::switchScreen(); } else { if (!gas || !brems || *gas > 200.f || *brems > 200.f) - espgui::switchScreen(true); + espgui::switchScreen(true); else { espgui::switchScreen(); } } -#endif while (true) { diff --git a/main/screens.cpp b/main/screens.cpp index 11c4ef3..38e36f6 100644 --- a/main/screens.cpp +++ b/main/screens.cpp @@ -8,7 +8,6 @@ #include "globals.h" #include "utils.h" #include "icons/logo.h" -#include "buttons.h" using namespace espgui; @@ -28,58 +27,6 @@ void initScreen() void updateDisplay() { - if (rotated) - { - const auto rotatedCopy = rotated; - rotated = 0; - - if (currentDisplay) - { - if (rotatedCopy < 0) - currentDisplay->buttonPressed(espgui::Button::Up); - else - currentDisplay->buttonPressed(espgui::Button::Down); - } - } - - if (requestFullRedraw) - { - requestFullRedraw = false; - - tft.init(); - - if (currentDisplay) - currentDisplay->initScreen(); - } - - if (confirmButtonPressed) - { - confirmButtonPressed = false; - - if (currentDisplay) - currentDisplay->buttonPressed(espgui::Button::Right); - } - - if (confirmButtonLongPressed) - { - confirmButtonLongPressed = false; - //Serial.println("todo: implement long press for confirm"); - } - - if (backButtonPressed) - { - backButtonPressed = false; - - if (currentDisplay) - currentDisplay->buttonPressed(espgui::Button::Left); - } - - if (backButtonLongPressed) - { - backButtonLongPressed = false; - //Serial.println("todo: implement long press for back"); - } - if (currentDisplay) currentDisplay->update(); diff --git a/main/settingsutils.cpp b/main/settingsutils.cpp index 3f8967e..bff90f8 100644 --- a/main/settingsutils.cpp +++ b/main/settingsutils.cpp @@ -35,4 +35,4 @@ void switchProfile(uint8_t index) return; } } -} // namespace +} // namespace settingsutils diff --git a/main/settingsutils.h b/main/settingsutils.h index 54dba3d..248cad7 100644 --- a/main/settingsutils.h +++ b/main/settingsutils.h @@ -4,4 +4,4 @@ namespace settingsutils { void switchProfile(uint8_t index); -} +} // namespace settingsutils diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index 2330cc8..04ffdb8 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -14,7 +14,6 @@ // local includes #include "wifi_bobbycar.h" -#include "buttons.h" #include "dpad.h" #ifdef FEATURE_DPAD_3WIRESW #include "dpad3wire.h" @@ -88,7 +87,6 @@ void not_needed() {} espcpputils::SchedulerTask schedulerTasksArr[] { espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms }, - espcpputils::SchedulerTask { "input", InputDispatcher::init, InputDispatcher::update, 20ms }, #ifdef FEATURE_DPAD espcpputils::SchedulerTask { "dpad", dpad::init, dpad::update, 20ms }, #endif diff --git a/main/texthelpers/wifistaconfigtexthelpers.cpp b/main/texthelpers/wifistaconfigtexthelpers.cpp deleted file mode 100644 index cc979c5..0000000 --- a/main/texthelpers/wifistaconfigtexthelpers.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "wifistaconfigtexthelpers.h" - -// 3rdparty lib includes -#include -#include -#include - -// local includes -#include "newsettings.h" - -using namespace espgui; - -std::string WifiStaConfigSsidText::text() const -{ - return fmt::format("&sssid: &f{}", richTextEscape(configs.wifi_configs[m_index].ssid.value)); -} - -std::string WifiStaConfigKeyText::text() const -{ - return fmt::format("&skey: &f{}", richTextEscape(configs.wifi_configs[m_index].key.value)); -} - -std::string WifiStaConfigStaticIpText::text() const -{ - return fmt::format("&sStatic Ip: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticIp.value)); -} - -std::string WifiStaConfigStaticSubnetText::text() const -{ - return fmt::format("&sStatic Mask: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticSubnet.value)); -} - -std::string WifiStaConfigStaticGatewayText::text() const -{ - return fmt::format("&sStatic Gw: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticGateway.value)); -} - -std::string WifiStaConfigStaticDns0Text::text() const -{ - return fmt::format("&sStatic Dns0: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns0.value)); -} - -std::string WifiStaConfigStaticDns1Text::text() const -{ - return fmt::format("&sStatic Dns1: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns1.value)); -} - -std::string WifiStaConfigStaticDns2Text::text() const -{ - return fmt::format("&sStatic Dns2: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns2.value)); -} diff --git a/main/texthelpers/wifistaconfigtexthelpers.h b/main/texthelpers/wifistaconfigtexthelpers.h deleted file mode 100644 index 5b11e55..0000000 --- a/main/texthelpers/wifistaconfigtexthelpers.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -// 3rdparty lib includes -#include - -class WifiStaConfigSsidText : public virtual espgui::TextInterface -{ -public: - WifiStaConfigSsidText(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigKeyText : public virtual espgui::TextInterface -{ -public: - WifiStaConfigKeyText(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticIpText : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticIpText(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticSubnetText : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticSubnetText(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticGatewayText : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticGatewayText(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticDns0Text : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticDns0Text(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticDns1Text : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticDns1Text(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -}; - -class WifiStaConfigStaticDns2Text : public virtual espgui::TextInterface -{ -public: - WifiStaConfigStaticDns2Text(int index) : m_index{index} {} - - std::string text() const override; - -private: - const int m_index; -};