Implemented the hupe
This commit is contained in:
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
65
main/bobbyhupe.cpp
Normal 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("BOBBYHUP_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
15
main/bobbyhupe.h
Normal 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
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,17 @@
|
||||
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);
|
||||
|
||||
} // namespace quickactions
|
||||
|
||||
// functions
|
||||
void open_garage();
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user