Refactorings again more
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
#include "rebootaction.h"
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_system.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <tftinstance.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "globals.h"
|
||||||
|
#include "texts.h"
|
||||||
|
|
||||||
|
void RebootAction::triggered()
|
||||||
|
{
|
||||||
|
espgui::tft.fillScreen(TFT_BLACK);
|
||||||
|
espgui::tft.setTextColor(TFT_YELLOW);
|
||||||
|
|
||||||
|
espgui::tft.drawString(TEXT_REBOOT, 5, 5, 4);
|
||||||
|
|
||||||
|
espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE);
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE);
|
||||||
|
espgui::tft.drawString("Rebooting now...", 0, 50, 4);
|
||||||
|
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
@@ -1,30 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <esp_system.h>
|
// 3rdparty lib includes
|
||||||
|
|
||||||
#include "actioninterface.h"
|
#include "actioninterface.h"
|
||||||
#include "globals.h"
|
|
||||||
#include "texts.h"
|
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
namespace {
|
class RebootAction : public virtual espgui::ActionInterface
|
||||||
class RebootAction : public virtual ActionInterface
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void triggered() override
|
void triggered() override;
|
||||||
{
|
|
||||||
tft.fillScreen(TFT_BLACK);
|
|
||||||
tft.setTextColor(TFT_YELLOW);
|
|
||||||
|
|
||||||
tft.drawString(TEXT_REBOOT, 5, 5, 4);
|
|
||||||
|
|
||||||
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
|
|
||||||
|
|
||||||
tft.setTextColor(TFT_WHITE);
|
|
||||||
tft.drawString("Rebooting now...", 0, 50, 4);
|
|
||||||
|
|
||||||
esp_restart();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
#include "changevaluedisplay_unifiedmodelmode.h"
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "utils.h"
|
||||||
|
#include "texts.h"
|
||||||
|
|
||||||
|
namespace espgui {
|
||||||
|
ChangeValueDisplay<UnifiedModelMode>::ChangeValueDisplay()
|
||||||
|
{
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_COMMUTATION>>>(UnifiedModelMode::Commutation, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_SINUSOIDAL>>>(UnifiedModelMode::Sinusoidal, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCVOLTAGE>>>(UnifiedModelMode::FocVoltage, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCSPEED>>>(UnifiedModelMode::FocSpeed, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCTORQUE>>>(UnifiedModelMode::FocTorque, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeValueDisplay<UnifiedModelMode>::start()
|
||||||
|
{
|
||||||
|
Base::start();
|
||||||
|
|
||||||
|
switch (const auto value = getValue())
|
||||||
|
{
|
||||||
|
case UnifiedModelMode::Commutation: setSelectedIndex(0); break;
|
||||||
|
case UnifiedModelMode::Sinusoidal: setSelectedIndex(1); break;
|
||||||
|
case UnifiedModelMode::FocVoltage: setSelectedIndex(2); break;
|
||||||
|
case UnifiedModelMode::FocSpeed: setSelectedIndex(3); break;
|
||||||
|
case UnifiedModelMode::FocTorque: setSelectedIndex(4); break;
|
||||||
|
default:
|
||||||
|
ESP_LOGW("BOBBY", "Unknown UnifiedModelMode: %i", int(value));
|
||||||
|
setSelectedIndex(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace espgui
|
||||||
|
@@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <esp_log.h>
|
// 3rdparty lib includes
|
||||||
|
|
||||||
#include "changevaluedisplay.h"
|
#include "changevaluedisplay.h"
|
||||||
#include "menudisplay.h"
|
#include "menudisplay.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "actions/setvalueaction.h"
|
#include "actions/setvalueaction.h"
|
||||||
#include "actions/backproxyaction.h"
|
#include "actions/backproxyaction.h"
|
||||||
#include "icons/back.h"
|
#include "icons/back.h"
|
||||||
#include "texts.h"
|
|
||||||
|
// local includes
|
||||||
#include "unifiedmodelmode.h"
|
#include "unifiedmodelmode.h"
|
||||||
|
|
||||||
namespace espgui {
|
namespace espgui {
|
||||||
@@ -25,31 +24,4 @@ public:
|
|||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
ChangeValueDisplay<UnifiedModelMode>::ChangeValueDisplay()
|
|
||||||
{
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_COMMUTATION>>>(UnifiedModelMode::Commutation, *this, *this);
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_SINUSOIDAL>>>(UnifiedModelMode::Sinusoidal, *this, *this);
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCVOLTAGE>>>(UnifiedModelMode::FocVoltage, *this, *this);
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCSPEED>>>(UnifiedModelMode::FocSpeed, *this, *this);
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<UnifiedModelMode>, StaticText<TEXT_FOCTORQUE>>>(UnifiedModelMode::FocTorque, *this, *this);
|
|
||||||
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&espgui::icons::back>>>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeValueDisplay<UnifiedModelMode>::start()
|
|
||||||
{
|
|
||||||
Base::start();
|
|
||||||
|
|
||||||
switch (const auto value = getValue())
|
|
||||||
{
|
|
||||||
case UnifiedModelMode::Commutation: setSelectedIndex(0); break;
|
|
||||||
case UnifiedModelMode::Sinusoidal: setSelectedIndex(1); break;
|
|
||||||
case UnifiedModelMode::FocVoltage: setSelectedIndex(2); break;
|
|
||||||
case UnifiedModelMode::FocSpeed: setSelectedIndex(3); break;
|
|
||||||
case UnifiedModelMode::FocTorque: setSelectedIndex(4); break;
|
|
||||||
default:
|
|
||||||
ESP_LOGW("BOBBY", "Unknown UnifiedModelMode: %i", int(value));
|
|
||||||
setSelectedIndex(5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace espgui
|
} // namespace espgui
|
||||||
|
@@ -0,0 +1,50 @@
|
|||||||
|
#include "garagedisplay.h"
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <tftinstance.h>
|
||||||
|
#include <screenmanager.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "texts.h"
|
||||||
|
|
||||||
|
#ifdef FEATURE_GARAGE
|
||||||
|
void GarageDisplay::start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GarageDisplay::initScreen()
|
||||||
|
{
|
||||||
|
espgui::tft.fillScreen(TFT_BLACK);
|
||||||
|
espgui::tft.setTextFont(4);
|
||||||
|
espgui::tft.setTextColor(TFT_YELLOW);
|
||||||
|
|
||||||
|
espgui::tft.drawString(TEXT_GARAGE, 5, 5, 4);
|
||||||
|
|
||||||
|
espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE);
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
|
||||||
|
espgui::tft.drawString("Garage", 20, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GarageDisplay::redraw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GarageDisplay::confirm()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GarageDisplay::back()
|
||||||
|
{
|
||||||
|
espgui::switchScreen<MainMenu>();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@@ -1,58 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// system includes
|
|
||||||
|
|
||||||
// esp-idf includes
|
|
||||||
#include <esp_log.h>
|
|
||||||
|
|
||||||
// 3rdparty lib includes
|
|
||||||
#include <fmt/core.h>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "actions/switchscreenaction.h"
|
|
||||||
#include "globals.h"
|
|
||||||
#include "texts.h"
|
|
||||||
#include "widgets/label.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
#ifdef FEATURE_GARAGE
|
#ifdef FEATURE_GARAGE
|
||||||
class GarageDisplay : public Display, public BackActionInterface<SwitchScreenAction<MainMenu>>
|
class GarageDisplay : public espgui::Display
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void start() override;
|
void start() override;
|
||||||
void initScreen() override;
|
void initScreen() override;
|
||||||
void redraw() override;
|
void redraw() override;
|
||||||
void confirm() override;
|
void confirm() override;
|
||||||
|
void back() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void GarageDisplay::start()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GarageDisplay::initScreen()
|
|
||||||
{
|
|
||||||
tft.fillScreen(TFT_BLACK);
|
|
||||||
tft.setTextFont(4);
|
|
||||||
tft.setTextColor(TFT_YELLOW);
|
|
||||||
|
|
||||||
tft.drawString(TEXT_GARAGE, 5, 5, 4);
|
|
||||||
|
|
||||||
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
|
|
||||||
|
|
||||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
|
||||||
|
|
||||||
tft.drawString("Garage", 20, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GarageDisplay::redraw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GarageDisplay::confirm()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
@@ -0,0 +1,144 @@
|
|||||||
|
#include "lockscreen.h"
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <tftinstance.h>
|
||||||
|
#include <screenmanager.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "globals.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "texts.h"
|
||||||
|
#include "buttons.h"
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
|
||||||
|
void Lockscreen::start()
|
||||||
|
{
|
||||||
|
m_numbers = {0,0,0,0};
|
||||||
|
m_currentIndex = 0;
|
||||||
|
m_pressed = false;
|
||||||
|
m_rotated = 0;
|
||||||
|
|
||||||
|
m_oldMode = currentMode;
|
||||||
|
currentMode = &m_mode;
|
||||||
|
|
||||||
|
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::initScreen()
|
||||||
|
{
|
||||||
|
espgui::tft.fillScreen(TFT_BLACK);
|
||||||
|
espgui::tft.setTextFont(4);
|
||||||
|
espgui::tft.setTextColor(TFT_YELLOW);
|
||||||
|
|
||||||
|
espgui::tft.drawString(TEXT_LOCKVEHICLE, 5, 5);
|
||||||
|
|
||||||
|
espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE);
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE);
|
||||||
|
espgui::tft.drawString("Enter code to unlock:", 0, 50);
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
|
||||||
|
for(int i = 0; i <= 3; i++)
|
||||||
|
{
|
||||||
|
drawRect(i, 3, TFT_WHITE);
|
||||||
|
drawRect(i, 4, TFT_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &label : m_labels)
|
||||||
|
label.start();
|
||||||
|
|
||||||
|
espgui::tft.setTextFont(7);
|
||||||
|
|
||||||
|
drawRect(0, 1, TFT_YELLOW);
|
||||||
|
drawRect(0, 2, TFT_YELLOW);
|
||||||
|
m_labels[0].redraw(std::to_string(m_numbers[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::update()
|
||||||
|
{
|
||||||
|
// just in case someone changes that settings somehow
|
||||||
|
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::redraw()
|
||||||
|
{
|
||||||
|
if (m_pressed)
|
||||||
|
{
|
||||||
|
drawRect(m_currentIndex, 1, TFT_BLACK);
|
||||||
|
drawRect(m_currentIndex, 2, TFT_BLACK);
|
||||||
|
|
||||||
|
if (++m_currentIndex>=4)
|
||||||
|
{
|
||||||
|
if (m_numbers == settings.lockscreen.pin)
|
||||||
|
{
|
||||||
|
espgui::switchScreen<MainMenu>();
|
||||||
|
#ifdef LOCKSCREEN_PLUGIN
|
||||||
|
#pragma message "Activating Lockscreen Plugin"
|
||||||
|
#include LOCKSCREEN_PLUGIN
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_numbers = {0,0,0,0};
|
||||||
|
m_currentIndex = 0;
|
||||||
|
std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); });
|
||||||
|
}
|
||||||
|
|
||||||
|
m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
|
||||||
|
|
||||||
|
drawRect(m_currentIndex, 1, TFT_YELLOW);
|
||||||
|
drawRect(m_currentIndex, 2, TFT_YELLOW);
|
||||||
|
|
||||||
|
m_pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_rotated)
|
||||||
|
{
|
||||||
|
m_numbers[m_currentIndex] -= m_rotated;
|
||||||
|
|
||||||
|
if (m_numbers[m_currentIndex] < 0)
|
||||||
|
m_numbers[m_currentIndex]+=10;
|
||||||
|
else if (m_numbers[m_currentIndex] > 9)
|
||||||
|
m_numbers[m_currentIndex]-=10;
|
||||||
|
|
||||||
|
m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
|
||||||
|
|
||||||
|
m_rotated = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::stop()
|
||||||
|
{
|
||||||
|
Base::stop();
|
||||||
|
|
||||||
|
if (currentMode == &m_mode)
|
||||||
|
{
|
||||||
|
// to avoid crash after deconstruction
|
||||||
|
m_mode.stop();
|
||||||
|
lastMode = nullptr;
|
||||||
|
|
||||||
|
currentMode = m_oldMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
profileButtonDisabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::confirm()
|
||||||
|
{
|
||||||
|
m_pressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::back()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::rotate(int offset)
|
||||||
|
{
|
||||||
|
m_rotated += offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lockscreen::drawRect(int index, int offset, uint32_t color) const
|
||||||
|
{
|
||||||
|
espgui::tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color);
|
||||||
|
}
|
||||||
|
@@ -6,20 +6,15 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "widgets/label.h"
|
#include "widgets/label.h"
|
||||||
#include "globals.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "texts.h"
|
|
||||||
#include "modes/ignoreinputmode.h"
|
#include "modes/ignoreinputmode.h"
|
||||||
#include "buttons.h"
|
|
||||||
|
|
||||||
#ifdef LOCKSCREEN_PLUGIN
|
#ifdef LOCKSCREEN_PLUGIN
|
||||||
#include "ledstrip.h"
|
#include "ledstrip.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
class Lockscreen : public espgui::Display
|
||||||
class Lockscreen : public Display, public DummyBack
|
|
||||||
{
|
{
|
||||||
using Base = Display;
|
using Base = espgui::Display;
|
||||||
|
|
||||||
static constexpr auto boxWidth = 35;
|
static constexpr auto boxWidth = 35;
|
||||||
static constexpr auto boxHeight = 50;
|
static constexpr auto boxHeight = 50;
|
||||||
@@ -33,16 +28,17 @@ public:
|
|||||||
void stop() override;
|
void stop() override;
|
||||||
|
|
||||||
void confirm() override;
|
void confirm() override;
|
||||||
|
void back() override;
|
||||||
void rotate(int offset) override;
|
void rotate(int offset) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawRect(int index, int offset, uint32_t color) const;
|
void drawRect(int index, int offset, uint32_t color) const;
|
||||||
|
|
||||||
std::array<Label, 4> m_labels {{
|
std::array<espgui::Label, 4> m_labels {{
|
||||||
Label{spacing, 100}, // boxWidth, boxHeight
|
espgui::Label{spacing, 100}, // boxWidth, boxHeight
|
||||||
Label{spacing*2+boxWidth, 100}, // boxWidth, boxHeight
|
espgui::Label{spacing*2+boxWidth, 100}, // boxWidth, boxHeight
|
||||||
Label{spacing*3+boxWidth*2, 100}, // boxWidth, boxHeight
|
espgui::Label{spacing*3+boxWidth*2, 100}, // boxWidth, boxHeight
|
||||||
Label{spacing*4+boxWidth*3, 100} // boxWidth, boxHeight
|
espgui::Label{spacing*4+boxWidth*3, 100} // boxWidth, boxHeight
|
||||||
}};
|
}};
|
||||||
|
|
||||||
std::array<int8_t, 4> m_numbers;
|
std::array<int8_t, 4> m_numbers;
|
||||||
@@ -55,132 +51,3 @@ private:
|
|||||||
ModeInterface *m_oldMode;
|
ModeInterface *m_oldMode;
|
||||||
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Speed};
|
IgnoreInputMode m_mode{0, bobbycar::protocol::ControlType::FieldOrientedControl, bobbycar::protocol::ControlMode::Speed};
|
||||||
};
|
};
|
||||||
|
|
||||||
void Lockscreen::start()
|
|
||||||
{
|
|
||||||
m_numbers = {0,0,0,0};
|
|
||||||
m_currentIndex = 0;
|
|
||||||
m_pressed = false;
|
|
||||||
m_rotated = 0;
|
|
||||||
|
|
||||||
m_oldMode = currentMode;
|
|
||||||
currentMode = &m_mode;
|
|
||||||
|
|
||||||
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::initScreen()
|
|
||||||
{
|
|
||||||
tft.fillScreen(TFT_BLACK);
|
|
||||||
tft.setTextFont(4);
|
|
||||||
tft.setTextColor(TFT_YELLOW);
|
|
||||||
|
|
||||||
tft.drawString(TEXT_LOCKVEHICLE, 5, 5);
|
|
||||||
|
|
||||||
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
|
|
||||||
|
|
||||||
tft.setTextColor(TFT_WHITE);
|
|
||||||
tft.drawString("Enter code to unlock:", 0, 50);
|
|
||||||
|
|
||||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
|
||||||
|
|
||||||
for(int i = 0; i <= 3; i++)
|
|
||||||
{
|
|
||||||
drawRect(i, 3, TFT_WHITE);
|
|
||||||
drawRect(i, 4, TFT_WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &label : m_labels)
|
|
||||||
label.start();
|
|
||||||
|
|
||||||
tft.setTextFont(7);
|
|
||||||
|
|
||||||
drawRect(0, 1, TFT_YELLOW);
|
|
||||||
drawRect(0, 2, TFT_YELLOW);
|
|
||||||
m_labels[0].redraw(std::to_string(m_numbers[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::update()
|
|
||||||
{
|
|
||||||
// just in case someone changes that settings somehow
|
|
||||||
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::redraw()
|
|
||||||
{
|
|
||||||
if (m_pressed)
|
|
||||||
{
|
|
||||||
drawRect(m_currentIndex, 1, TFT_BLACK);
|
|
||||||
drawRect(m_currentIndex, 2, TFT_BLACK);
|
|
||||||
|
|
||||||
if (++m_currentIndex>=4)
|
|
||||||
{
|
|
||||||
if (m_numbers == settings.lockscreen.pin)
|
|
||||||
{
|
|
||||||
switchScreen<MainMenu>();
|
|
||||||
#ifdef LOCKSCREEN_PLUGIN
|
|
||||||
#pragma message "Activating Lockscreen Plugin"
|
|
||||||
#include LOCKSCREEN_PLUGIN
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_numbers = {0,0,0,0};
|
|
||||||
m_currentIndex = 0;
|
|
||||||
std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); });
|
|
||||||
}
|
|
||||||
|
|
||||||
m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
|
|
||||||
|
|
||||||
drawRect(m_currentIndex, 1, TFT_YELLOW);
|
|
||||||
drawRect(m_currentIndex, 2, TFT_YELLOW);
|
|
||||||
|
|
||||||
m_pressed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_rotated)
|
|
||||||
{
|
|
||||||
m_numbers[m_currentIndex] -= m_rotated;
|
|
||||||
|
|
||||||
if (m_numbers[m_currentIndex] < 0)
|
|
||||||
m_numbers[m_currentIndex]+=10;
|
|
||||||
else if (m_numbers[m_currentIndex] > 9)
|
|
||||||
m_numbers[m_currentIndex]-=10;
|
|
||||||
|
|
||||||
m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
|
|
||||||
|
|
||||||
m_rotated = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::stop()
|
|
||||||
{
|
|
||||||
Base::stop();
|
|
||||||
|
|
||||||
if (currentMode == &m_mode)
|
|
||||||
{
|
|
||||||
// to avoid crash after deconstruction
|
|
||||||
m_mode.stop();
|
|
||||||
lastMode = nullptr;
|
|
||||||
|
|
||||||
currentMode = m_oldMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
profileButtonDisabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::confirm()
|
|
||||||
{
|
|
||||||
m_pressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::rotate(int offset)
|
|
||||||
{
|
|
||||||
m_rotated += offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lockscreen::drawRect(int index, int offset, uint32_t color) const
|
|
||||||
{
|
|
||||||
tft.drawRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
#include "poweroffdisplay.h"
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <tftinstance.h>
|
||||||
|
#include <screenmanager.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "utils.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "texts.h"
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
void PoweroffDisplay::start()
|
||||||
|
{
|
||||||
|
m_startTime = espchrono::millis_clock::now();
|
||||||
|
|
||||||
|
for (Controller &controller : controllers)
|
||||||
|
controller.command.poweroff = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoweroffDisplay::initScreen()
|
||||||
|
{
|
||||||
|
espgui::tft.fillScreen(TFT_BLACK);
|
||||||
|
espgui::tft.setTextColor(TFT_YELLOW);
|
||||||
|
|
||||||
|
espgui::tft.drawString(TEXT_POWEROFF, 5, 5, 4);
|
||||||
|
|
||||||
|
espgui::tft.fillRect(0, 34, espgui::tft.width(), 3, TFT_WHITE);
|
||||||
|
|
||||||
|
espgui::tft.setTextColor(TFT_WHITE);
|
||||||
|
espgui::tft.drawString("Trying to turn off", 15, 50, 4);
|
||||||
|
espgui::tft.drawString("both controllers", 25, 75, 4);
|
||||||
|
espgui::tft.drawString("Please stand still...", 20, 125, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoweroffDisplay::update()
|
||||||
|
{
|
||||||
|
if (espchrono::millis_clock::now() - m_startTime >= 1000ms)
|
||||||
|
espgui::switchScreen<MainMenu>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoweroffDisplay::stop()
|
||||||
|
{
|
||||||
|
for (Controller &controller : controllers)
|
||||||
|
controller.command.poweroff = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoweroffDisplay::confirm()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoweroffDisplay::back()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@@ -5,56 +5,19 @@
|
|||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "globals.h"
|
|
||||||
#include "texts.h"
|
|
||||||
|
|
||||||
namespace {
|
class PoweroffDisplay : public espgui::Display
|
||||||
class PoweroffDisplay : public Display, public DummyConfirm, public DummyBack
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void start() override;
|
void start() override;
|
||||||
void initScreen() override;
|
void initScreen() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void redraw() override {};
|
void redraw() override {}
|
||||||
void stop() override;
|
void stop() override;
|
||||||
|
|
||||||
|
void confirm() override;
|
||||||
|
void back() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
espchrono::millis_clock::time_point m_startTime;
|
espchrono::millis_clock::time_point m_startTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
void PoweroffDisplay::start()
|
|
||||||
{
|
|
||||||
m_startTime = espchrono::millis_clock::now();
|
|
||||||
|
|
||||||
for (Controller &controller : controllers)
|
|
||||||
controller.command.poweroff = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PoweroffDisplay::initScreen()
|
|
||||||
{
|
|
||||||
tft.fillScreen(TFT_BLACK);
|
|
||||||
tft.setTextColor(TFT_YELLOW);
|
|
||||||
|
|
||||||
tft.drawString(TEXT_POWEROFF, 5, 5, 4);
|
|
||||||
|
|
||||||
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
|
|
||||||
|
|
||||||
tft.setTextColor(TFT_WHITE);
|
|
||||||
tft.drawString("Trying to turn off", 15, 50, 4);
|
|
||||||
tft.drawString("both controllers", 25, 75, 4);
|
|
||||||
tft.drawString("Please stand still...", 20, 125, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PoweroffDisplay::update()
|
|
||||||
{
|
|
||||||
if (espchrono::millis_clock::now() - m_startTime >= 1000ms)
|
|
||||||
switchScreen<MainMenu>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PoweroffDisplay::stop()
|
|
||||||
{
|
|
||||||
for (Controller &controller : controllers)
|
|
||||||
controller.command.poweroff = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -7,8 +7,8 @@
|
|||||||
#include <espwifistack.h>
|
#include <espwifistack.h>
|
||||||
|
|
||||||
#ifdef FEATURE_OTA
|
#ifdef FEATURE_OTA
|
||||||
extern cpputils::DelayedConstruction<EspAsyncOta> asyncOta;
|
cpputils::DelayedConstruction<EspAsyncOta> asyncOta;
|
||||||
extern bool asyncOtaTaskStarted;
|
bool asyncOtaTaskStarted{};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr const char * const TAG = "BOBBYOTA";
|
constexpr const char * const TAG = "BOBBYOTA";
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
// local includes
|
// local includes
|
||||||
|
|
||||||
#ifdef FEATURE_OTA
|
#ifdef FEATURE_OTA
|
||||||
cpputils::DelayedConstruction<EspAsyncOta> asyncOta;
|
extern cpputils::DelayedConstruction<EspAsyncOta> asyncOta;
|
||||||
bool asyncOtaTaskStarted{};
|
extern bool asyncOtaTaskStarted;
|
||||||
|
|
||||||
void initOta();
|
void initOta();
|
||||||
void handleOta();
|
void handleOta();
|
||||||
|
Reference in New Issue
Block a user