This commit is contained in:
2021-11-01 22:22:41 +01:00
parent 5bbe3fec89
commit 7a11708d57
26 changed files with 200 additions and 91 deletions

3
.gitmodules vendored
View File

@ -58,3 +58,6 @@
[submodule "components/esp-gui-lib"]
path = components/esp-gui-lib
url = ../../0xFEEDC0DE64/esp-gui-lib.git
[submodule "components/espconfiglib"]
path = components/espconfiglib
url = ../../0xFEEDC0DE64/espconfiglib.git

View File

@ -30,6 +30,7 @@ set(headers
globals.h
ledstripdefines.h
ledstrip.h
newsettings.h
macros_bobbycar.h
modeinterface.h
ota.h
@ -59,6 +60,7 @@ set(headers
accessors/globalaccessors.h
accessors/settingsaccessors.h
accessors/wifiaccessors.h
actions/assertaction.h
actions/bluetoothbeginaction.h
actions/bluetoothbeginmasteraction.h
actions/bluetoothconnectbmsaction.h
@ -69,6 +71,7 @@ set(headers
actions/bmsturnoffdischargeaction.h
actions/bmsturnonchargeaction.h
actions/bmsturnondischargeaction.h
actions/dividebyzeroaction.h
actions/erasenvsaction.h
actions/ledstripanimationactions.h
actions/ledstripblinkactions.h
@ -91,6 +94,7 @@ set(headers
displays/gametrakcalibratedisplay.h
displays/garagedisplay.h
displays/graphdisplay.h
displays/ledstripcolorsdisplay.h
displays/lockscreen.h
displays/menus/aboutmenu.h
displays/menus/accesspointwifisettingsmenu.h
@ -116,7 +120,6 @@ set(headers
displays/menus/invertmenu.h
displays/menus/larsmmodesettingsmenu.h
displays/menus/ledstripmenu.h
displays/menus/ledstripcolorsmenu.h
displays/menus/ledstripselectanimationmenu.h
displays/menus/ledstripselectblinkmenu.h
displays/menus/limitssettingsmenu.h
@ -211,6 +214,7 @@ set(sources
globals.cpp
ledstrip.cpp
ledstripdefines.cpp
newsettings.cpp
macros_bobbycar.cpp
main.cpp
modeinterface.cpp
@ -241,6 +245,7 @@ set(sources
accessors/globalaccessors.cpp
accessors/settingsaccessors.cpp
accessors/wifiaccessors.cpp
actions/assertaction.cpp
actions/bluetoothbeginaction.cpp
actions/bluetoothbeginmasteraction.cpp
actions/bluetoothconnectbmsaction.cpp
@ -251,6 +256,7 @@ set(sources
actions/bmsturnoffdischargeaction.cpp
actions/bmsturnonchargeaction.cpp
actions/bmsturnondischargeaction.cpp
actions/dividebyzeroaction.cpp
actions/erasenvsaction.cpp
actions/ledstripanimationactions.cpp
actions/ledstripblinkactions.cpp
@ -273,6 +279,7 @@ set(sources
displays/gametrakcalibratedisplay.cpp
displays/garagedisplay.cpp
displays/graphdisplay.cpp
displays/ledstripcolorsdisplay.cpp
displays/lockscreen.cpp
displays/menus/aboutmenu.cpp
displays/menus/accesspointwifisettingsmenu.cpp
@ -362,7 +369,7 @@ set(dependencies
libsodium freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver
arduino-esp32 ArduinoJson esp-nimble-cpp FastLED-idf TFT_eSPI
bobbycar-protocol cpputils cxx-ring-buffer date
espasynchttpreq espasyncota espchrono espcpputils esp-gui-lib esphttpdutils espwifistack expected fmt
espasynchttpreq espasyncota espchrono espcpputils espconfiglib esp-gui-lib esphttpdutils espwifistack expected fmt
)
idf_component_register(

View File

@ -0,0 +1 @@
#include "globalaccessors.h"

View File

@ -5,14 +5,8 @@
#include "globals.h"
#include "modes/tempomatmode.h"
using namespace espgui;
struct AvgSpeedAccessor : public espgui::RefAccessor<float> { float &getRef() const override { return avgSpeed; } };
struct AvgSpeedKmhAccessor : public espgui::RefAccessor<float> { float &getRef() const override { return avgSpeedKmh; } };
struct SumCurrentAccessor : public espgui::RefAccessor<float> { float &getRef() const override { return sumCurrent; } };
namespace {
struct AvgSpeedAccessor : public RefAccessor<float> { float &getRef() const override { return avgSpeed; } };
struct AvgSpeedKmhAccessor : public RefAccessor<float> { float &getRef() const override { return avgSpeedKmh; } };
struct SumCurrentAccessor : public RefAccessor<float> { float &getRef() const override { return sumCurrent; } };
struct TempomatModeCruiseMotTgtAccessor : public RefAccessor<int16_t> { int16_t &getRef() const override { return modes::tempomatMode.nCruiseMotTgt; } };
} // namespace
struct TempomatModeCruiseMotTgtAccessor : public espgui::RefAccessor<int16_t> { int16_t &getRef() const override { return modes::tempomatMode.nCruiseMotTgt; } };

View File

@ -0,0 +1 @@
#include "settingsaccessors.h"

View File

@ -1,18 +1,17 @@
#pragma once
// 3rdparty lib includes
#include <accessorinterface.h>
// local includes
#include "globals.h"
#include "accessorinterface.h"
#include "utils.h"
using namespace espgui;
namespace {
//! Special type of RefAccessor that also saves settings after setValue()
template<typename T>
struct RefAccessorSaveSettings : public virtual RefAccessor<T>
struct RefAccessorSaveSettings : public virtual espgui::RefAccessor<T>
{
void setValue(T value) override { RefAccessor<T>::setValue(value); saveSettings(); };
void setValue(T value) override { espgui::RefAccessor<T>::setValue(value); saveSettings(); };
};
#ifdef FEATURE_BMS
@ -26,7 +25,7 @@ struct ReverseBeepDuration1Accessor : public RefAccessorSaveSettings<int16_t> {
struct IMotMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.iMotMax; } };
struct IDcMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.iDcMax; } };
struct NMotMaxKmhAccessor : public virtual AccessorInterface<int16_t>
struct NMotMaxKmhAccessor : public virtual espgui::AccessorInterface<int16_t>
{
int16_t getValue() const override { return convertToKmh(settings.limits.nMotMax); }
void setValue(int16_t value) override { settings.limits.nMotMax = convertFromKmh(value); saveSettings(); }
@ -50,7 +49,7 @@ struct CloudEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRe
struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.cloudSettings.cloudTransmitTimeout; } };
#endif
struct TimezoneOffsetAccessor : public virtual AccessorInterface<int32_t>
struct TimezoneOffsetAccessor : public virtual espgui::AccessorInterface<int32_t>
{
int32_t getValue() const override { return settings.timeSettings.timezoneOffset.count(); }
void setValue(int32_t value) override { settings.timeSettings.timezoneOffset = espchrono::minutes32{value}; saveSettings(); }
@ -59,7 +58,7 @@ struct DaylightSavingModeAccessor : public RefAccessorSaveSettings<espchrono::Da
#ifdef FEATURE_NTP
struct TimeServerEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.timeSettings.timeServerEnabled; } };
struct TimeSyncModeAccessor : public RefAccessorSaveSettings<sntp_sync_mode_t> { sntp_sync_mode_t &getRef() const override { return settings.timeSettings.timeSyncMode; } };
struct TimeSyncIntervalAccessor : public virtual AccessorInterface<int32_t>
struct TimeSyncIntervalAccessor : public virtual espgui::AccessorInterface<int32_t>
{
int32_t getValue() const override { return settings.timeSettings.timeSyncInterval.count(); }
void setValue(int32_t value) override { settings.timeSettings.timeSyncInterval = espchrono::milliseconds32{value}; saveSettings(); }
@ -77,7 +76,7 @@ struct BackLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &g
struct BackRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertBackRight; } };
struct WheelDiameterMmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.wheelDiameter; } };
struct WheelDiameterInchAccessor : public virtual AccessorInterface<float>
struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface<float>
{
float getValue() const override { return convertToInch(settings.controllerHardware.wheelDiameter); }
void setValue(float value) override { settings.controllerHardware.wheelDiameter = convertFromInch(value); saveSettings(); }
@ -183,4 +182,3 @@ struct BatteryApplyCalibrationAccessor : public RefAccessorSaveSettings<bool> {
struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } };
template<uint8_t index>
struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings<int8_t> { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } };
}

View File

@ -0,0 +1 @@
#include "wifiaccessors.h"

View File

@ -2,8 +2,3 @@
// local includes
#include "accessorinterface.h"
using namespace espgui;
namespace {
}

View File

@ -0,0 +1,9 @@
#include "assertaction.h"
// system includes
#include <cassert>
void AssertAction::triggered()
{
assert(0);
}

View File

@ -0,0 +1,10 @@
#pragma once
// 3rdparty lib includes
#include "actioninterface.h"
class AssertAction : public virtual espgui::ActionInterface
{
public:
void triggered() override;
};

View File

@ -0,0 +1,12 @@
#include "dividebyzeroaction.h"
// esp-idf includes
#include <esp_log.h>
void DivideByZeroAction::triggered()
{
int i = 1;
i--;
int goodbye = 42 / i;
ESP_LOGW("BOBBY", "divide by zero %i", goodbye);
}

View File

@ -0,0 +1,10 @@
#pragma once
// 3rdparty lib includes
#include "actioninterface.h"
class DivideByZeroAction : public virtual espgui::ActionInterface
{
public:
void triggered() override;
};

View File

View File

@ -1,31 +1,31 @@
#pragma once
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <TFT_eSPI.h>
#include <FastLED.h>
#include <cpputils.h>
#include <menuitem.h>
#include <actions/switchscreenaction.h>
#include <actioninterface.h>
// Local includes
// local includes
#include "menudisplay.h"
#include "utils.h"
#include "menuitem.h"
#include "ledstrip.h"
#include "icons/back.h"
#include "icons/bobbycar.h"
#include "texts.h"
#include "actions/dummyaction.h"
#include "actions/switchscreenaction.h"
#include "actioninterface.h"
#include "globals.h"
#include "esp_log.h"
using namespace espgui;
namespace {
class LedstripMenu;
class LedstripMenu;
}
namespace {
static int8_t selected_side = 7;
static int8_t selected_color;
bool state_select_color{false};
@ -53,46 +53,56 @@ const std::array<uint16_t, 8> tft_colors = {
TFT_MAGENTA
};
class LedstripColorsMenuBackAction : ActionInterface
class LedstripColorsDisplay : public espgui::DisplayWithTitle
{
public:
void triggered() {
if(!state_select_color)
{
switchScreen<LedstripMenu>();
}
else
{
state_select_color = false;
tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK);
}
}
};
using Base = espgui::DisplayWithTitle;
class LedstripColorsMenu :
public MenuDisplay,
public StaticText<TEXT_LEDSTRIPCOLORMENU>,
public BackActionInterface<LedstripColorsMenuBackAction>
{
using Base = MenuDisplay;
public:
std::string text() const override;
void back() override;
void initScreen() override;
void redraw() override;
void rotate(int offset) override;
void confirm() override;
void drawColors();
void drawSide(Bobbycar_Side side, unsigned int color);
void clearSides();
LedstripColorsMenu() {}
private:
bool already_drew_circle{false};
};
void LedstripColorsMenu::redraw()
std::string LedstripColorsDisplay::text() const
{
Base::redraw();
return TEXT_LEDSTRIPCOLORMENU;
}
void LedstripColorsDisplay::back()
{
if(!state_select_color)
{
switchScreen<LedstripMenu>();
}
else
{
state_select_color = false;
tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK);
}
}
void LedstripColorsDisplay::initScreen()
{
Base::initScreen();
tft.setSwapBytes(true);
tft.pushImage(70, 60, bobbyicons::bobbycar.WIDTH, bobbyicons::bobbycar.HEIGHT, bobbyicons::bobbycar.buffer);
tft.setSwapBytes(false);
}
void LedstripColorsDisplay::redraw()
{
Base::redraw();
auto y_pos = ((tft.width() - 40) / 8 + 4) + 240;
if (last_state != state_select_color)
@ -103,22 +113,19 @@ void LedstripColorsMenu::redraw()
tft.setTextFont(2);
tft.setTextColor(TFT_WHITE);
if(state_select_color)
tft.drawString(state_select_color ?
"Please select a color!" :
"Please select a side!", 50, y_pos);
if (!already_drew_circle)
{
tft.drawString("Please select a color!", 50, y_pos);
}
else
{
tft.drawString("Please select a side!", 50, y_pos);
}
if(!already_drew_circle)
{
this->drawSide(static_cast<Bobbycar_Side>(selected_side), TFT_GOLD);
drawSide(static_cast<Bobbycar_Side>(selected_side), TFT_GOLD);
already_drew_circle = true;
}
}
void LedstripColorsMenu::rotate(int offset)
void LedstripColorsDisplay::rotate(int offset)
{
if (offset < 0)
{
@ -161,22 +168,22 @@ void LedstripColorsMenu::rotate(int offset)
if (state_select_color)
{
this->drawColors();
drawColors();
}
else
{
tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK);
this->clearSides();
this->drawSide(static_cast<Bobbycar_Side>(selected_side), TFT_GOLD);
clearSides();
drawSide(static_cast<Bobbycar_Side>(selected_side), TFT_GOLD);
}
}
void LedstripColorsMenu::confirm()
void LedstripColorsDisplay::confirm()
{
if(!state_select_color)
{
state_select_color = true;
this->drawColors();
drawColors();
}
else
{
@ -189,7 +196,7 @@ void LedstripColorsMenu::confirm()
}
}
void LedstripColorsMenu::drawColors()
void LedstripColorsDisplay::drawColors()
{
uint16_t width = (tft.width() - 40);
auto cube_width = width / 8;
@ -205,15 +212,15 @@ void LedstripColorsMenu::drawColors()
}
}
void LedstripColorsMenu::clearSides()
void LedstripColorsDisplay::clearSides()
{
for(int index = 0; index < 8; index++)
{
this->drawSide(static_cast<Bobbycar_Side>(index), TFT_BLACK);
drawSide(static_cast<Bobbycar_Side>(index), TFT_BLACK);
}
}
void LedstripColorsMenu::drawSide(Bobbycar_Side side, unsigned int color)
void LedstripColorsDisplay::drawSide(Bobbycar_Side side, unsigned int color)
{
const auto middle = tft.width() / 2;
const auto width = bobbyicons::bobbycar.WIDTH;

View File

@ -4,19 +4,14 @@
#include "menudisplay.h"
#include "utils.h"
#include "actions/dummyaction.h"
#include "actions/assertaction.h"
#include "actions/dividebyzeroaction.h"
#include "icons/back.h"
#include "texts.h"
#include <esp_log.h>
// forward declares
namespace {
class SettingsMenu;
class AssertAction : public virtual ActionInterface { public: void triggered() override { assert(0); } };
class DivideByZeroAction : public virtual ActionInterface { public: void triggered() override { int goodbye = 42 / 0; ESP_LOGW("divByZero", "%i", goodbye); } };
} // namespace
using namespace espgui;

View File

@ -23,7 +23,7 @@
// forward declares
namespace {
class MainWindow;
class LedstripColorsMenu;
class LedstripColorsDisplay;
} // namespace
using namespace espgui;
@ -124,7 +124,7 @@ class LedstripMenu :
public:
LedstripMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIPCOLORMENU>, SwitchScreenAction<LedstripColorsMenu>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIPCOLORMENU>, SwitchScreenAction<LedstripColorsDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDANIMATION>, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BRAKELIGHTS>, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLINKBEEP>, ToggleBoolAction, CheckboxIcon, EnableBeepWhenBlinkAccessor>>();

View File

@ -62,7 +62,7 @@ using namespace std::chrono_literals;
#include "displays/menus/tempomatmodesettingsmenu.h"
#include "displays/menus/modessettingsmenu.h"
#ifdef FEATURE_LEDSTRIP
#include "displays/menus/ledstripcolorsmenu.h"
#include "displays/ledstripcolorsdisplay.h"
#endif
#ifdef FEATURE_MOSFETS
#include "displays/menus/mosfetsmenu.h"

0
main/newsettings.cpp Normal file
View File

0
main/newsettings.h Normal file
View File

View File

@ -180,6 +180,19 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
# end of Simple Async HTTP Request
#
# ESP Config lib settings
#
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_NONE is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_ERROR is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_WARN is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG_INFO=y
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_DEBUG is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_VERBOSE is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG=3
# CONFIG_SEPARATE_FACTORY_NVS_PARTITION is not set
# end of ESP Config lib settings
#
# espcpputils settings
#

View File

@ -180,6 +180,19 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
# end of Simple Async HTTP Request
#
# ESP Config lib settings
#
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_NONE is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_ERROR is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_WARN is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG_INFO=y
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_DEBUG is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_VERBOSE is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG=3
# CONFIG_SEPARATE_FACTORY_NVS_PARTITION is not set
# end of ESP Config lib settings
#
# espcpputils settings
#

View File

@ -180,6 +180,19 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
# end of Simple Async HTTP Request
#
# ESP Config lib settings
#
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_NONE is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_ERROR is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_WARN is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG_INFO=y
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_DEBUG is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_VERBOSE is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG=3
# CONFIG_SEPARATE_FACTORY_NVS_PARTITION is not set
# end of ESP Config lib settings
#
# espcpputils settings
#

View File

@ -180,6 +180,19 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
# end of Simple Async HTTP Request
#
# ESP Config lib settings
#
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_NONE is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_ERROR is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_WARN is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG_INFO=y
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_DEBUG is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_VERBOSE is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG=3
# CONFIG_SEPARATE_FACTORY_NVS_PARTITION is not set
# end of ESP Config lib settings
#
# espcpputils settings
#

View File

@ -180,6 +180,19 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
# end of Simple Async HTTP Request
#
# ESP Config lib settings
#
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_NONE is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_ERROR is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_WARN is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG_INFO=y
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_DEBUG is not set
# CONFIG_LOG_LOCAL_LEVEL_CONFIG_VERBOSE is not set
CONFIG_LOG_LOCAL_LEVEL_CONFIG=3
# CONFIG_SEPARATE_FACTORY_NVS_PARTITION is not set
# end of ESP Config lib settings
#
# espcpputils settings
#