Removed InputDispatcher, add lots of more changevaluedisplays for wifi

This commit is contained in:
2021-12-30 06:00:04 +01:00
parent 973fb66985
commit b1de1de93a
33 changed files with 762 additions and 1342 deletions

View File

@ -57,26 +57,7 @@ set(BOBBYCAR_BUILDFLAGS
-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

View File

@ -57,26 +57,7 @@ set(BOBBYCAR_BUILDFLAGS
-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

View File

@ -48,18 +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

View File

@ -48,14 +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

View File

@ -48,14 +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

View File

@ -57,26 +57,7 @@ set(BOBBYCAR_BUILDFLAGS
-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

View File

@ -48,18 +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

View File

@ -11,7 +11,6 @@ set(headers
bobbycheckbox.h
bobbyerrorhandler.h
buildserver.h
buttons.h
can.h
changevaluedisplay_bluetoothmode.h
changevaluedisplay_controlmode.h
@ -228,7 +227,6 @@ set(headers
modes/tempomatmode.h
texthelpers/networktexthelpers.h
texthelpers/wifiaptexthelpers.h
texthelpers/wifistaconfigtexthelpers.h
texthelpers/wifistatexthelpers.h
widgets/doubleprogressbar.h
)
@ -244,7 +242,6 @@ set(sources
bobbybuttons.cpp
bobbyerrorhandler.cpp
buildserver.cpp
buttons.cpp
can.cpp
changevaluedisplay_bluetoothmode.cpp
changevaluedisplay_controlmode.cpp
@ -456,7 +453,6 @@ set(sources
modes/tempomatmode.cpp
texthelpers/networktexthelpers.cpp
texthelpers/wifiaptexthelpers.cpp
texthelpers/wifistaconfigtexthelpers.cpp
texthelpers/wifistatexthelpers.cpp
widgets/doubleprogressbar.cpp
)

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

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

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