Merge pull request #291 from bobbycar-graz/hupen-update

This commit is contained in:
CommanderRedYT
2022-03-24 23:04:48 +01:00
committed by GitHub
11 changed files with 161 additions and 27 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -22,6 +22,7 @@ enum BobbyButton
[[nodiscard]] std::optional<espgui::Button> translateRawButton(uint8_t button);
void buttonPressedCommon(espgui::Button button);
void buttonReleasedCommon(espgui::Button button);
class BobbyButtons : public virtual espgui::ButtonsInterface
{

65
main/bobbyhupe.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "bobbyhupe.h"
// system includes
#include <esp_log.h>
// 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<espchrono::millis_clock::time_point> 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

15
main/bobbyhupe.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
// 3rdparty lib includes
#include <espchrono.h>
namespace bobbyhupe {
extern bool hupe_state;
extern std::optional<espchrono::millis_clock::time_point> hupe_last_time_sent;
void handle_hupe();
void activate_hupe();
void deactivate_hupe();
void activate_compressor();
void deactivate_compressor();
void toggle_compressor();
} // namespace bobbyhupe

View File

@ -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<BobbyQuickActions> *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;
}
}
}

View File

@ -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();

View File

@ -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<BobbyQuickActions>::ChangeValueDisplay()
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_OPEN_GARAGE>>>(BobbyQuickActions::OPEN_GARAGE, *this, *this, *this);
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_WIFI_SCAN>>>(BobbyQuickActions::WIFI_SCAN, *this, *this, *this);
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_TEMPOMAT>>>(BobbyQuickActions::PWMOMAT, *this, *this, *this);
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_COMPRESSOR>>>(BobbyQuickActions::COMPRESSOR_TOGGLE, *this, *this, *this);
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_HUPE>>>(BobbyQuickActions::HUPE, *this, *this, *this);
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
}
@ -51,9 +55,11 @@ void ChangeValueDisplay<BobbyQuickActions>::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);
}
}

View File

@ -26,4 +26,5 @@ void BobbyDisplay::buttonPressed(espgui::Button button)
void BobbyDisplay::buttonReleased(espgui::Button button)
{
//Base::buttonReleased(button);
buttonReleasedCommon(button);
}

View File

@ -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);
}

View File

@ -1,14 +1,17 @@
#include "espnowfunctions.h"
// 3rdparty lib includes
#include <espchrono.h>
#include <esp_log.h>
#include <numberparsing.h>
#include <espwifistack.h>
// 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();