Merge pull request #205 from bobbycar-graz/button-calibrate

Removed InputDispatcher, add lots of more changevaluedisplays for wifi
This commit is contained in:
2021-12-31 18:28:49 +01:00
committed by GitHub
49 changed files with 1090 additions and 1689 deletions

View File

@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_6WIRESW_IN3=18
-DPINS_DPAD_6WIRESW_IN4=19
-DPINS_DPAD_6WIRESW_IN5=26
# -DDPAD_5WIRESW_UP=1
# -DDPAD_5WIRESW_DOWN=5
# -DDPAD_5WIRESW_CONFIRM=2
# -DDPAD_5WIRESW_BACK=6
# -DDPAD_5WIRESW_PROFILE0=4
# -DDPAD_5WIRESW_PROFILE1=0
# -DDPAD_5WIRESW_PROFILE2=7
# -DDPAD_5WIRESW_PROFILE3=3
# -DDPAD_5WIRESW_DEBUG
-DDPAD_6WIRESW_UP=1
-DDPAD_6WIRESW_DOWN=5
-DDPAD_6WIRESW_CONFIRM=2
-DDPAD_6WIRESW_BACK=6
-DDPAD_6WIRESW_PROFILE0=4
-DDPAD_6WIRESW_PROFILE1=0
-DDPAD_6WIRESW_PROFILE2=7
-DDPAD_6WIRESW_PROFILE3=3
-DDPAD_6WIRESW_BLINK_LEFT=8
-DDPAD_6WIRESW_BLINK_RIGHT=9
# -DDPAD_6WIRESW_DEBUG
-DFEATURE_GSCHISSENE_DIODE
-DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_6WIRESW_IN3=18
-DPINS_DPAD_6WIRESW_IN4=19
-DPINS_DPAD_6WIRESW_IN5=26
# -DDPAD_5WIRESW_UP=1
# -DDPAD_5WIRESW_DOWN=5
# -DDPAD_5WIRESW_CONFIRM=2
# -DDPAD_5WIRESW_BACK=6
# -DDPAD_5WIRESW_PROFILE0=4
# -DDPAD_5WIRESW_PROFILE1=0
# -DDPAD_5WIRESW_PROFILE2=7
# -DDPAD_5WIRESW_PROFILE3=3
# -DDPAD_5WIRESW_DEBUG
-DDPAD_6WIRESW_UP=1
-DDPAD_6WIRESW_DOWN=5
-DDPAD_6WIRESW_CONFIRM=2
-DDPAD_6WIRESW_BACK=6
-DDPAD_6WIRESW_PROFILE0=4
-DDPAD_6WIRESW_PROFILE1=0
-DDPAD_6WIRESW_PROFILE2=7
-DDPAD_6WIRESW_PROFILE3=3
-DDPAD_6WIRESW_BLINK_LEFT=8
-DDPAD_6WIRESW_BLINK_RIGHT=9
# -DDPAD_6WIRESW_DEBUG
-DFEATURE_GSCHISSENE_DIODE
-DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -48,19 +48,6 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_5WIRESW_IN1=27
-DPINS_DPAD_5WIRESW_IN2=32
-DPINS_DPAD_5WIRESW_IN3=33
-DDPAD_5WIRESW_UP=2
-DDPAD_5WIRESW_DOWN=11
-DDPAD_5WIRESW_CONFIRM=5
-DDPAD_5WIRESW_BACK=8
-DDPAD_5WIRESW_PROFILE0=4
-DDPAD_5WIRESW_PROFILE1=1
-DDPAD_5WIRESW_PROFILE2=10
-DDPAD_5WIRESW_PROFILE3=7
-DDPAD_5WIRESW_BLINK_LEFT=9
-DDPAD_5WIRESW_BLINK_RIGHT=0
-DDPAD_5WIRESW_QUICKACTION_DOWN=3
-DDPAD_5WIRESW_QUICKACTION_UP=6
# -DDPAD_5WIRESW_DEBUG
-DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -48,15 +48,6 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_5WIRESW_IN2=27
-DPINS_DPAD_5WIRESW_IN3=18
-DPINS_DPAD_5WIRESW_IN4=19
-DDPAD_5WIRESW_UP=1
-DDPAD_5WIRESW_DOWN=5
-DDPAD_5WIRESW_CONFIRM=2
-DDPAD_5WIRESW_BACK=6
-DDPAD_5WIRESW_PROFILE0=4
-DDPAD_5WIRESW_PROFILE1=0
-DDPAD_5WIRESW_PROFILE2=7
-DDPAD_5WIRESW_PROFILE3=3
# -DDPAD_5WIRESW_DEBUG
# -DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -48,15 +48,6 @@ set(BOBBYCAR_BUILDFLAGS
# -DPINS_DPAD_5WIRESW_IN2=27
# -DPINS_DPAD_5WIRESW_IN3=18
# -DPINS_DPAD_5WIRESW_IN4=19
# -DDPAD_5WIRESW_UP=1
# -DDPAD_5WIRESW_DOWN=5
# -DDPAD_5WIRESW_CONFIRM=2
# -DDPAD_5WIRESW_BACK=6
# -DDPAD_5WIRESW_PROFILE0=4
# -DDPAD_5WIRESW_PROFILE1=0
# -DDPAD_5WIRESW_PROFILE2=7
# -DDPAD_5WIRESW_PROFILE3=3
# -DDPAD_5WIRESW_DEBUG
-DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -56,30 +56,7 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_6WIRESW_IN3=18
-DPINS_DPAD_6WIRESW_IN4=19
-DPINS_DPAD_6WIRESW_IN5=26
# -DDPAD_5WIRESW_UP=1
# -DDPAD_5WIRESW_DOWN=5
# -DDPAD_5WIRESW_CONFIRM=2
# -DDPAD_5WIRESW_BACK=6
# -DDPAD_5WIRESW_PROFILE0=4
# -DDPAD_5WIRESW_PROFILE1=0
# -DDPAD_5WIRESW_PROFILE2=7
# -DDPAD_5WIRESW_PROFILE3=3
# -DDPAD_5WIRESW_DEBUG
-DDPAD_6WIRESW_UP=1
-DDPAD_6WIRESW_DOWN=5
-DDPAD_6WIRESW_CONFIRM=2
-DDPAD_6WIRESW_BACK=6
-DDPAD_6WIRESW_PROFILE0=4
-DDPAD_6WIRESW_PROFILE1=0
-DDPAD_6WIRESW_PROFILE2=7
-DDPAD_6WIRESW_PROFILE3=3
-DDPAD_6WIRESW_BLINK_LEFT=8
-DDPAD_6WIRESW_BLINK_RIGHT=9
# -DDPAD_6WIRESW_DEBUG
# -DFEATURE_GSCHISSENE_DIODE
# -DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -48,19 +48,6 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_DPAD_5WIRESW_IN1=4
-DPINS_DPAD_5WIRESW_IN2=5
-DPINS_DPAD_5WIRESW_IN3=27
-DDPAD_5WIRESW_UP=4
-DDPAD_5WIRESW_DOWN=7
-DDPAD_5WIRESW_CONFIRM=1
-DDPAD_5WIRESW_BACK=10
-DDPAD_5WIRESW_PROFILE0=11
-DDPAD_5WIRESW_PROFILE1=8
-DDPAD_5WIRESW_PROFILE2=5
-DDPAD_5WIRESW_PROFILE3=2
-DDPAD_5WIRESW_BLINK_LEFT=9
-DDPAD_5WIRESW_BLINK_RIGHT=0
-DDPAD_5WIRESW_QUICKACTION_DOWN=3
-DDPAD_5WIRESW_QUICKACTION_UP=6
# -DDPAD_5WIRESW_DEBUG
-DFEATURE_BLE
# -DFEATURE_BLUETOOTH
# -DFEATURE_BMS

View File

@ -11,7 +11,6 @@ set(headers
bobbycheckbox.h
bobbyerrorhandler.h
buildserver.h
buttons.h
can.h
changevaluedisplay_bluetoothmode.h
changevaluedisplay_controlmode.h
@ -110,11 +109,8 @@ set(headers
displays/bobbymenudisplay.h
displays/bobbypopupdisplay.h
displays/bobbysplitgraphdisplay.h
displays/calibratedisplay.h
displays/buttoncalibratedisplay.h
displays/calibratevoltagedisplay.h
displays/dpad5wire2outdebugdisplay.h
displays/dpad5wiredebugdisplay.h
displays/dpad6wiredebugdisplay.h
displays/gameoflifedisplay.h
displays/gametrakcalibratedisplay.h
displays/ledstripcolorsdisplay.h
@ -185,6 +181,7 @@ set(headers
displays/menus/wifistasettingsmenu.h
displays/metersdisplay.h
displays/pingpongdisplay.h
displays/potiscalibratedisplay.h
displays/poweroffdisplay.h
displays/powersupplydisplay.h
displays/qrcodedebug.h
@ -228,7 +225,6 @@ set(headers
modes/tempomatmode.h
texthelpers/networktexthelpers.h
texthelpers/wifiaptexthelpers.h
texthelpers/wifistaconfigtexthelpers.h
texthelpers/wifistatexthelpers.h
widgets/doubleprogressbar.h
)
@ -244,7 +240,6 @@ set(sources
bobbybuttons.cpp
bobbyerrorhandler.cpp
buildserver.cpp
buttons.cpp
can.cpp
changevaluedisplay_bluetoothmode.cpp
changevaluedisplay_controlmode.cpp
@ -340,11 +335,8 @@ set(sources
displays/bobbymenudisplay.cpp
displays/bobbypopupdisplay.cpp
displays/bobbysplitgraphdisplay.cpp
displays/calibratedisplay.cpp
displays/buttoncalibratedisplay.cpp
displays/calibratevoltagedisplay.cpp
displays/dpad5wire2outdebugdisplay.cpp
displays/dpad5wiredebugdisplay.cpp
displays/dpad6wiredebugdisplay.cpp
displays/gameoflifedisplay.cpp
displays/gametrakcalibratedisplay.cpp
displays/ledstripcolorsdisplay.cpp
@ -413,6 +405,7 @@ set(sources
displays/menus/wifistasettingsmenu.cpp
displays/metersdisplay.cpp
displays/pingpongdisplay.cpp
displays/potiscalibratedisplay.cpp
displays/poweroffdisplay.cpp
displays/powersupplydisplay.cpp
displays/qrcodedebug.cpp
@ -456,7 +449,6 @@ set(sources
modes/tempomatmode.cpp
texthelpers/networktexthelpers.cpp
texthelpers/wifiaptexthelpers.cpp
texthelpers/wifistaconfigtexthelpers.cpp
texthelpers/wifistatexthelpers.cpp
widgets/doubleprogressbar.cpp
)

View File

@ -14,6 +14,9 @@
struct AutoConnectBmsAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.autoConnectBms; } };
#endif
// Bluetooth
struct BluetoothNameAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.bluetoothName; } };
// Buzzer
struct ReverseBeepAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.reverseBeep; } };
struct ReverseBeepFreq0Accessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.reverseBeepFreq0; } };
@ -61,6 +64,7 @@ struct TimezoneOffsetAccessor : public NewSettingsChronoAdaptorAccessor<espchron
struct DaylightSavingModeAccessor : public NewSettingsAccessor<espchrono::DayLightSavingMode> { ConfigWrapper<espchrono::DayLightSavingMode> &getConfig() const override { return configs.timeDst; } };
#ifdef FEATURE_NTP
struct TimeServerEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.timeServerEnabled; } };
struct TimeServerAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.timeServer; } };
struct TimeSyncModeAccessor : public NewSettingsAccessor<sntp_sync_mode_t> { ConfigWrapper<sntp_sync_mode_t> &getConfig() const override { return configs.timeSyncMode; } };
//struct TimeSyncIntervalAccessor : public NewSettingsAccessor<int32_t> { ConfigWrapper<int32_t> &getConfig() const override { return configs.timeSyncInterval; } };
struct TimeSyncIntervalAccessor : public NewSettingsChronoAdaptorAccessor<espchrono::milliseconds32> { ConfigWrapper<espchrono::milliseconds32> &getConfig() const override { return configs.timeSyncInterval; } };

View File

@ -1,11 +1,14 @@
#pragma once
// 3rdparty lib includes
#include "actioninterface.h"
// local includes
#include "ledstrip.h"
// #include "ledstripdefines.h"
#include "ledstripdefines.h"
#ifdef FEATURE_LEDSTRIP
template<uint16_t type>
template<LedstripAnimation type>
class LedStripSetAnimationAction : public virtual espgui::ActionInterface
{
public:

View File

@ -1,7 +1,20 @@
#include "bobbybuttons.h"
// esp-idf includes
#include <esp_log.h>
// local includes
#include "newsettings.h"
#include "settingsutils.h"
#include "modes/defaultmode.h"
#ifdef FEATURE_LEDSTRIP
#include "ledstripdefines.h"
#include "ledstrip.h"
#endif
namespace {
constexpr const char TAG[] = "BUTTONS";
} // namespace
[[nodiscard]] std::optional<espgui::Button> translateRawButton(uint8_t button)
{
@ -35,6 +48,8 @@
if (configs.dpadMappingDown2.value == button)
return Button(BobbyButton::Down2);
ESP_LOGW(TAG, "unknown raw button %hhu", button);
return std::nullopt;
}
@ -42,14 +57,64 @@ void buttonPressedCommon(espgui::Button button)
{
switch (BobbyButton(button))
{
case BobbyButton::Profile0: /* TODO */ break;
case BobbyButton::Profile1: /* TODO */ break;
case BobbyButton::Profile2: /* TODO */ break;
case BobbyButton::Profile3: /* TODO */ break;
case BobbyButton::Left2: /* TODO */ break;
case BobbyButton::Right2: /* TODO */ break;
case BobbyButton::Up2: /* TODO */ break;
case BobbyButton::Down2: /* TODO */ break;
case BobbyButton::Profile0:
settingsutils::switchProfile(0);
break;
case BobbyButton::Profile1:
settingsutils::switchProfile(1);
break;
case BobbyButton::Profile2:
settingsutils::switchProfile(2);
break;
case BobbyButton::Profile3:
settingsutils::switchProfile(3);
break;
case BobbyButton::Left2:
#ifdef FEATURE_LEDSTRIP
if (blinkAnimation == LEDSTRIP_OVERWRITE_NONE) //transition from off to left
{
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT;
}
else if (blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT) // transition to warning
{
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else // transition to off
{
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
break;
case BobbyButton::Right2:
#ifdef FEATURE_LEDSTRIP
if (blinkAnimation == LEDSTRIP_OVERWRITE_NONE) //transition from off to right
{
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT;
}
else if (blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT) // transition to warning
{
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else // transition to off
{
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
break;
case BobbyButton::Up2:
if (settings.handbremse.enable)
{
using namespace handbremse;
if (stateWish == StateWish::brake || angezogen)
stateWish = StateWish::release;
else
stateWish = StateWish::brake;
wishTimer = espchrono::millis_clock::now();
}
break;
case BobbyButton::Down2:
/* TODO */
break;
default:;
}
}

View File

@ -1,191 +0,0 @@
#include "buttons.h"
#include "modes/defaultmode.h"
using namespace std::chrono_literals;
int rotated{};
bool requestFullRedraw{};
bool confirmButtonPressed{};
bool confirmButtonLongPressed{};
bool backButtonPressed{};
bool backButtonLongPressed{};
bool profileButtonDisabled{};
std::optional<espchrono::millis_clock::time_point> upPressedSince;
int upPressRepeat{};
std::optional<espchrono::millis_clock::time_point> downPressedSince;
int downPressRepeat{};
void InputDispatcher::init()
{
}
void InputDispatcher::update()
{
if (upPressedSince && espchrono::ago(*upPressedSince) > (upPressRepeat > 2 ? 50ms : 400ms))
{
upPressedSince = espchrono::millis_clock::now();
upPressRepeat++;
rotated -= 1;
}
if (downPressedSince && espchrono::ago(*downPressedSince) > (downPressRepeat > 2 ? 50ms : 400ms))
{
downPressedSince = espchrono::millis_clock::now();
downPressRepeat++;
rotated += 1;
}
}
void InputDispatcher::rotate(int offset)
{
rotated += offset;
}
void InputDispatcher::upButton(bool pressed)
{
if (pressed)
{
upPressedSince = espchrono::millis_clock::now();
upPressRepeat = 0;
rotated -= 1;
}
else
{
upPressedSince = std::nullopt;
}
}
void InputDispatcher::downButton(bool pressed)
{
if (pressed)
{
downPressedSince = espchrono::millis_clock::now();
downPressRepeat = 0;
rotated += 1;
}
else
{
downPressedSince = std::nullopt;
}
}
void InputDispatcher::confirmButton(bool pressed)
{
static espchrono::millis_clock::time_point pressBegin{};
const auto now = espchrono::millis_clock::now();
if (pressed)
pressBegin = now;
else
{
const auto duration = now - pressBegin;
if (duration < 500ms)
confirmButtonPressed = true;
else if (duration < 2000ms)
confirmButtonLongPressed = true;
else
requestFullRedraw = true;
pressBegin = {};
}
}
void InputDispatcher::backButton(bool pressed)
{
static espchrono::millis_clock::time_point pressBegin{};
const auto now = espchrono::millis_clock::now();
if (pressed)
pressBegin = now;
else
{
const auto duration = now - pressBegin;
if (duration < 500ms)
backButtonPressed = true;
else
backButtonLongPressed = true;
pressBegin = {};
}
}
void InputDispatcher::profileButton(uint8_t index, bool pressed)
{
if (!pressed)
return;
if (profileButtonDisabled)
return;
settingsutils::switchProfile(index);
}
#ifdef SWITCH_BLINK
void InputDispatcher::blinkRightButton(bool pressed)
#else
void InputDispatcher::blinkLeftButton(bool pressed)
#endif
{
if(!pressed)return;
#ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to left
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT;
}
else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT){ // transition to warning
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else{ // transition to off
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
}
#ifndef SWITCH_BLINK
void InputDispatcher::blinkRightButton(bool pressed)
#else
void InputDispatcher::blinkLeftButton(bool pressed)
#endif
{
if(!pressed)return;
#ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to right
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT;
}
else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT){ // transition to warning
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else{ // transition to off
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
}
void InputDispatcher::quickActionButtonDown(bool pressed)
{
using namespace handbremse;
if(!pressed)return;
if (settings.handbremse.enable)
{
if (stateWish == StateWish::brake || angezogen)
stateWish = StateWish::release;
else
stateWish = StateWish::brake;
wishTimer = espchrono::millis_clock::now();
}
}
void InputDispatcher::quickActionButtonUp(bool pressed)
{
}

View File

@ -1,58 +0,0 @@
#pragma once
// system includes
#include <optional>
// 3rdparty lib includes
#include <espchrono.h>
// local includes
#include "settingsutils.h"
#include "ledstripdefines.h"
#ifdef FEATURE_LEDSTRIP
#include "ledstrip.h"
#endif
extern int rotated;
extern bool requestFullRedraw;
extern bool confirmButtonPressed;
extern bool confirmButtonLongPressed;
extern bool backButtonPressed;
extern bool backButtonLongPressed;
extern bool profileButtonDisabled;
extern std::optional<espchrono::millis_clock::time_point> upPressedSince;
extern int upPressRepeat;
extern std::optional<espchrono::millis_clock::time_point> downPressedSince;
extern int downPressRepeat;
class InputDispatcher
{
public:
static void init();
static void update();
static void rotate(int offset);
static void upButton(bool pressed);
static void downButton(bool pressed);
static void confirmButton(bool pressed);
static void backButton(bool pressed);
static void profileButton(uint8_t index, bool pressed);
static void blinkLeftButton(bool pressed);
static void blinkRightButton(bool pressed);
static void quickActionButtonDown(bool pressed);
static void quickActionButtonUp(bool pressed);
};

View File

@ -11,6 +11,8 @@
#include <tftinstance.h>
#include <esp32-hal-gpio.h>
#include <screenmanager.h>
#include <changevaluedisplay.h>
#include <changevaluedisplay_string.h>
// local includes
#include "globals.h"
@ -22,6 +24,9 @@ constexpr const char * const TAG = "DEBUG";
uint8_t consoleControlCharsReceived{};
bool uart0Initialized{};
void handleNormalChar(char c);
void handleSpecialChar(char c);
} // namespace
void initDebugInput()
@ -70,112 +75,140 @@ void handleDebugInput()
else
consoleControlCharsReceived = 0;
break;
case 'i':
case 'I':
consoleControlCharsReceived = 0;
espgui::tft.init();
break;
case 'p':
case 'P':
{
consoleControlCharsReceived = 0;
const auto firstPower = controllers.front.command.poweroff;
for (Controller &controller : controllers)
controller.command.poweroff = !firstPower;
break;
}
case 'l':
case 'L':
{
consoleControlCharsReceived = 0;
const auto firstLed = controllers.front.command.led;
for (Controller &controller : controllers)
controller.command.led = !firstLed;
break;
}
case 'r':
case 'R':
consoleControlCharsReceived = 0;
loadSettings();
break;
case 's':
case 'S':
consoleControlCharsReceived = 0;
saveSettings();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
consoleControlCharsReceived = 0;
for (Controller &controller : controllers)
controller.command.buzzer.freq = c-'0';
break;
case 'z':
case 'Z':
consoleControlCharsReceived = 0;
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Left2));
espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Left2));
}
break;
case 'u':
case 'U':
consoleControlCharsReceived = 0;
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Right2));
espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Right2));
}
break;
default:
consoleControlCharsReceived = 0;
handleNormalChar(c);
}
}
else
{
consoleControlCharsReceived = 0;
switch (c)
{
case 'A': // Up arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Up);
espgui::currentDisplay->buttonReleased(espgui::Button::Up);
}
break;
case 'B': // Down arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Down);
espgui::currentDisplay->buttonReleased(espgui::Button::Down);
}
break;
case 'C': // Right arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Right);
espgui::currentDisplay->buttonReleased(espgui::Button::Right);
}
break;
case 'D': // Left arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Left);
espgui::currentDisplay->buttonReleased(espgui::Button::Left);
}
break;
default:
ESP_LOGI(TAG, "unknown control char received: %hhx", c);
}
handleSpecialChar(c);
}
}
}
}
namespace {
void handleNormalChar(char c)
{
if (auto display = espgui::currentDisplay ? espgui::currentDisplay->asChangeValueDisplayString() : nullptr)
{
switch (c)
{
case ' ' ... '~':
display->setShownValue(display->shownValue() + c);
break;
case 8:
if (auto val = display->shownValue(); !val.empty())
{
val.pop_back();
display->setShownValue(std::move(val));
}
break;
default:
ESP_LOGW(TAG, "unknown char %hhx %c", c, c);
}
}
else
{
switch (c)
{
case 'i':
case 'I':
espgui::tft.init();
break;
case 'p':
case 'P':
{
const auto firstPower = controllers.front.command.poweroff;
for (Controller &controller : controllers)
controller.command.poweroff = !firstPower;
break;
}
case 'l':
case 'L':
{
const auto firstLed = controllers.front.command.led;
for (Controller &controller : controllers)
controller.command.led = !firstLed;
break;
}
case 'r':
case 'R':
loadSettings();
break;
case 's':
case 'S':
saveSettings();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
for (Controller &controller : controllers)
controller.command.buzzer.freq = c-'0';
break;
case 'z':
case 'Z':
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Left2));
espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Left2));
}
break;
case 'u':
case 'U':
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button(BobbyButton::Right2));
espgui::currentDisplay->buttonReleased(espgui::Button(BobbyButton::Right2));
}
break;
}
}
}
void handleSpecialChar(char c)
{
switch (c)
{
case 'A': // Up arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Up);
espgui::currentDisplay->buttonReleased(espgui::Button::Up);
}
break;
case 'B': // Down arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Down);
espgui::currentDisplay->buttonReleased(espgui::Button::Down);
}
break;
case 'C': // Right arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Right);
espgui::currentDisplay->buttonReleased(espgui::Button::Right);
}
break;
case 'D': // Left arrow pressed
if (espgui::currentDisplay)
{
espgui::currentDisplay->buttonPressed(espgui::Button::Left);
espgui::currentDisplay->buttonReleased(espgui::Button::Left);
}
break;
default:
ESP_LOGI(TAG, "unknown control char received: %hhx", c);
}
}
} // namespace

View File

@ -0,0 +1,199 @@
#include "buttoncalibratedisplay.h"
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <tftinstance.h>
#include <fmt/core.h>
#include <screenmanager.h>
// local includes
#include "newsettings.h"
#include "displays/menus/boardcomputerhardwaresettingsmenu.h"
#include "bobbyerrorhandler.h"
namespace {
constexpr const char TAG[] = "BUTTON";
} // namespace
std::string ButtonCalibrateDisplay::text() const
{
return "Button calibrate";
}
void ButtonCalibrateDisplay::start()
{
Base::start();
m_oldMode = currentMode;
currentMode = &m_mode;
m_lastButton = std::nullopt;
m_status = WaitingLeft;
m_finished = false;
}
void ButtonCalibrateDisplay::initScreen()
{
Base::initScreen();
m_labelInstruction.start();
m_labelLeft.start();
m_labelRight.start();
m_labelUp.start();
m_labelDown.start();
m_labelEnd.start();
}
void ButtonCalibrateDisplay::update()
{
Base::update();
if (m_finished)
{
m_finished = false;
if (auto result = configs.write_config(configs.dpadMappingLeft, m_leftButton); !result)
{
BobbyErrorHandler{}.errorOccured(std::move(result).error());
return;
}
if (auto result = configs.write_config(configs.dpadMappingRight, m_rightButton); !result)
{
BobbyErrorHandler{}.errorOccured(std::move(result).error());
return;
}
if (auto result = configs.write_config(configs.dpadMappingUp, m_upButton); !result)
{
BobbyErrorHandler{}.errorOccured(std::move(result).error());
return;
}
if (auto result = configs.write_config(configs.dpadMappingDown, m_downButton); !result)
{
BobbyErrorHandler{}.errorOccured(std::move(result).error());
return;
}
espgui::switchScreen<BoardcomputerHardwareSettingsMenu>();
}
}
void ButtonCalibrateDisplay::redraw()
{
Base::redraw();
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
switch (m_status)
{
case WaitingLeft:
if (m_lastButton)
m_labelInstruction.redraw("Press LEFT again");
else
m_labelInstruction.redraw("Press LEFT");
break;
case WaitingRight:
if (m_lastButton)
m_labelInstruction.redraw("Press RIGHT again");
else
m_labelInstruction.redraw("Press RIGHT");
break;
case WaitingUp:
if (m_lastButton)
m_labelInstruction.redraw("Press UP again");
else
m_labelInstruction.redraw("Press UP");
break;
case WaitingDown:
if (m_lastButton)
m_labelInstruction.redraw("Press DOWN again");
else
m_labelInstruction.redraw("Press DOWN");
break;
case Finished:
m_labelInstruction.redraw("Finished");
break;
}
m_labelLeft.redraw(m_status > WaitingLeft ? fmt::format("Left: {}", m_leftButton) : std::string{});
m_labelRight.redraw(m_status > WaitingRight ? fmt::format("Right: {}", m_rightButton) : std::string{});
m_labelUp.redraw(m_status > WaitingUp ? fmt::format("Up: {}", m_upButton) : std::string{});
m_labelDown.redraw(m_status > WaitingDown ? fmt::format("Down: {}", m_downButton) : std::string{});
m_labelEnd.redraw(m_status == Finished ? "Press RIGHT to save" : "");
}
void ButtonCalibrateDisplay::stop()
{
Base::stop();
if (currentMode == &m_mode)
{
// to avoid crash after deconstruction
m_mode.stop();
lastMode = nullptr;
currentMode = m_oldMode;
}
}
void ButtonCalibrateDisplay::rawButtonPressed(uint8_t button)
{
//Base::rawButtonPressed(button);
if (m_status == Finished)
{
if (button == m_rightButton)
{
ESP_LOGI(TAG, "correct button");
m_finished = true;
}
else
ESP_LOGI(TAG, "wrong button");
}
else if (!m_lastButton || *m_lastButton != button)
m_lastButton = button;
else
{
switch (m_status)
{
case WaitingLeft:
m_leftButton = button;
m_lastButton = std::nullopt;
m_status = WaitingRight;
break;
case WaitingRight:
m_rightButton = button;
m_lastButton = std::nullopt;
m_status = WaitingUp;
break;
case WaitingUp:
m_upButton = button;
m_lastButton = std::nullopt;
m_status = WaitingDown;
break;
case WaitingDown:
m_downButton = button;
m_lastButton = std::nullopt;
m_status = Finished;
break;
case Finished:;
}
}
}
void ButtonCalibrateDisplay::rawButtonReleased(uint8_t button)
{
//Base::rawButtonReleased(button);
}
void ButtonCalibrateDisplay::buttonPressed(espgui::Button button)
{
//Base::buttonPressed(button);
}
void ButtonCalibrateDisplay::buttonReleased(espgui::Button button)
{
//Base::buttonReleased(button);
}

View File

@ -0,0 +1,53 @@
#pragma once
// 3rdparty lib includes
#include <displaywithtitle.h>
#include <widgets/label.h>
// local includes
#include "globals.h"
#include "modeinterface.h"
#include "modes/ignoreinputmode.h"
class ButtonCalibrateDisplay : public espgui::DisplayWithTitle
{
using Base = espgui::DisplayWithTitle;
public:
ButtonCalibrateDisplay() = default;
explicit ButtonCalibrateDisplay(bool bootup) : m_bootup{bootup} {}
std::string text() const override;
void start() override;
void initScreen() override;
void update() override;
void redraw() override;
void stop() override;
void rawButtonPressed(uint8_t button) override;
void rawButtonReleased(uint8_t button) override;
void buttonPressed(espgui::Button button) override;
void buttonReleased(espgui::Button button) override;
private:
const bool m_bootup{false};
ModeInterface *m_oldMode;
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Torque};
std::optional<uint8_t> m_lastButton;
enum { WaitingLeft, WaitingRight, WaitingUp, WaitingDown, Finished } m_status;
espgui::Label m_labelInstruction{25, 72};
espgui::Label m_labelLeft{25, 100};
espgui::Label m_labelRight{25, 125};
espgui::Label m_labelUp{25, 150};
espgui::Label m_labelDown{25, 175};
espgui::Label m_labelEnd{25, 225};
uint8_t m_leftButton, m_rightButton, m_upButton, m_downButton;
bool m_finished;
};

View File

@ -1,94 +0,0 @@
#pragma once
#include "display.h"
#include "globals.h"
#include "widgets/label.h"
#include "dpad5wire_2out.h"
namespace {
#ifdef FEATURE_DPAD_5WIRESW_2OUT
class DPad5Wire2OutDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack
{
public:
void initScreen() override;
void redraw() override;
private:
Label m_labelRaw{0, 50};
Label m_labelUp{175, 75};
Label m_labelDown{175, 100};
Label m_labelBack{175, 125};
Label m_labelConfirm{175, 150};
Label m_labelProfile0{175, 175};
Label m_labelProfile1{175, 200};
Label m_labelProfile2{175, 225};
Label m_labelProfile3{175, 250};
Label m_labelGas{175, 275};
Label m_labelBrems{175, 300};
};
void DPad5Wire2OutDebugDisplay::initScreen()
{
tft.fillScreen(TFT_BLACK);
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW);
tft.drawString("DPad 5wire debug", 5, 5);
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("UP:", 30, 75);
tft.drawString("DOWN:", 30, 100);
tft.drawString("CONFIRM:", 30, 125);
tft.drawString("BACK:", 30, 150);
tft.drawString("PROFILE0:", 30, 175);
tft.drawString("PROFILE1:", 30, 200);
tft.drawString("PROFILE2:", 30, 225);
tft.drawString("PROFILE3:", 30, 250);
tft.drawString("GAS:", 30, 275);
tft.drawString("BREMS:", 30, 300);
m_labelRaw.start();
m_labelUp.start();
m_labelDown.start();
m_labelBack.start();
m_labelConfirm.start();
m_labelProfile0.start();
m_labelProfile1.start();
m_labelProfile2.start();
m_labelProfile3.start();
m_labelGas.start();
m_labelBrems.start();
}
void DPad5Wire2OutDebugDisplay::redraw()
{
m_labelRaw.redraw(std::string{} +
(std::get<0>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<1>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<2>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<3>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<4>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<5>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<6>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<7>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<8>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<9>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<10>(dpad5wire_2out::lastState) ? '1' : '0') + ' ' +
(std::get<11>(dpad5wire_2out::lastState) ? '1' : '0'));
m_labelUp.redraw(std::get<DPAD_5WIRESW_UP>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelDown.redraw(std::get<DPAD_5WIRESW_DOWN>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelBack.redraw(std::get<DPAD_5WIRESW_BACK>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelConfirm.redraw(std::get<DPAD_5WIRESW_CONFIRM>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelProfile0.redraw(std::get<DPAD_5WIRESW_PROFILE0>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelProfile1.redraw(std::get<DPAD_5WIRESW_PROFILE1>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelProfile2.redraw(std::get<DPAD_5WIRESW_PROFILE2>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelProfile3.redraw(std::get<DPAD_5WIRESW_PROFILE3>(dpad5wire_2out::lastState) ? "1" : "0");
m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?");
m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?");
}
#endif
}

View File

@ -1,90 +0,0 @@
#pragma once
#include "display.h"
#include "globals.h"
#include "widgets/label.h"
#include "dpad5wire.h"
namespace {
#ifdef FEATURE_DPAD_5WIRESW
class DPad5WireDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack
{
public:
void initScreen() override;
void redraw() override;
private:
Label m_labelRaw{30, 50};
Label m_labelUp{175, 75};
Label m_labelDown{175, 100};
Label m_labelBack{175, 125};
Label m_labelConfirm{175, 150};
Label m_labelProfile0{175, 175};
Label m_labelProfile1{175, 200};
Label m_labelProfile2{175, 225};
Label m_labelProfile3{175, 250};
Label m_labelGas{175, 275};
Label m_labelBrems{175, 300};
};
void DPad5WireDebugDisplay::initScreen()
{
tft.fillScreen(TFT_BLACK);
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW);
tft.drawString("DPad 5wire debug", 5, 5);
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("UP:", 30, 75);
tft.drawString("DOWN:", 30, 100);
tft.drawString("CONFIRM:", 30, 125);
tft.drawString("BACK:", 30, 150);
tft.drawString("PROFILE0:", 30, 175);
tft.drawString("PROFILE1:", 30, 200);
tft.drawString("PROFILE2:", 30, 225);
tft.drawString("PROFILE3:", 30, 250);
tft.drawString("GAS:", 30, 275);
tft.drawString("BREMS:", 30, 300);
m_labelRaw.start();
m_labelUp.start();
m_labelDown.start();
m_labelBack.start();
m_labelConfirm.start();
m_labelProfile0.start();
m_labelProfile1.start();
m_labelProfile2.start();
m_labelProfile3.start();
m_labelGas.start();
m_labelBrems.start();
}
void DPad5WireDebugDisplay::redraw()
{
m_labelRaw.redraw(std::string{} +
(std::get<0>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<1>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<2>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<3>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<4>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<5>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<6>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<7>(dpad5wire::lastState) ? '1' : '0'));
m_labelUp.redraw(std::get<DPAD_5WIRESW_UP>(dpad5wire::lastState) ? "1" : "0");
m_labelDown.redraw(std::get<DPAD_5WIRESW_DOWN>(dpad5wire::lastState) ? "1" : "0");
m_labelBack.redraw(std::get<DPAD_5WIRESW_BACK>(dpad5wire::lastState) ? "1" : "0");
m_labelConfirm.redraw(std::get<DPAD_5WIRESW_CONFIRM>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile0.redraw(std::get<DPAD_5WIRESW_PROFILE0>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile1.redraw(std::get<DPAD_5WIRESW_PROFILE1>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile2.redraw(std::get<DPAD_5WIRESW_PROFILE2>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile3.redraw(std::get<DPAD_5WIRESW_PROFILE3>(dpad5wire::lastState) ? "1" : "0");
m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?");
m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?");
}
#endif
}

View File

@ -1,92 +0,0 @@
#pragma once
#include "display.h"
#include "globals.h"
#include "widgets/label.h"
#include "dpad6wire.h"
namespace {
#ifdef FEATURE_DPAD_6WIRESW
class DPad6WireDebugDisplay : public Display, public virtual DummyConfirm, public virtual DummyBack
{
public:
void initScreen() override;
void redraw() override;
private:
Label m_labelRaw{0, 50};
Label m_labelUp{175, 75};
Label m_labelDown{175, 100};
Label m_labelBack{175, 125};
Label m_labelConfirm{175, 150};
Label m_labelProfile0{175, 175};
Label m_labelProfile1{175, 200};
Label m_labelProfile2{175, 225};
Label m_labelProfile3{175, 250};
Label m_labelGas{175, 275};
Label m_labelBrems{175, 300};
};
void DPad6WireDebugDisplay::initScreen()
{
tft.fillScreen(TFT_BLACK);
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW);
tft.drawString("DPad 5wire debug", 5, 5);
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("UP:", 30, 75);
tft.drawString("DOWN:", 30, 100);
tft.drawString("CONFIRM:", 30, 125);
tft.drawString("BACK:", 30, 150);
tft.drawString("PROFILE0:", 30, 175);
tft.drawString("PROFILE1:", 30, 200);
tft.drawString("PROFILE2:", 30, 225);
tft.drawString("PROFILE3:", 30, 250);
tft.drawString("GAS:", 30, 275);
tft.drawString("BREMS:", 30, 300);
m_labelRaw.start();
m_labelUp.start();
m_labelDown.start();
m_labelBack.start();
m_labelConfirm.start();
m_labelProfile0.start();
m_labelProfile1.start();
m_labelProfile2.start();
m_labelProfile3.start();
m_labelGas.start();
m_labelBrems.start();
}
void DPad6WireDebugDisplay::redraw()
{
m_labelRaw.redraw(std::string{} +
(std::get<0>(dpad6wire::lastState) ? 'Z' : '0') + ' ' +
(std::get<1>(dpad6wire::lastState) ? '1' : '0') + ' ' +
(std::get<2>(dpad6wire::lastState) ? '2' : '0') + ' ' +
(std::get<3>(dpad6wire::lastState) ? '3' : '0') + ' ' +
(std::get<4>(dpad6wire::lastState) ? '4' : '0') + ' ' +
(std::get<5>(dpad6wire::lastState) ? '5' : '0') + ' ' +
(std::get<6>(dpad6wire::lastState) ? '6' : '0') + ' ' +
(std::get<7>(dpad6wire::lastState) ? '7' : '0') + ' ' +
(std::get<8>(dpad6wire::lastState) ? '8' : '0') + ' ' +
(std::get<9>(dpad6wire::lastState) ? '9' : '0'));
m_labelUp.redraw(std::get<DPAD_6WIRESW_UP>(dpad6wire::lastState) ? "1" : "0");
m_labelDown.redraw(std::get<DPAD_6WIRESW_DOWN>(dpad6wire::lastState) ? "1" : "0");
m_labelBack.redraw(std::get<DPAD_6WIRESW_BACK>(dpad6wire::lastState) ? "1" : "0");
m_labelConfirm.redraw(std::get<DPAD_6WIRESW_CONFIRM>(dpad6wire::lastState) ? "1" : "0");
m_labelProfile0.redraw(std::get<DPAD_6WIRESW_PROFILE0>(dpad6wire::lastState) ? "1" : "0");
m_labelProfile1.redraw(std::get<DPAD_6WIRESW_PROFILE1>(dpad6wire::lastState) ? "1" : "0");
m_labelProfile2.redraw(std::get<DPAD_6WIRESW_PROFILE2>(dpad6wire::lastState) ? "1" : "0");
m_labelProfile3.redraw(std::get<DPAD_6WIRESW_PROFILE3>(dpad6wire::lastState) ? "1" : "0");
m_labelGas.redraw(raw_gas ? std::to_string(*raw_gas) : "?");
m_labelBrems.redraw(raw_brems ? std::to_string(*raw_brems) : "?");
}
#endif
}

View File

@ -8,7 +8,7 @@
#include "globals.h"
#include "utils.h"
#include "displays/menus/mainmenu.h"
#include "displays/calibratedisplay.h"
#include "displays/potiscalibratedisplay.h"
#include "bobbybuttons.h"
#ifdef LOCKSCREEN_PLUGIN
#include "ledstripdefines.h"
@ -88,7 +88,7 @@ void Lockscreen::redraw()
if (m_numbers == settings.lockscreen.pin)
{
if (!gas || !brems || *gas > 200.f || *brems > 200.f)
espgui::switchScreen<CalibrateDisplay>(true);
espgui::switchScreen<PotisCalibrateDisplay>(true);
else
espgui::switchScreen<MainMenu>();
#ifdef LOCKSCREEN_PLUGIN

View File

@ -1,11 +1,15 @@
#include "blesettingsmenu.h"
// 3rdparty lib includes
#include "actions/dummyaction.h"
#include "actions/switchscreenaction.h"
#include "icons/back.h"
#include <actions/dummyaction.h>
#include <actions/switchscreenaction.h>
#include <icons/back.h>
#include <changevaluedisplay.h>
#include <changevaluedisplay_string.h>
#include <textwithvaluehelper.h>
// local includes
#include "displays/bobbychangevaluedisplay.h"
#include "accessors/settingsaccessors.h"
#include "bletexthelpers.h"
#include "displays/menus/settingsmenu.h"
@ -14,16 +18,27 @@
#ifdef FEATURE_BLE
namespace {
constexpr char TEXT_BLESETTINGS[] = "BLE settings";
constexpr char TEXT_BLEENABLED[] = "BLE enabled";
constexpr char TEXT_ENABLED[] = "Enabled";
constexpr char TEXT_NAME[] = "Name";
constexpr char TEXT_NAME_FORMATTED[] = "Name: &s";
constexpr char TEXT_BACK[] = "Back";
using ApSsidChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<std::string>,
espgui::StaticText<TEXT_NAME>,
BluetoothNameAccessor,
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<BleSettingsMenu>>,
espgui::BackActionInterface<espgui::SwitchScreenAction<BleSettingsMenu>>
>;
} // namespace
BleSettingsMenu::BleSettingsMenu()
{
using namespace espgui;
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLEENABLED>, BobbyCheckbox, BleEnabledAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ENABLED>, BobbyCheckbox, BleEnabledAccessor>>();
constructMenuItem<makeComponent<MenuItem, BleServerPeerDevicesText, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BleCharacSubscribedText, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_NAME_FORMATTED, BluetoothNameAccessor>, SwitchScreenAction<ApSsidChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}

View File

@ -14,14 +14,16 @@
#include "icons/lock.h"
#include "accessors/settingsaccessors.h"
#include "displays/menus/lockscreensettingsmenu.h"
#include "displays/calibratedisplay.h"
#include "displays/potiscalibratedisplay.h"
#include "displays/menus/timersmenu.h"
#include "displays/menus/settingsmenu.h"
#include "displays/buttoncalibratedisplay.h"
namespace {
constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings";
constexpr char TEXT_BUTTONCALIBRATE[] = "Button Calibrate";
constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings";
constexpr char TEXT_CALIBRATE[] = "Calibrate";
constexpr char TEXT_POTISCALIBRATE[] = "Potis Calibrate";
constexpr char TEXT_SAMPLECOUNT[] = "sampleCount";
constexpr char TEXT_GASMIN[] = "gasMin";
constexpr char TEXT_GASMAX[] = "gasMax";
@ -171,9 +173,10 @@ using namespace espgui;
BoardcomputerHardwareSettingsMenu::BoardcomputerHardwareSettingsMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LOCKSCREENSETTINGS>, SwitchScreenAction<LockscreenSettingsMenu>, StaticMenuItemIcon<&bobbyicons::lock>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BUTTONCALIBRATE>, SwitchScreenAction<ButtonCalibrateDisplay>>>();
constructMenuItem<makeComponent<MenuItem, GasText, DisabledColor, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BremsText, DisabledColor, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CALIBRATE>, SwitchScreenAction<CalibrateDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POTISCALIBRATE>, SwitchScreenAction<PotisCalibrateDisplay>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SAMPLECOUNT, SampleCountAccessor>, SwitchScreenAction<SampleCountChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_GASMIN, GasMinAccessor>, SwitchScreenAction<GasMinChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_GASMAX, GasMaxAccessor>, SwitchScreenAction<GasMaxChangeScreen>>>();

View File

@ -8,6 +8,7 @@
#include "changevaluedisplay.h"
#include "changevaluedisplay_daylightsavingmode.h"
#include "changevaluedisplay_sntp_sync_mode_t.h"
#include "changevaluedisplay_string.h"
#include "actions/switchscreenaction.h"
#include "actions/dummyaction.h"
#include "icons/back.h"
@ -69,6 +70,14 @@ using DaylightSavingModeChangeDisplay = espgui::makeComponent<
>;
#ifdef FEATURE_NTP
using TimeServerChangeDisplay = espgui::makeComponent<
BobbyChangeValueDisplay<std::string>,
espgui::StaticText<TEXT_NTPSERVER>,
TimeServerAccessor,
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<TimeSettingsMenu>>,
espgui::BackActionInterface<espgui::SwitchScreenAction<TimeSettingsMenu>>
>;
using TimeSyncModeChangeDisplay = espgui::makeComponent<
BobbyChangeValueDisplay<sntp_sync_mode_t>,
espgui::StaticText<TEXT_NTPMODE>,
@ -96,17 +105,16 @@ public:
#endif
} // namespace
using namespace espgui;
TimeSettingsMenu::TimeSettingsMenu()
{
using namespace espgui;
constructMenuItem<makeComponent<MenuItem, CurrentUtcDateTimeText, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, CurrentLocalDateTimeText, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OFFSET>, SwitchScreenAction<TimezoneOffsetChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DAYLIGHTSAVINGMODE>, SwitchScreenAction<DaylightSavingModeChangeDisplay>>>();
#ifdef FEATURE_NTP
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPENABLED>, BobbyCheckbox, TimeServerEnabledAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPSERVER>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPSERVER>, SwitchScreenAction<TimeServerChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPMODE>, SwitchScreenAction<TimeSyncModeChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPINTERVAL>, SwitchScreenAction<TimeSyncIntervalChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, NtpSyncStatusText, DummyAction>>();
@ -121,5 +129,5 @@ std::string TimeSettingsMenu::text() const
void TimeSettingsMenu::back()
{
switchScreen<SettingsMenu>();
espgui::switchScreen<SettingsMenu>();
}

View File

@ -16,6 +16,7 @@
#include "displays/bobbychangevaluedisplay.h"
#include "changevaluedisplay.h"
#include "changevaluedisplay_string.h"
#include "changevaluedisplay_ip_address_t.h"
#include "changevaluedisplay_wifi_auth_mode_t.h"
#include "wifiapclientsmenu.h"
#include "networksettingsmenu.h"
@ -33,17 +34,17 @@ constexpr char TEXT_DISABLEWHENONLINE[] = "Disable when online";
constexpr char TEXT_BACK[] = "Back";
constexpr char TEXT_SSID[] = "AP SSID";
constexpr char TEXT_SSID_FORMATTED[] = "&sssid: &2";
constexpr char TEXT_SSID_FORMATTED[] = "&sssid: ";
constexpr char TEXT_KEY[] = "AP Key";
constexpr char TEXT_KEY_FORMATTED[] = "&skey: &2";
constexpr char TEXT_KEY_FORMATTED[] = "&skey: ";
constexpr char TEXT_IP[] = "AP IP";
constexpr char TEXT_IP_FORMATTED[] = "&sIP: &f&2";
constexpr char TEXT_IP_FORMATTED[] = "&sIP: &f";
constexpr char TEXT_MASK[] = "AP Mask";
constexpr char TEXT_MASK_FORMATTED[] = "&sMask: &f&2";
constexpr char TEXT_MASK_FORMATTED[] = "&sMask: &f";
constexpr char TEXT_CHANNEL[] = "AP Channel";
constexpr char TEXT_CHANNEL_FORMATTED[] = "&sChannel: &f&2";
constexpr char TEXT_CHANNEL_FORMATTED[] = "&sChannel: &f";
constexpr char TEXT_AUTHMODE[] = "AP Authmode";
constexpr char TEXT_AUTHMODE_FORMATTED[] = "&sAuthmode: &2";
constexpr char TEXT_AUTHMODE_FORMATTED[] = "&sAuthmode: ";
class WifiApClientsAction : public virtual ActionInterface
{
@ -67,6 +68,22 @@ using ApKeyChangeScreen = espgui::makeComponent<
espgui::BackActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>
>;
using ApIpChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<wifi_stack::ip_address_t>,
espgui::StaticText<TEXT_IP>,
WifiApIpAccessor,
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>,
espgui::BackActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>
>;
using ApMaskChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<wifi_stack::ip_address_t>,
espgui::StaticText<TEXT_MASK>,
WifiApMaskAccessor,
espgui::ConfirmActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>,
espgui::BackActionInterface<espgui::SwitchScreenAction<WifiApSettingsMenu>>
>;
using ApChannelChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<uint8_t>,
espgui::StaticText<TEXT_CHANNEL>,
@ -87,17 +104,17 @@ using ApAuthmodeChangeScreen = espgui::makeComponent<
WifiApSettingsMenu::WifiApSettingsMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ENABLED>, BobbyCheckbox, WifiApEnabledAccessor>>();
//constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISABLEWHENONLINE>, BobbyCheckbox, WifiApDisableWhenOnlineAccessor>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SSID_FORMATTED, WifiApSsidAccessor>, SwitchScreenAction<ApSsidChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_KEY_FORMATTED, WifiApKeyAccessor>, SwitchScreenAction<ApKeyChangeScreen>>>();
//constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISABLEWHENONLINE>, BobbyCheckbox, WifiApDisableWhenOnlineAccessor>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SSID_FORMATTED, WifiApSsidAccessor>, SwitchScreenAction<ApSsidChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_KEY_FORMATTED, WifiApKeyAccessor>, SwitchScreenAction<ApKeyChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, WifiApMacText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_IP_FORMATTED, WifiApIpAccessor>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_MASK_FORMATTED, WifiApMaskAccessor>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CHANNEL_FORMATTED, WifiApChannelAccessor>, SwitchScreenAction<ApChannelChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_IP_FORMATTED, WifiApIpAccessor>, SwitchScreenAction<ApIpChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_MASK_FORMATTED, WifiApMaskAccessor>, SwitchScreenAction<ApMaskChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CHANNEL_FORMATTED, WifiApChannelAccessor>, SwitchScreenAction<ApChannelChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_AUTHMODE_FORMATTED, WifiApAuthmodeAccessor>, SwitchScreenAction<ApAuthmodeChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, WifiApHostnameText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, WifiApClientsText, WifiApClientsAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<NetworkSettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
constructMenuItem<makeComponent<MenuItem, WifiApHostnameText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, WifiApClientsText, WifiApClientsAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<NetworkSettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
}
std::string WifiApSettingsMenu::text() const

View File

@ -6,22 +6,96 @@
#include <actions/switchscreenaction.h>
#include <icons/back.h>
#include <screenmanager.h>
#include <changevaluedisplay.h>
#include <changevaluedisplay_string.h>
#include <changevaluedisplay_ip_address_t.h>
#include <textwithvaluehelper.h>
// local includes
#include "texthelpers/wifistaconfigtexthelpers.h"
#include "displays/bobbychangevaluedisplay.h"
#include "accessors/wifistaconfigaccessors.h"
#include "wifistaconfigsmenu.h"
#include "newsettings.h"
#include "bobbycheckbox.h"
using namespace espgui;
namespace {
constexpr char TEXT_SSID_TITLE[] = "WiFi {} SSID";
constexpr char TEXT_SSID_FORMATTED[] = "&sSSID: &f";
constexpr char TEXT_KEY_TITLE[] = "WiFi {} Key";
constexpr char TEXT_KEY_FORMATTED[] = "&sKey: &f";
constexpr char TEXT_USESTATICIP[] = "Use Static Ip";
constexpr char TEXT_STATICIP_TITLE[] = "WiFi {} Static Ip";
constexpr char TEXT_STATICIP_FORMATTED[] = "&sStatic Ip: &f";
constexpr char TEXT_STATICMASK_TITLE[] = "WiFi {} Static Mask";
constexpr char TEXT_STATICMASK_FORMATTED[] = "&sStatic Mask: &f";
constexpr char TEXT_STATICGW_TITLE[] = "WiFi {} Static Gw";
constexpr char TEXT_STATICGW_FORMATTED[] = "&sStatic Gw: &f";
constexpr char TEXT_USESTATICDNS[] = "Use Static Dns";
constexpr char TEXT_STATICDNS0_TITLE[] = "WiFi {} Static Dns0";
constexpr char TEXT_STATICDNS0_FORMATTED[] = "&sStatic Dns0: &f";
constexpr char TEXT_STATICDNS1_TITLE[] = "WiFi {} Static Dns1";
constexpr char TEXT_STATICDNS1_FORMATTED[] = "&sStatic Dns1: &f";
constexpr char TEXT_STATICDNS2_TITLE[] = "WiFi {} Static Dns2";
constexpr char TEXT_STATICDNS2_FORMATTED[] = "&sStatic Dns2: &f";
constexpr char TEXT_DELETECONFIG[] = "Delete config";
constexpr char TEXT_BACK[] = "Back";
template<typename T, typename Taccessor, const char *Ttitle>
class StaChangeScreen :
public BobbyChangeValueDisplay<T>,
public Taccessor
{
public:
explicit StaChangeScreen(int index) : Taccessor{index}, m_index{index} {}
std::string text() const override { return fmt::format(Ttitle, m_index + 1); }
void confirm() override { espgui::switchScreen<WifiStaConfigEntryMenu>(m_index); }
void back() override { espgui::switchScreen<WifiStaConfigEntryMenu>(m_index); }
private:
const int m_index;
};
template<typename TchangeScreen, typename Taccessor, const char *Ttext>
class StaChangeMenuItem :
public espgui::MenuItem,
public espgui::TextWithValueHelper<Ttext, Taccessor>
{
public:
explicit StaChangeMenuItem(int index) :
espgui::TextWithValueHelper<Ttext, Taccessor>{index},
m_index{index}
{}
void triggered() override { espgui::switchScreen<TchangeScreen>(m_index); }
private:
const int m_index;
};
using StaSsidChangeScreen = StaChangeScreen<std::string, WifiStaConfigSsidAccessor, TEXT_SSID_TITLE>;
using StaSsidMenuItem = StaChangeMenuItem<StaSsidChangeScreen, WifiStaConfigSsidAccessor, TEXT_SSID_FORMATTED>;
using StaKeyChangeScreen = StaChangeScreen<std::string, WifiStaConfigKeyAccessor, TEXT_KEY_TITLE>;
using StaKeyMenuItem = StaChangeMenuItem<StaKeyChangeScreen, WifiStaConfigKeyAccessor, TEXT_KEY_FORMATTED>;
using StaStaticIpChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticIpAccessor, TEXT_STATICIP_TITLE>;
using StaStaticIpMenuItem = StaChangeMenuItem<StaStaticIpChangeScreen, WifiStaConfigStaticIpAccessor, TEXT_STATICIP_FORMATTED>;
using StaStaticMaskChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticSubnetAccessor, TEXT_STATICMASK_TITLE>;
using StaStaticMaskMenuItem = StaChangeMenuItem<StaStaticMaskChangeScreen, WifiStaConfigStaticSubnetAccessor, TEXT_STATICMASK_FORMATTED>;
using StaStaticGwChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticSubnetAccessor, TEXT_STATICGW_TITLE>;
using StaStaticGwMenuItem = StaChangeMenuItem<StaStaticGwChangeScreen, WifiStaConfigStaticSubnetAccessor, TEXT_STATICGW_FORMATTED>;
using StaStaticDns0ChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS0_TITLE>;
using StaStaticDns0MenuItem = StaChangeMenuItem<StaStaticDns0ChangeScreen, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS0_FORMATTED>;
using StaStaticDns1ChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS1_TITLE>;
using StaStaticDns1MenuItem = StaChangeMenuItem<StaStaticDns1ChangeScreen, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS1_FORMATTED>;
using StaStaticDns2ChangeScreen = StaChangeScreen<wifi_stack::ip_address_t, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS2_TITLE>;
using StaStaticDns2MenuItem = StaChangeMenuItem<StaStaticDns2ChangeScreen, WifiStaConfigStaticSubnetAccessor, TEXT_STATICDNS2_FORMATTED>;
class ClearConfigAction : public virtual espgui::ActionInterface
{
public:
@ -37,16 +111,17 @@ private:
WifiStaConfigEntryMenu::WifiStaConfigEntryMenu(int index) :
m_index{index}
{
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigSsidText, DummyAction>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigKeyText, DummyAction>>(index);
using namespace espgui;
constructMenuItem<StaSsidMenuItem>(index);
constructMenuItem<StaKeyMenuItem>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigUseStaticIpAccessor, StaticText<TEXT_USESTATICIP>, BobbyCheckbox>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticIpText, DummyAction>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticSubnetText, DummyAction>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticGatewayText, DummyAction>>(index);
constructMenuItem<StaStaticIpMenuItem>(index);
constructMenuItem<StaStaticMaskMenuItem>(index);
constructMenuItem<StaStaticGwMenuItem>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigUseStaticDnsAccessor, StaticText<TEXT_USESTATICDNS>, BobbyCheckbox>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticDns0Text, DummyAction>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticDns1Text, DummyAction>>(index);
constructMenuItem<makeComponentArgs<MenuItem, WifiStaConfigStaticDns2Text, DummyAction>>(index);
constructMenuItem<StaStaticDns0MenuItem>(index);
constructMenuItem<StaStaticDns1MenuItem>(index);
constructMenuItem<StaStaticDns2MenuItem>(index);
constructMenuItem<makeComponentArgs<MenuItem, ClearConfigAction, StaticText<TEXT_DELETECONFIG>>>(index);
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<WifiStaConfigsMenu>, StaticMenuItemIcon<&icons::back>>>();
}
@ -58,7 +133,7 @@ std::string WifiStaConfigEntryMenu::text() const
void WifiStaConfigEntryMenu::back()
{
switchScreen<WifiStaConfigsMenu>();
espgui::switchScreen<WifiStaConfigsMenu>();
}
namespace {

View File

@ -1,4 +1,4 @@
#include "calibratedisplay.h"
#include "potiscalibratedisplay.h"
// 3rdparty lib includes
#include <tftinstance.h>
@ -9,22 +9,19 @@
#include "displays/statusdisplay.h"
#include "displays/menus/boardcomputerhardwaresettingsmenu.h"
#include "newsettings.h"
#include "utils.h"
#include "globals.h"
namespace {
constexpr char TEXT_CALIBRATE[] = "Calibrate";
constexpr char TEXT_CALIBRATE[] = "Potis Calibrate";
} // namespace
CalibrateDisplay::CalibrateDisplay(bool bootup) :
m_bootup{bootup}
{
}
std::string CalibrateDisplay::text() const
std::string PotisCalibrateDisplay::text() const
{
return TEXT_CALIBRATE;
}
void CalibrateDisplay::start()
void PotisCalibrateDisplay::start()
{
Base::start();
@ -37,7 +34,7 @@ void CalibrateDisplay::start()
m_brems = std::nullopt;
}
void CalibrateDisplay::initScreen()
void PotisCalibrateDisplay::initScreen()
{
Base::initScreen();
@ -56,7 +53,7 @@ void CalibrateDisplay::initScreen()
m_renderedButton = -1;
}
void CalibrateDisplay::update()
void PotisCalibrateDisplay::update()
{
Base::update();
@ -71,7 +68,7 @@ void CalibrateDisplay::update()
m_brems = std::nullopt;
}
void CalibrateDisplay::redraw()
void PotisCalibrateDisplay::redraw()
{
Base::redraw();
@ -159,7 +156,7 @@ void CalibrateDisplay::redraw()
m_renderedButton = m_selectedButton;
}
void CalibrateDisplay::stop()
void PotisCalibrateDisplay::stop()
{
Base::stop();
@ -173,7 +170,7 @@ void CalibrateDisplay::stop()
}
}
void CalibrateDisplay::buttonPressed(espgui::Button button)
void PotisCalibrateDisplay::buttonPressed(espgui::Button button)
{
Base::buttonPressed(button);
@ -277,7 +274,7 @@ void CalibrateDisplay::buttonPressed(espgui::Button button)
}
}
void CalibrateDisplay::copyFromSettings()
void PotisCalibrateDisplay::copyFromSettings()
{
m_gasMin = configs.gasMin.value;
m_gasMax = configs.gasMax.value;
@ -285,7 +282,7 @@ void CalibrateDisplay::copyFromSettings()
m_bremsMax = configs.bremsMax.value;
}
void CalibrateDisplay::copyToSettings()
void PotisCalibrateDisplay::copyToSettings()
{
configs.write_config(configs.gasMin, m_gasMin);
configs.write_config(configs.gasMax, m_gasMax);

View File

@ -13,17 +13,16 @@
// local includes
#include "bobbydisplaywithtitle.h"
#include "globals.h"
#include "utils.h"
#include "modeinterface.h"
#include "modes/ignoreinputmode.h"
class CalibrateDisplay : public BobbyDisplayWithTitle
class PotisCalibrateDisplay : public BobbyDisplayWithTitle
{
using Base = BobbyDisplayWithTitle;
public:
CalibrateDisplay() = default;
explicit CalibrateDisplay(bool bootup);
PotisCalibrateDisplay() = default;
explicit PotisCalibrateDisplay(bool bootup) : m_bootup{bootup} {}
std::string text() const override;
void start() override;

View File

@ -1,13 +1,19 @@
#pragma once
// system includes
#include <tuple>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <screenmanager.h>
#include "buttons.h"
// local includes
#include "types.h"
#include "newsettings.h"
#include "bobbybuttons.h"
namespace {
namespace dpad

View File

@ -6,12 +6,14 @@
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
#include <screenmanager.h>
// local includes
#include "dpad.h"
#include "buttons.h"
#include "types.h"
#include "globals.h"
#include "newsettings.h"
#include "bobbybuttons.h"
namespace {
namespace dpad3wire

View File

@ -0,0 +1,122 @@
#include "dpad5wire.h"
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
#include <screenmanager.h>
// local includes
#include "types.h"
#include "globals.h"
#include "newsettings.h"
#include "bobbybuttons.h"
namespace {
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
void begin();
std::array<bool, 8> read();
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
void Helper<OUT, IN1, IN2, IN3, IN4>::begin()
{
pinMode(OUT, OUTPUT);
}
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
std::array<bool, 8> Helper<OUT, IN1, IN2, IN3, IN4>::read()
{
std::array<bool, 8> result;
digitalWrite(OUT, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
pinMode(IN4, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
result[3] = digitalRead(IN4)==LOW;
digitalWrite(OUT, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
pinMode(IN4, INPUT_PULLDOWN);
vPortYield();
result[4] = digitalRead(IN1);
result[5] = digitalRead(IN2);
result[6] = digitalRead(IN3);
result[7] = digitalRead(IN4);
return result;
}
#ifdef FEATURE_DPAD_5WIRESW
Helper<PINS_DPAD_5WIRESW_OUT, PINS_DPAD_5WIRESW_IN1, PINS_DPAD_5WIRESW_IN2, PINS_DPAD_5WIRESW_IN3, PINS_DPAD_5WIRESW_IN4> helper;
std::array<bool, 8> lastState;
std::array<espchrono::millis_clock::time_point, 8> debounce;
#endif
} // namespace
#ifdef FEATURE_DPAD_5WIRESW
namespace dpad5wire {
void init()
{
helper.begin();
std::fill(std::begin(lastState), std::end(lastState), false);
std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now());
}
void update()
{
const auto newState = helper.read();
#ifdef DPAD_5WIRESW_DEBUG
lastState = newState;
return;
#endif
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{settings.boardcomputerHardware.dpadDebounce};
for (auto i = 0; i < 8; i++)
if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce)
{
lastState[i] = newState[i];
if (espgui::currentDisplay)
{
if (newState[i])
espgui::currentDisplay->rawButtonPressed(i);
else
espgui::currentDisplay->rawButtonReleased(i);
}
debounce[i] = now;
}
}
} // namespace dpad5wire
#endif

View File

@ -1,188 +1,8 @@
#pragma once
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
// local includes
#include "buttons.h"
#include "types.h"
#include "globals.h"
namespace {
namespace dpad5wire {
#ifdef FEATURE_DPAD_5WIRESW
class State : public std::array<bool, 8>
{
public:
State() : std::array<bool, 8>{false, false, false, false, false, false, false, false} {}
State(const std::array<bool, 8> &other) : std::array<bool, 8>{} {}
State &operator=(const std::array<bool, 8> &other)
{
std::array<bool, 8>::operator=(other);
return *this;
}
State &operator=(const State &other)
{
std::array<bool, 8>::operator=(other);
return *this;
}
bool &up{this->at(DPAD_5WIRESW_UP)};
bool &down{this->at(DPAD_5WIRESW_DOWN)};
bool &confirm{this->at(DPAD_5WIRESW_CONFIRM)};
bool &back{this->at(DPAD_5WIRESW_BACK)};
bool &profile0{this->at(DPAD_5WIRESW_PROFILE0)};
bool &profile1{this->at(DPAD_5WIRESW_PROFILE1)};
bool &profile2{this->at(DPAD_5WIRESW_PROFILE2)};
bool &profile3{this->at(DPAD_5WIRESW_PROFILE3)};
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
void begin();
State read();
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
void Helper<OUT, IN1, IN2, IN3, IN4>::begin()
{
pinMode(OUT, OUTPUT);
}
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
State Helper<OUT, IN1, IN2, IN3, IN4>::read()
{
State result;
digitalWrite(OUT, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
pinMode(IN4, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
result[3] = digitalRead(IN4)==LOW;
digitalWrite(OUT, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
pinMode(IN4, INPUT_PULLDOWN);
vPortYield();
result[4] = digitalRead(IN1);
result[5] = digitalRead(IN2);
result[6] = digitalRead(IN3);
result[7] = digitalRead(IN4);
return result;
}
Helper<PINS_DPAD_5WIRESW_OUT, PINS_DPAD_5WIRESW_IN1, PINS_DPAD_5WIRESW_IN2, PINS_DPAD_5WIRESW_IN3, PINS_DPAD_5WIRESW_IN4> helper;
State lastState;
espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3;
void init()
{
helper.begin();
debounceUp = debounceDown = debounceConfirm = debounceBack = debounceProfile0 = debounceProfile1 = debounceProfile2 = debounceProfile3 = espchrono::millis_clock::now();
}
void update()
{
const auto newState = helper.read();
#ifdef DPAD_5WIRESW_DEBUG
lastState = newState;
return;
#endif
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{settings.boardcomputerHardware.dpadDebounce};
if (lastState.up != newState.up && now - debounceUp > dpadDebounce)
{
lastState.up = newState.up;
InputDispatcher::upButton(newState.up);
debounceUp = now;
}
if (lastState.down != newState.down && now - debounceDown > dpadDebounce)
{
lastState.down = newState.down;
InputDispatcher::downButton(newState.down);
debounceDown = now;
}
if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce)
{
lastState.confirm = newState.confirm;
InputDispatcher::confirmButton(newState.confirm);
debounceConfirm = now;
}
if (lastState.back != newState.back && now - debounceBack > dpadDebounce)
{
lastState.back = newState.back;
InputDispatcher::backButton(newState.back);
debounceBack = now;
}
if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce)
{
lastState.profile0 = newState.profile0;
InputDispatcher::profileButton(0, newState.profile0);
debounceProfile0 = now;
}
if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce)
{
lastState.profile1 = newState.profile1;
InputDispatcher::profileButton(1, newState.profile1);
debounceProfile1 = now;
}
if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce)
{
lastState.profile2 = newState.profile2;
InputDispatcher::profileButton(2, newState.profile2);
debounceProfile2 = now;
}
if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce)
{
lastState.profile3 = newState.profile3;
InputDispatcher::profileButton(3, newState.profile3);
debounceProfile3 = now;
}
}
#endif
namespace dpad5wire {
void init();
void update();
} // namespace dpad5wire
} // namespace
#endif

View File

@ -0,0 +1,145 @@
#include "dpad5wire_2out.h"
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
#include <screenmanager.h>
// local includes
#include "types.h"
#include "globals.h"
#include "newsettings.h"
#include "bobbybuttons.h"
namespace {
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
void begin();
std::array<bool, 12> read();
};
template<pin_t OUT1, pin_t OUT2, pin_t IN1, pin_t IN2, pin_t IN3>
void Helper<OUT1, OUT2, IN1, IN2, IN3>::begin()
{
}
template<pin_t OUT1, pin_t OUT2, pin_t IN1, pin_t IN2, pin_t IN3>
std::array<bool, 12> Helper<OUT1, OUT2, IN1, IN2, IN3>::read()
{
std::array<bool, 12> result;
pinMode(OUT1, OUTPUT);
pinMode(OUT2, INPUT);
digitalWrite(OUT1, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
digitalWrite(OUT1, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
vPortYield();
result[3] = digitalRead(IN1);
result[4] = digitalRead(IN2);
result[5] = digitalRead(IN3);
pinMode(OUT1, INPUT);
pinMode(OUT2, OUTPUT);
digitalWrite(OUT2, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
vPortYield();
result[6] = digitalRead(IN1)==LOW;
result[7] = digitalRead(IN2)==LOW;
result[8] = digitalRead(IN3)==LOW;
digitalWrite(OUT2, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
vPortYield();
result[9] = digitalRead(IN1);
result[10] = digitalRead(IN2);
result[11] = digitalRead(IN3);
return result;
}
#ifdef FEATURE_DPAD_5WIRESW_2OUT
Helper<PINS_DPAD_5WIRESW_OUT1, PINS_DPAD_5WIRESW_OUT2, PINS_DPAD_5WIRESW_IN1, PINS_DPAD_5WIRESW_IN2, PINS_DPAD_5WIRESW_IN3> helper;
std::array<bool, 12> lastState;
std::array<espchrono::millis_clock::time_point, 12> debounce;
#endif
} // namespace
#ifdef FEATURE_DPAD_5WIRESW_2OUT
namespace dpad5wire_2out {
void init()
{
helper.begin();
std::fill(std::begin(lastState), std::end(lastState), false);
std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now());
}
void update()
{
const auto newState = helper.read();
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value};
for (auto i = 0; i < 12; i++)
if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce)
{
lastState[i] = newState[i];
if (espgui::currentDisplay)
{
if (newState[i])
espgui::currentDisplay->rawButtonPressed(i);
else
espgui::currentDisplay->rawButtonReleased(i);
}
debounce[i] = now;
}
}
} // namespace dpad5wire_2out
#endif

View File

@ -1,260 +1,8 @@
#pragma once
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
// local includes
#include "buttons.h"
#include "types.h"
#include "globals.h"
#include "newsettings.h"
namespace {
namespace dpad5wire_2out {
#ifdef FEATURE_DPAD_5WIRESW_2OUT
class State : public std::array<bool, 12>
{
public:
State() : std::array<bool, 12>{false, false, false, false, false, false, false, false, false, false, false, false} {}
State(const std::array<bool, 12> &other) : std::array<bool, 12>{} {}
State &operator=(const std::array<bool, 12> &other)
{
std::array<bool, 12>::operator=(other);
return *this;
}
State &operator=(const State &other)
{
std::array<bool, 12>::operator=(other);
return *this;
}
bool &up{this->at(DPAD_5WIRESW_UP)};
bool &down{this->at(DPAD_5WIRESW_DOWN)};
bool &confirm{this->at(DPAD_5WIRESW_CONFIRM)};
bool &back{this->at(DPAD_5WIRESW_BACK)};
bool &profile0{this->at(DPAD_5WIRESW_PROFILE0)};
bool &profile1{this->at(DPAD_5WIRESW_PROFILE1)};
bool &profile2{this->at(DPAD_5WIRESW_PROFILE2)};
bool &profile3{this->at(DPAD_5WIRESW_PROFILE3)};
bool &blink_left{this->at(DPAD_5WIRESW_BLINK_LEFT)};
bool &blink_right{this->at(DPAD_5WIRESW_BLINK_RIGHT)};
bool &quickaction_down{this->at(DPAD_5WIRESW_QUICKACTION_DOWN)};
bool &quickaction_up{this->at(DPAD_5WIRESW_QUICKACTION_UP)};
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
void begin();
State read();
};
template<pin_t OUT1, pin_t OUT2, pin_t IN1, pin_t IN2, pin_t IN3>
void Helper<OUT1, OUT2, IN1, IN2, IN3>::begin()
{
}
template<pin_t OUT1, pin_t OUT2, pin_t IN1, pin_t IN2, pin_t IN3>
State Helper<OUT1, OUT2, IN1, IN2, IN3>::read()
{
State result;
pinMode(OUT1, OUTPUT);
pinMode(OUT2, INPUT);
digitalWrite(OUT1, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
digitalWrite(OUT1, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
vPortYield();
result[3] = digitalRead(IN1);
result[4] = digitalRead(IN2);
result[5] = digitalRead(IN3);
pinMode(OUT1, INPUT);
pinMode(OUT2, OUTPUT);
digitalWrite(OUT2, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
vPortYield();
result[6] = digitalRead(IN1)==LOW;
result[7] = digitalRead(IN2)==LOW;
result[8] = digitalRead(IN3)==LOW;
digitalWrite(OUT2, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
vPortYield();
result[9] = digitalRead(IN1);
result[10] = digitalRead(IN2);
result[11] = digitalRead(IN3);
return result;
}
Helper<PINS_DPAD_5WIRESW_OUT1, PINS_DPAD_5WIRESW_OUT2, PINS_DPAD_5WIRESW_IN1, PINS_DPAD_5WIRESW_IN2, PINS_DPAD_5WIRESW_IN3> helper;
State lastState;
espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3, debounceBlinkLeft, debounceBlinkRight, debounceQuickactionDown, debounceQuickactionUp;
void init()
{
helper.begin();
debounceUp =
debounceDown =
debounceConfirm =
debounceBack =
debounceProfile0 =
debounceProfile1 =
debounceProfile2 =
debounceProfile3 =
debounceBlinkLeft=
debounceBlinkRight =
debounceQuickactionDown =
debounceQuickactionUp =
espchrono::millis_clock::now();
}
void update()
{
const auto newState = helper.read();
#ifdef DPAD_5WIRESW_DEBUG
lastState = newState;
return;
#endif
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value};
if (lastState.up != newState.up && now - debounceUp > dpadDebounce)
{
lastState.up = newState.up;
InputDispatcher::upButton(newState.up);
debounceUp = now;
}
if (lastState.down != newState.down && now - debounceDown > dpadDebounce)
{
lastState.down = newState.down;
InputDispatcher::downButton(newState.down);
debounceDown = now;
}
if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce)
{
lastState.confirm = newState.confirm;
InputDispatcher::confirmButton(newState.confirm);
debounceConfirm = now;
}
if (lastState.back != newState.back && now - debounceBack > dpadDebounce)
{
lastState.back = newState.back;
InputDispatcher::backButton(newState.back);
debounceBack = now;
}
if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce)
{
lastState.profile0 = newState.profile0;
InputDispatcher::profileButton(0, newState.profile0);
debounceProfile0 = now;
}
if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce)
{
lastState.profile1 = newState.profile1;
InputDispatcher::profileButton(1, newState.profile1);
debounceProfile1 = now;
}
if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce)
{
lastState.profile2 = newState.profile2;
InputDispatcher::profileButton(2, newState.profile2);
debounceProfile2 = now;
}
if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce)
{
lastState.profile3 = newState.profile3;
InputDispatcher::profileButton(3, newState.profile3);
debounceProfile3 = now;
}
if (lastState.blink_left != newState.blink_left && now - debounceBlinkLeft > dpadDebounce)
{
lastState.blink_left = newState.blink_left;
InputDispatcher::blinkLeftButton(newState.blink_left);
debounceBlinkLeft = now;
}
if (lastState.blink_right != newState.blink_right && now - debounceBlinkRight > dpadDebounce)
{
lastState.blink_right = newState.blink_right;
InputDispatcher::blinkRightButton(newState.blink_right);
debounceBlinkRight = now;
}
if (lastState.quickaction_down != newState.quickaction_down && now - debounceQuickactionDown > dpadDebounce)
{
lastState.quickaction_down = newState.quickaction_down;
InputDispatcher::quickActionButtonDown(newState.quickaction_down);
debounceQuickactionDown = now;
}
if (lastState.quickaction_up != newState.quickaction_up && now - debounceQuickactionUp > dpadDebounce)
{
lastState.quickaction_up = newState.quickaction_up;
InputDispatcher::quickActionButtonUp(newState.quickaction_up);
debounceQuickactionUp = now;
}
}
#endif
namespace dpad5wire_2out {
void init();
void update();
} // namespace dpad5wire_2out
} // namespace
#endif

View File

@ -0,0 +1,134 @@
#include "dpad6wire.h"
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
#include <screenmanager.h>
// local includes
#include "types.h"
#include "globals.h"
#include "newsettings.h"
#include "bobbybuttons.h"
namespace {
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
static constexpr auto In5Pin = IN5;
void begin();
std::array<bool, 10> read();
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
void Helper<OUT, IN1, IN2, IN3, IN4, IN5>::begin()
{
pinMode(OUT, OUTPUT);
}
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
std::array<bool, 10> Helper<OUT, IN1, IN2, IN3, IN4, IN5>::read()
{
std::array<bool, 10> result;
digitalWrite(OUT, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
pinMode(IN4, INPUT_PULLUP);
pinMode(IN5, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
result[3] = digitalRead(IN4)==LOW;
result[8] = digitalRead(IN5)==LOW;
digitalWrite(OUT, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
pinMode(IN4, INPUT_PULLDOWN);
pinMode(IN5, INPUT_PULLDOWN);
vPortYield();
result[4] = digitalRead(IN1);
result[5] = digitalRead(IN2);
result[6] = digitalRead(IN3);
result[7] = digitalRead(IN4);
result[9] = digitalRead(IN5);
#ifdef FEATURE_GSCHISSENE_DIODE
if (result[8] && result[9]) result[9] = 0;
#endif
return result;
}
#ifdef FEATURE_DPAD_6WIRESW
Helper<PINS_DPAD_6WIRESW_OUT, PINS_DPAD_6WIRESW_IN1, PINS_DPAD_6WIRESW_IN2, PINS_DPAD_6WIRESW_IN3, PINS_DPAD_6WIRESW_IN4, PINS_DPAD_6WIRESW_IN5> helper;
std::array<bool, 10> lastState;
std::array<espchrono::millis_clock::time_point, 10> debounce;
#endif
} // namespace
#ifdef FEATURE_DPAD_6WIRESW
namespace dpad6wire {
void init()
{
helper.begin();
std::fill(std::begin(lastState), std::end(lastState), false);
std::fill(std::begin(debounce), std::end(debounce), espchrono::millis_clock::now());
}
void update()
{
const auto newState = helper.read();
#ifdef DPAD_6WIRESW_DEBUG
lastState = newState;
return;
#endif
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value};
for (auto i = 0; i < 10; i++)
if (lastState[i] != newState[i] && now - debounce[i] > dpadDebounce)
{
lastState[i] = newState[i];
if (espgui::currentDisplay)
{
if (newState[i])
espgui::currentDisplay->rawButtonPressed(i);
else
espgui::currentDisplay->rawButtonReleased(i);
}
debounce[i] = now;
}
}
} // namespace dpad6wire
#endif

View File

@ -1,214 +1,8 @@
#pragma once
// system includes
#include <array>
// Arduino includes
#include <Arduino.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
// local includes
#include "buttons.h"
#include "types.h"
#include "globals.h"
#include "newsettings.h"
namespace {
namespace dpad6wire {
#ifdef FEATURE_DPAD_6WIRESW
class State : public std::array<bool, 10>
{
public:
State() : std::array<bool, 10>{false, false, false, false, false, false, false, false, false, false} {}
State(const std::array<bool, 10> &other) : std::array<bool, 10>{} {}
State &operator=(const std::array<bool, 10> &other)
{
std::array<bool, 10>::operator=(other);
return *this;
}
State &operator=(const State &other)
{
std::array<bool, 10>::operator=(other);
return *this;
}
bool &up{this->at(DPAD_6WIRESW_UP)};
bool &down{this->at(DPAD_6WIRESW_DOWN)};
bool &confirm{this->at(DPAD_6WIRESW_CONFIRM)};
bool &back{this->at(DPAD_6WIRESW_BACK)};
bool &profile0{this->at(DPAD_6WIRESW_PROFILE0)};
bool &profile1{this->at(DPAD_6WIRESW_PROFILE1)};
bool &profile2{this->at(DPAD_6WIRESW_PROFILE2)};
bool &profile3{this->at(DPAD_6WIRESW_PROFILE3)};
bool &blink_left{this->at(DPAD_6WIRESW_BLINK_LEFT)};
bool &blink_right{this->at(DPAD_6WIRESW_BLINK_RIGHT)};
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
class Helper
{
public:
static constexpr auto OutPin = OUT;
static constexpr auto In1Pin = IN1;
static constexpr auto In2Pin = IN2;
static constexpr auto In3Pin = IN3;
static constexpr auto In4Pin = IN4;
static constexpr auto In5Pin = IN5;
void begin();
State read();
};
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
void Helper<OUT, IN1, IN2, IN3, IN4, IN5>::begin()
{
pinMode(OUT, OUTPUT);
}
template<pin_t OUT, pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4, pin_t IN5>
State Helper<OUT, IN1, IN2, IN3, IN4, IN5>::read()
{
State result;
digitalWrite(OUT, LOW);
pinMode(IN1, INPUT_PULLUP);
pinMode(IN2, INPUT_PULLUP);
pinMode(IN3, INPUT_PULLUP);
pinMode(IN4, INPUT_PULLUP);
pinMode(IN5, INPUT_PULLUP);
vPortYield();
result[0] = digitalRead(IN1)==LOW;
result[1] = digitalRead(IN2)==LOW;
result[2] = digitalRead(IN3)==LOW;
result[3] = digitalRead(IN4)==LOW;
result[8] = digitalRead(IN5)==LOW;
digitalWrite(OUT, HIGH);
pinMode(IN1, INPUT_PULLDOWN);
pinMode(IN2, INPUT_PULLDOWN);
pinMode(IN3, INPUT_PULLDOWN);
pinMode(IN4, INPUT_PULLDOWN);
pinMode(IN5, INPUT_PULLDOWN);
vPortYield();
result[4] = digitalRead(IN1);
result[5] = digitalRead(IN2);
result[6] = digitalRead(IN3);
result[7] = digitalRead(IN4);
result[9] = digitalRead(IN5);
#ifdef FEATURE_GSCHISSENE_DIODE
if (result[8] && result[9]) result[9] = 0;
#endif
return result;
}
Helper<PINS_DPAD_6WIRESW_OUT, PINS_DPAD_6WIRESW_IN1, PINS_DPAD_6WIRESW_IN2, PINS_DPAD_6WIRESW_IN3, PINS_DPAD_6WIRESW_IN4, PINS_DPAD_6WIRESW_IN5> helper;
State lastState;
espchrono::millis_clock::time_point debounceUp, debounceDown, debounceConfirm, debounceBack, debounceProfile0, debounceProfile1, debounceProfile2, debounceProfile3, debounceBlinkLeft, debounceBlinkRight;
void init()
{
helper.begin();
debounceUp = debounceDown = debounceConfirm = debounceBack = debounceProfile0 = debounceProfile1 = debounceProfile2 = debounceProfile3 = debounceBlinkLeft = debounceBlinkRight = espchrono::millis_clock::now();
}
void update()
{
const auto newState = helper.read();
#ifdef DPAD_6WIRESW_DEBUG
lastState = newState;
return;
#endif
const auto now = espchrono::millis_clock::now();
const std::chrono::milliseconds dpadDebounce{configs.dpadDebounce.value};
if (lastState.up != newState.up && now - debounceUp > dpadDebounce)
{
lastState.up = newState.up;
InputDispatcher::upButton(newState.up);
debounceUp = now;
}
if (lastState.down != newState.down && now - debounceDown > dpadDebounce)
{
lastState.down = newState.down;
InputDispatcher::downButton(newState.down);
debounceDown = now;
}
if (lastState.confirm != newState.confirm && now - debounceConfirm > dpadDebounce)
{
lastState.confirm = newState.confirm;
InputDispatcher::confirmButton(newState.confirm);
debounceConfirm = now;
}
if (lastState.back != newState.back && now - debounceBack > dpadDebounce)
{
lastState.back = newState.back;
InputDispatcher::backButton(newState.back);
debounceBack = now;
}
if (lastState.profile0 != newState.profile0 && now - debounceProfile0 > dpadDebounce)
{
lastState.profile0 = newState.profile0;
InputDispatcher::profileButton(0, newState.profile0);
debounceProfile0 = now;
}
if (lastState.profile1 != newState.profile1 && now - debounceProfile1 > dpadDebounce)
{
lastState.profile1 = newState.profile1;
InputDispatcher::profileButton(1, newState.profile1);
debounceProfile1 = now;
}
if (lastState.profile2 != newState.profile2 && now - debounceProfile2 > dpadDebounce)
{
lastState.profile2 = newState.profile2;
InputDispatcher::profileButton(2, newState.profile2);
debounceProfile2 = now;
}
if (lastState.profile3 != newState.profile3 && now - debounceProfile3 > dpadDebounce)
{
lastState.profile3 = newState.profile3;
InputDispatcher::profileButton(3, newState.profile3);
debounceProfile3 = now;
}
if (lastState.blink_left != newState.blink_left && now - debounceBlinkLeft > dpadDebounce)
{
lastState.blink_left = newState.blink_left;
InputDispatcher::blinkLeftButton(newState.blink_left);
debounceBlinkLeft = now;
}
if (lastState.blink_right != newState.blink_right && now - debounceBlinkRight > dpadDebounce)
{
lastState.blink_right = newState.blink_right;
InputDispatcher::blinkRightButton(newState.blink_right);
debounceBlinkRight = now;
}
}
#endif
namespace dpad6wire {
void init();
void update();
} // namespace dpad6wire
} // namespace
#endif

View File

@ -18,12 +18,12 @@ std::vector<CRGB> leds;
uint8_t gHue = 0;
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
uint16_t animation_type = LedstripAnimation::DefaultRainbow;
LedstripAnimation animation_type = LedstripAnimation::DefaultRainbow;
void initLedStrip()
{
animation_type = settings.ledstrip.animationType;
animation_type = LedstripAnimation(settings.ledstrip.animationType);
leds.resize(settings.ledstrip.ledsCount);
FastLED.addLeds<NEOPIXEL, PINS_LEDSTRIP>(&*std::begin(leds), leds.size())
.setCorrection(TypicalSMD5050);

View File

@ -6,6 +6,9 @@
// 3rdparty lib includes
#include <FastLED.h>
// local includes
#include "ledstripdefines.h"
#ifdef FEATURE_LEDSTRIP
enum Bobbycar_Side
{
@ -32,7 +35,7 @@ extern std::vector<CRGB> leds;
extern uint8_t gHue;
extern uint16_t blinkAnimation;
extern uint16_t animation_type;
extern LedstripAnimation animation_type;
void showDefaultLedstrip();
void showAnimation();

View File

@ -14,7 +14,8 @@
#endif
#define LEDSTRIP_OVERWRITE_BLINKBOTH 3
enum LedstripAnimation : uint16_t {
enum LedstripAnimation : uint8_t
{
DefaultRainbow,
BetterRainbow,
SpeedSync,

View File

@ -23,7 +23,8 @@ using namespace std::chrono_literals;
#include "modes/defaultmode.h"
#include "displays/statusdisplay.h"
#include "displays/lockscreen.h"
#include "displays/calibratedisplay.h"
#include "displays/potiscalibratedisplay.h"
#include "displays/buttoncalibratedisplay.h"
#include "newsettings.h"
#include "taskmanager.h"
@ -71,28 +72,26 @@ extern "C" void app_main()
bootLabel.redraw("switchScreen");
#if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG)
switchScreen<DPad5WireDebugDisplay>();
#elif defined(FEATURE_DPAD_5WIRESW_2OUT) && defined(DPAD_5WIRESW_DEBUG)
switchScreen<DPad5Wire2OutDebugDisplay>();
#elif defined(FEATURE_DPAD_6WIRESW) && defined(DPAD_6WIRESW_DEBUG)
switchScreen<DPad6WireDebugDisplay>();
#else
if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked)
if (configs.dpadMappingLeft.value == INPUT_MAPPING_NONE ||
configs.dpadMappingRight.value == INPUT_MAPPING_NONE ||
configs.dpadMappingUp.value == INPUT_MAPPING_NONE ||
configs.dpadMappingDown.value == INPUT_MAPPING_NONE)
{
espgui::switchScreen<ButtonCalibrateDisplay>(true);
}
else if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked)
{
espgui::switchScreen<Lockscreen>();
}
else
{
if (!gas || !brems || *gas > 200.f || *brems > 200.f)
espgui::switchScreen<CalibrateDisplay>(true);
espgui::switchScreen<PotisCalibrateDisplay>(true);
else
{
espgui::switchScreen<StatusDisplay>();
}
}
#endif
while (true)
{

View File

@ -8,7 +8,6 @@
#include "globals.h"
#include "utils.h"
#include "icons/logo.h"
#include "buttons.h"
using namespace espgui;
@ -28,58 +27,6 @@ void initScreen()
void updateDisplay()
{
if (rotated)
{
const auto rotatedCopy = rotated;
rotated = 0;
if (currentDisplay)
{
if (rotatedCopy < 0)
currentDisplay->buttonPressed(espgui::Button::Up);
else
currentDisplay->buttonPressed(espgui::Button::Down);
}
}
if (requestFullRedraw)
{
requestFullRedraw = false;
tft.init();
if (currentDisplay)
currentDisplay->initScreen();
}
if (confirmButtonPressed)
{
confirmButtonPressed = false;
if (currentDisplay)
currentDisplay->buttonPressed(espgui::Button::Right);
}
if (confirmButtonLongPressed)
{
confirmButtonLongPressed = false;
//Serial.println("todo: implement long press for confirm");
}
if (backButtonPressed)
{
backButtonPressed = false;
if (currentDisplay)
currentDisplay->buttonPressed(espgui::Button::Left);
}
if (backButtonLongPressed)
{
backButtonLongPressed = false;
//Serial.println("todo: implement long press for back");
}
if (currentDisplay)
currentDisplay->update();

View File

@ -35,4 +35,4 @@ void switchProfile(uint8_t index)
return;
}
}
} // namespace
} // namespace settingsutils

View File

@ -4,4 +4,4 @@
namespace settingsutils {
void switchProfile(uint8_t index);
}
} // namespace settingsutils

View File

@ -14,7 +14,6 @@
// local includes
#include "wifi_bobbycar.h"
#include "buttons.h"
#include "dpad.h"
#ifdef FEATURE_DPAD_3WIRESW
#include "dpad3wire.h"
@ -88,7 +87,6 @@ void not_needed() {}
espcpputils::SchedulerTask schedulerTasksArr[] {
espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms },
espcpputils::SchedulerTask { "input", InputDispatcher::init, InputDispatcher::update, 20ms },
#ifdef FEATURE_DPAD
espcpputils::SchedulerTask { "dpad", dpad::init, dpad::update, 20ms },
#endif

View File

@ -1,51 +0,0 @@
#include "wifistaconfigtexthelpers.h"
// 3rdparty lib includes
#include <fmt/core.h>
#include <richtextrenderer.h>
#include <espwifiutils.h>
// local includes
#include "newsettings.h"
using namespace espgui;
std::string WifiStaConfigSsidText::text() const
{
return fmt::format("&sssid: &f{}", richTextEscape(configs.wifi_configs[m_index].ssid.value));
}
std::string WifiStaConfigKeyText::text() const
{
return fmt::format("&skey: &f{}", richTextEscape(configs.wifi_configs[m_index].key.value));
}
std::string WifiStaConfigStaticIpText::text() const
{
return fmt::format("&sStatic Ip: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticIp.value));
}
std::string WifiStaConfigStaticSubnetText::text() const
{
return fmt::format("&sStatic Mask: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticSubnet.value));
}
std::string WifiStaConfigStaticGatewayText::text() const
{
return fmt::format("&sStatic Gw: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticGateway.value));
}
std::string WifiStaConfigStaticDns0Text::text() const
{
return fmt::format("&sStatic Dns0: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns0.value));
}
std::string WifiStaConfigStaticDns1Text::text() const
{
return fmt::format("&sStatic Dns1: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns1.value));
}
std::string WifiStaConfigStaticDns2Text::text() const
{
return fmt::format("&sStatic Dns2: &f{}", wifi_stack::toString(configs.wifi_configs[m_index].staticDns2.value));
}

View File

@ -1,92 +0,0 @@
#pragma once
// 3rdparty lib includes
#include <textinterface.h>
class WifiStaConfigSsidText : public virtual espgui::TextInterface
{
public:
WifiStaConfigSsidText(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigKeyText : public virtual espgui::TextInterface
{
public:
WifiStaConfigKeyText(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticIpText : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticIpText(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticSubnetText : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticSubnetText(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticGatewayText : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticGatewayText(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticDns0Text : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticDns0Text(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticDns1Text : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticDns1Text(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};
class WifiStaConfigStaticDns2Text : public virtual espgui::TextInterface
{
public:
WifiStaConfigStaticDns2Text(int index) : m_index{index} {}
std::string text() const override;
private:
const int m_index;
};