Added pwmomat

This commit is contained in:
CommanderRedYT
2022-02-14 22:43:32 +01:00
parent e17e7ba5f8
commit 97c9ecec4d
8 changed files with 76 additions and 15 deletions

View File

@ -218,6 +218,7 @@ set(headers
statistics.h
statustexthelper.h
taskmanager.h
tempomat.h
texthelpers/networktexthelpers.h
texthelpers/wifiaptexthelpers.h
texthelpers/wifistatexthelpers.h
@ -449,6 +450,7 @@ set(sources
statistics.cpp
statustexthelper.cpp
taskmanager.cpp
tempomat.cpp
texthelpers/networktexthelpers.cpp
texthelpers/wifiaptexthelpers.cpp
texthelpers/wifistatexthelpers.cpp

View File

@ -2,7 +2,9 @@
// local includes
#include "espnowfunctions.h"
#include "handbremse.h"
#include "newsettings.h"
#include "tempomat.h"
#include "wifi_bobbycar.h"
namespace quickactions {
@ -44,6 +46,9 @@ void handle_bobby_quickaction(espgui::Button button)
case BobbyQuickActions::WIFI_SCAN:
action_wifi_scan();
break;
case BobbyQuickActions::PWMOMAT:
handle_pwmomat();
break;
default:
return;
}
@ -117,18 +122,25 @@ void handle_handbremse()
{
if (configs.handbremse.enable.value)
{
using namespace handbremse;
if (stateWish == StateWish::brake || angezogen)
stateWish = StateWish::release;
using StateWish = handbremse::StateWish;
if (handbremse::stateWish == StateWish::brake || handbremse::angezogen)
handbremse::stateWish = StateWish::release;
else
stateWish = StateWish::brake;
wishTimer = espchrono::millis_clock::now();
handbremse::stateWish = StateWish::brake;
handbremse::wishTimer = espchrono::millis_clock::now();
}
}
void batteryDebugPrint()
void handle_pwmomat()
{
ESP_LOGI("BATTERY", "");
if (pwmomat::tempomat_pwm)
{
pwmomat::wish = pwmomat::WISH::WISH_DISABLE;
}
else
{
pwmomat::wish = pwmomat::WISH::WISH_ENABLE;
}
}
} // namespace quickactions

View File

@ -13,7 +13,8 @@
x(BLINK_RIGHT) \
x(HANDBREMSE) \
x(OPEN_GARAGE) \
x(WIFI_SCAN)
x(WIFI_SCAN) \
x(PWMOMAT)
DECLARE_TYPESAFE_ENUM(BobbyQuickActions, : uint8_t, BobbyQuickActionsValues)
namespace quickactions {
@ -26,6 +27,6 @@ void blink_left();
void blink_right();
void handle_handbremse();
void action_wifi_scan();
void batteryDebugPrint();
void handle_pwmomat();
} // namespace quickactions

View File

@ -22,6 +22,7 @@ constexpr char TEXT_QUICKACTION_BLINK_RIGHT[] = "Blink Right";
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_BACK[] = "Back";
} // namespace
@ -33,6 +34,7 @@ ChangeValueDisplay<BobbyQuickActions>::ChangeValueDisplay()
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<BobbyQuickActions>, StaticText<TEXT_QUICKACTION_HANDBREMSE>>>(BobbyQuickActions::HANDBREMSE, *this, *this, *this);
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, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
}
@ -48,9 +50,10 @@ void ChangeValueDisplay<BobbyQuickActions>::start()
case BobbyQuickActions::HANDBREMSE: setSelectedIndex(3); break;
case BobbyQuickActions::OPEN_GARAGE: setSelectedIndex(4); break;
case BobbyQuickActions::WIFI_SCAN: setSelectedIndex(5); break;
default:
case BobbyQuickActions::PWMOMAT: setSelectedIndex(6); break;
default:
ESP_LOGW(TAG, "Unknown BobbyQuickActions: %i", std::to_underlying(value));
setSelectedIndex(6);
setSelectedIndex(7);
}
}

View File

@ -37,10 +37,6 @@ constexpr char TEXT_SUBGASVAL[] = "Add Gas";
constexpr char TEXT_SUBBRAKEVAL[] = "Add Brake";
constexpr char TEXT_ADDGASVAL[] = "Sub Gas";
constexpr char TEXT_ADDBRAKEVAL[] = "Sub Brake";
constexpr char TEXT_HYBRIDENABLE[] = "Enable Hybrid mode";
constexpr char TEXT_HYBRIDACTIVATIONLIMIT[] = "Hybrid activation-limit";
constexpr char TEXT_HYBRIDDEACTIVATIONLIMIT[] = "Hybrid deactivation-limit";
constexpr char TEXT_LIMITS_TO_NEAR[] = "Hybrid limits too near (>20)";
constexpr char TEXT_HANDBREMSE_ENABLE[] = "Enable Handbremse";
constexpr char TEXT_HANDBREMSE_AUTOMATIC[] = "Automatic Handbremse";
constexpr char TEXT_HANDBREMSE_VISUALIZE[] = "Visualize Handbremse";

View File

@ -1,5 +1,9 @@
#include "defaultmode.h"
// local includes
#include "handbremse.h"
#include "tempomat.h"
using namespace std::chrono_literals;
namespace modes {
@ -214,6 +218,21 @@ void DefaultMode::update()
}
}
if (!pwmomat::tempomat_pwm && pwmomat::wish == pwmomat::WISH::WISH_ENABLE)
{
pwmomat::tempomat_pwm = pwm;
pwmomat::wish = pwmomat::WISH::NONE;
pwmomat::enabled_time = now;
}
else if ((pwmomat::tempomat_pwm && pwmomat::enabled_time) && (espchrono::ago(*pwmomat::enabled_time) > 500ms) && (pwm >= std::min(*pwmomat::tempomat_pwm+10, 1500.f) || pwmomat::wish == pwmomat::WISH::WISH_DISABLE)) // disable tempomat when pwm is larger than saved pwm
{
pwmomat::wish = pwmomat::WISH::NONE;
pwmomat::tempomat_pwm = std::nullopt;
}
if (pwmomat::tempomat_pwm)
pwm = *pwmomat::tempomat_pwm;
m_lastPwm = pwm;
m_lastTime = now;

8
main/tempomat.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "tempomat.h"
namespace pwmomat {
std::optional<float> tempomat_pwm;
std::optional<espchrono::millis_clock::time_point> enabled_time;
WISH wish{WISH::NONE};
} // namespace pwmomat

20
main/tempomat.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
// system includes
#include <optional>
// 3rdparty lib includes
#include <espchrono.h>
namespace pwmomat {
extern std::optional<float> tempomat_pwm; // saved pwm
extern std::optional<espchrono::millis_clock::time_point> enabled_time;
enum class WISH : uint8_t {
NONE,
WISH_ENABLE,
WISH_DISABLE,
};
extern WISH wish;
} // namespace pwmomat