diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 37241cb..61d2b8e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -41,6 +41,7 @@ set(headers bobbybuttons.h bobbycheckbox.h bobbyerrorhandler.h + bobbyhupe.h bobbyquickactions.h bobbyschedulertask.h bobbytypesafeenum.h @@ -187,8 +188,8 @@ set(headers icons/presets.h icons/reboot.h icons/scan.h - icons/shortcircuit.h icons/settings.h + icons/shortcircuit.h icons/statistics.h icons/time.h icons/update.h @@ -279,6 +280,7 @@ set(sources bmsutils.cpp bobbybuttons.cpp bobbyerrorhandler.cpp + bobbyhupe.cpp bobbyquickactions.cpp buildserver.cpp can.cpp @@ -421,8 +423,8 @@ set(sources icons/presets.cpp icons/reboot.cpp icons/scan.cpp - icons/shortcircuit.cpp icons/settings.cpp + icons/shortcircuit.cpp icons/statistics.cpp icons/time.cpp icons/update.cpp diff --git a/main/bobbybuttons.cpp b/main/bobbybuttons.cpp index dc345fb..7ad1923 100644 --- a/main/bobbybuttons.cpp +++ b/main/bobbybuttons.cpp @@ -80,6 +80,20 @@ void buttonPressedCommon(espgui::Button button) } } +void buttonReleasedCommon(espgui::Button button) +{ + switch (BobbyButton(button)) + { + case BobbyButton::Left2: + case BobbyButton::Right2: + case BobbyButton::Up2: + case BobbyButton::Down2: + quickactions::handle_bobby_quickaction(button, false); + break; + default:; + } +} + void BobbyButtons::rawButtonPressed(uint8_t button) { //Base::rawButtonPressed(button); @@ -103,4 +117,5 @@ void BobbyButtons::buttonPressed(espgui::Button button) void BobbyButtons::buttonReleased(espgui::Button button) { //Base::buttonReleased(button); + buttonReleasedCommon(button); } diff --git a/main/bobbybuttons.h b/main/bobbybuttons.h index f11977b..bd206b2 100644 --- a/main/bobbybuttons.h +++ b/main/bobbybuttons.h @@ -22,6 +22,7 @@ enum BobbyButton [[nodiscard]] std::optional translateRawButton(uint8_t button); void buttonPressedCommon(espgui::Button button); +void buttonReleasedCommon(espgui::Button button); class BobbyButtons : public virtual espgui::ButtonsInterface { diff --git a/main/bobbyhupe.cpp b/main/bobbyhupe.cpp new file mode 100644 index 0000000..80df891 --- /dev/null +++ b/main/bobbyhupe.cpp @@ -0,0 +1,65 @@ +#include "bobbyhupe.h" + +// system includes +#include + +// local includes +#include "espnowfunctions.h" + +using namespace std::chrono_literals; + +namespace { +constexpr const char * const TAG = "BOBBY_HUPE"; + +void sendState(const std::string& state) +{ + if (const auto error = espnow::send_espnow_message(fmt::format("{}:0:0", state)); error != ESP_OK) + { + ESP_LOGE(TAG, "Error sending hupe message: %s", esp_err_to_name(error)); + } +} +} // namespace + +namespace bobbyhupe { +bool hupe_state{false}; +std::optional hupe_last_time_sent; + +void activate_hupe() +{ + hupe_state = true; +} + +void deactivate_hupe() +{ + hupe_state = false; +} + +void activate_compressor() +{ + sendState("COMPRESSOR_AN"); +} + +void deactivate_compressor() +{ + sendState("COMPRESSOR_AUS"); +} + +void toggle_compressor() +{ + sendState("COMPRESSOR_TOGGLE"); +} + +void handle_hupe() +{ + if ((hupe_state && !hupe_last_time_sent) || (hupe_state && hupe_last_time_sent && espchrono::ago(*hupe_last_time_sent) > 1s)) + { + hupe_last_time_sent = espchrono::millis_clock::now(); + sendState("BOBBYHUPE_AN"); + } + else if (!hupe_state && hupe_last_time_sent) + { + hupe_last_time_sent = std::nullopt; + sendState("BOBBYHUPE_AUS"); + } +} +} // namespace bobbyhupe diff --git a/main/bobbyhupe.h b/main/bobbyhupe.h new file mode 100644 index 0000000..3281733 --- /dev/null +++ b/main/bobbyhupe.h @@ -0,0 +1,15 @@ +#pragma once + +// 3rdparty lib includes +#include + +namespace bobbyhupe { +extern bool hupe_state; +extern std::optional hupe_last_time_sent; +void handle_hupe(); +void activate_hupe(); +void deactivate_hupe(); +void activate_compressor(); +void deactivate_compressor(); +void toggle_compressor(); +} // namespace bobbyhupe diff --git a/main/bobbyquickactions.cpp b/main/bobbyquickactions.cpp index 5cfdfa3..d43be4a 100644 --- a/main/bobbyquickactions.cpp +++ b/main/bobbyquickactions.cpp @@ -6,10 +6,11 @@ #include "newsettings.h" #include "tempomat.h" #include "wifi_bobbycar.h" +#include "bobbyhupe.h" namespace quickactions { -void handle_bobby_quickaction(espgui::Button button) +void handle_bobby_quickaction(espgui::Button button, bool pressed) { espconfig::ConfigWrapper *config = nullptr; switch (BobbyButton(button)) @@ -30,27 +31,46 @@ void handle_bobby_quickaction(espgui::Button button) return; } - switch (config->value) { - case BobbyQuickActions::BLINK_LEFT: - blink_left(); - break; - case BobbyQuickActions::BLINK_RIGHT: - blink_right(); - break; - case BobbyQuickActions::HANDBREMSE: - handle_handbremse(); - break; - case BobbyQuickActions::OPEN_GARAGE: - open_garage(); - break; - case BobbyQuickActions::WIFI_SCAN: - action_wifi_scan(); - break; - case BobbyQuickActions::PWMOMAT: - handle_pwmomat(); - break; - default: - return; + if (pressed) + { + switch (config->value) { + case BobbyQuickActions::BLINK_LEFT: + blink_left(); + break; + case BobbyQuickActions::BLINK_RIGHT: + blink_right(); + break; + case BobbyQuickActions::HANDBREMSE: + handle_handbremse(); + break; + case BobbyQuickActions::OPEN_GARAGE: + open_garage(); + break; + case BobbyQuickActions::WIFI_SCAN: + action_wifi_scan(); + break; + case BobbyQuickActions::PWMOMAT: + handle_pwmomat(); + break; + case BobbyQuickActions::HUPE: + bobbyhupe::activate_hupe(); + break; + case BobbyQuickActions::COMPRESSOR_TOGGLE: + bobbyhupe::toggle_compressor(); + break; + default: + return; + } + } + else + { + switch (config->value) { + case BobbyQuickActions::HUPE: + bobbyhupe::deactivate_hupe(); + break; + default: + return; + } } } diff --git a/main/bobbyquickactions.h b/main/bobbyquickactions.h index 48efd5b..53dd84e 100644 --- a/main/bobbyquickactions.h +++ b/main/bobbyquickactions.h @@ -14,12 +14,15 @@ x(HANDBREMSE) \ x(OPEN_GARAGE) \ x(WIFI_SCAN) \ - x(PWMOMAT) + x(PWMOMAT) \ + x(HUPE) \ + x(COMPRESSOR_TOGGLE) + DECLARE_TYPESAFE_ENUM(BobbyQuickActions, : uint8_t, BobbyQuickActionsValues) namespace quickactions { -void handle_bobby_quickaction(espgui::Button button); +void handle_bobby_quickaction(espgui::Button button, bool pressed = true); // functions void open_garage(); diff --git a/main/changevaluedisplay_bobbyquickactions.cpp b/main/changevaluedisplay_bobbyquickactions.cpp index 610b399..e164f3b 100644 --- a/main/changevaluedisplay_bobbyquickactions.cpp +++ b/main/changevaluedisplay_bobbyquickactions.cpp @@ -23,6 +23,8 @@ constexpr char TEXT_QUICKACTION_HANDBREMSE[] = "Handbremse"; constexpr char TEXT_QUICKACTION_OPEN_GARAGE[] = "Open Garage"; constexpr char TEXT_QUICKACTION_WIFI_SCAN[] = "Wifi Scan"; constexpr char TEXT_QUICKACTION_TEMPOMAT[] = "Toggle PWM-Omat"; +constexpr char TEXT_QUICKACTION_COMPRESSOR[] = "Remote-Compressor"; +constexpr char TEXT_QUICKACTION_HUPE[] = "Remote-Hupe"; constexpr char TEXT_BACK[] = "Back"; } // namespace @@ -35,6 +37,8 @@ ChangeValueDisplay::ChangeValueDisplay() constructMenuItem, StaticText>>(BobbyQuickActions::OPEN_GARAGE, *this, *this, *this); constructMenuItem, StaticText>>(BobbyQuickActions::WIFI_SCAN, *this, *this, *this); constructMenuItem, StaticText>>(BobbyQuickActions::PWMOMAT, *this, *this, *this); + constructMenuItem, StaticText>>(BobbyQuickActions::COMPRESSOR_TOGGLE, *this, *this, *this); + constructMenuItem, StaticText>>(BobbyQuickActions::HUPE, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); } @@ -51,9 +55,11 @@ void ChangeValueDisplay::start() case BobbyQuickActions::OPEN_GARAGE: setSelectedIndex(4); break; case BobbyQuickActions::WIFI_SCAN: setSelectedIndex(5); break; case BobbyQuickActions::PWMOMAT: setSelectedIndex(6); break; + case BobbyQuickActions::COMPRESSOR_TOGGLE: setSelectedIndex(7); break; + case BobbyQuickActions::HUPE: setSelectedIndex(8); break; default: ESP_LOGW(TAG, "Unknown BobbyQuickActions: %i", std::to_underlying(value)); - setSelectedIndex(7); + setSelectedIndex(9); } } diff --git a/main/displays/bobbydisplay.cpp b/main/displays/bobbydisplay.cpp index dda2469..562882b 100644 --- a/main/displays/bobbydisplay.cpp +++ b/main/displays/bobbydisplay.cpp @@ -26,4 +26,5 @@ void BobbyDisplay::buttonPressed(espgui::Button button) void BobbyDisplay::buttonReleased(espgui::Button button) { //Base::buttonReleased(button); + buttonReleasedCommon(button); } diff --git a/main/displays/bobbymenudisplay.cpp b/main/displays/bobbymenudisplay.cpp index 2066720..3a75d9c 100644 --- a/main/displays/bobbymenudisplay.cpp +++ b/main/displays/bobbymenudisplay.cpp @@ -1,6 +1,7 @@ #include "bobbymenudisplay.h" // local includes +#include "esp_log.h" #include "bobbybuttons.h" void BobbyMenuDisplay::rawButtonPressed(uint8_t button) @@ -26,4 +27,5 @@ void BobbyMenuDisplay::buttonPressed(espgui::Button button) void BobbyMenuDisplay::buttonReleased(espgui::Button button) { //Base::buttonReleased(button); + buttonReleasedCommon(button); } diff --git a/main/espnowfunctions.cpp b/main/espnowfunctions.cpp index fe6b562..a58b450 100644 --- a/main/espnowfunctions.cpp +++ b/main/espnowfunctions.cpp @@ -1,14 +1,17 @@ #include "espnowfunctions.h" +// 3rdparty lib includes #include #include #include #include +// local includes #include "globals.h" #include "utils.h" #include "time_bobbycar.h" #include "newsettings.h" +#include "bobbyhupe.h" namespace espnow { uint16_t lastYear; // Used for esp-now timesync @@ -142,6 +145,7 @@ void initESPNow() void handle() { + bobbyhupe::handle_hupe(); if (initialized < 255 && espnow_init_allowed()) { initESPNow();