Lock screen pin now configurable

This commit is contained in:
2021-09-18 16:17:27 +02:00
parent 444366c00c
commit cb0c02bc8f
16 changed files with 171 additions and 20 deletions

Submodule esp-idf updated: 9e9abdf483...0e76163859

View File

@ -71,6 +71,7 @@ set(headers
displays/menus/boardcomputerhardwaresettingsmenu.h
displays/menus/dynamicdebugmenu.h
displays/menus/limitssettingsmenu.h
displays/menus/lockscreensettingsmenu.h
displays/menus/mainmenu.h
displays/menus/motorfeedbackdebugmenu.h
displays/menus/wifiscanmenu.h

View File

@ -151,4 +151,8 @@ struct CenterOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t
struct SmallOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.smallOffset; } };
struct BigOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.bigOffset; } };
#endif
struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } };
template<uint8_t index>
struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings<int8_t> { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } };
}

View File

@ -1,5 +1,8 @@
#pragma once
// 3rdparty lib includes
#include <fmt/core.h>
// local includes
#include "textinterface.h"
#include "globals.h"
@ -20,21 +23,21 @@ using BluetoothHasClientText = BluetoothStatusTextHelper<TEXT_BLUETOOTHHASCLIENT
//using BluetoothConnectedText = BluetoothStatusTextHelper<TEXT_BLUETOOTHCONNECTED, bool, &BluetoothSerial::connected>;
struct BluetoothConnectedText : public virtual TextInterface {
public:
std::string text() const override { return std::string{"connected: "} + to_string(bluetoothSerial.connected()); }
std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHCONNECTED, to_string(bluetoothSerial.connected())); }
};
//constexpr char TEXT_BLUETOOTHISREADY[] = "Is ready: ";
//using BluetoothIsReadyText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADY, bool, &BluetoothSerial::isReady>;
struct BluetoothIsReadyText : public virtual TextInterface {
public:
std::string text() const override { return std::string{"isReady: "} + to_string(bluetoothSerial.isReady()); }
std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHISREADY, to_string(bluetoothSerial.isReady())); }
};
//constexpr char TEXT_BLUETOOTHISREADYMASTER[] = "Is ready (M): ";
//using BluetoothIsReadyMasterText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADYMASTER, bool, &BluetoothSerial::isReady>;
class BluetoothIsReadyMasterText : public virtual TextInterface {
public:
std::string text() const override { return std::string{"isReady (M): "} + to_string(bluetoothSerial.isReady(true)); }
std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHISREADYMASTER, to_string(bluetoothSerial.isReady(true))); }
};
#endif
}

View File

@ -19,6 +19,8 @@ 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;
@ -126,6 +128,9 @@ public:
if (!pressed)
return;
if (profileButtonDisabled)
return;
switchProfile(index);
}
};

View File

@ -1,13 +1,16 @@
#pragma once
// system includes
#include <array>
// local includes
#include "display.h"
#include "widgets/label.h"
#include "globals.h"
#include "utils.h"
#include "texts.h"
#include "modes/ignoreinputmode.h"
#include "buttons.h"
namespace {
class MainMenu;
@ -25,7 +28,7 @@ class Lockscreen : public Display, public DummyBack
public:
void start() override;
void initScreen() override;
void update() override {}
void update() override;
void redraw() override;
void stop() override;
@ -62,6 +65,8 @@ void Lockscreen::start()
m_oldMode = currentMode;
currentMode = &m_mode;
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
}
void Lockscreen::initScreen()
@ -95,6 +100,12 @@ void Lockscreen::initScreen()
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)
@ -104,7 +115,7 @@ void Lockscreen::redraw()
if (++m_currentIndex>=4)
{
if (m_numbers == decltype(m_numbers){1,2,3,4})
if (m_numbers == settings.lockscreen.pin)
{
switchScreen<MainMenu>();
return;
@ -150,6 +161,8 @@ void Lockscreen::stop()
currentMode = m_oldMode;
}
profileButtonDisabled = false;
}
void Lockscreen::confirm()

View File

@ -10,6 +10,7 @@
#include "actions/dummyaction.h"
#include "actions/switchscreenaction.h"
#include "actions/toggleboolaction.h"
#include "icons/lock.h"
#include "icons/back.h"
#include "checkboxicon.h"
#include "texts.h"
@ -18,6 +19,7 @@
// forward declares
namespace {
class BoardcomputerHardwareSettingsMenu;
class LockscreenSettingsMenu;
class CalibrateDisplay;
class GametrakCalibrateDisplay;
class TimersMenu;
@ -31,20 +33,20 @@ struct GasText : public virtual TextInterface {
public:
std::string text() const override
{
return std::string{"gas: "} +
(raw_gas ? std::to_string(*raw_gas) : "?") +
": " +
(gas ? fmt::format("{:.02f}", *gas) : "?");
return fmt::format("{}: {}: {}",
"gas",
raw_gas ? std::to_string(*raw_gas) : "?",
gas ? fmt::format("{:.02f}", *gas) : "?");
}
};
struct BremsText : public virtual TextInterface {
public:
std::string text() const override
{
return std::string{"brems: "} +
(raw_brems ? std::to_string(*raw_brems) : "?") +
": " +
(brems ? fmt::format("{:.02f}", *brems) : "?");
return fmt::format("{}: {}: {}",
"brems",
raw_brems ? std::to_string(*raw_brems) : "?",
brems ? fmt::format("{:.02f}", *brems) : "?");
}
};
@ -160,6 +162,7 @@ class BoardcomputerHardwareSettingsMenu :
public:
BoardcomputerHardwareSettingsMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LOCKSCREENSETTINGS>, SwitchScreenAction<LockscreenSettingsMenu>, StaticMenuItemIcon<&icons::lock>>>();
constructMenuItem<makeComponent<MenuItem, GasText, DisabledColor, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BremsText, DisabledColor, StaticFont<2>, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CALIBRATE>, SwitchScreenAction<CalibrateDisplay>>>();

View File

@ -0,0 +1,72 @@
#pragma once
// local includes
#include "menudisplay.h"
#include "menuitem.h"
#include "actions/toggleboolaction.h"
#include "actions/switchscreenaction.h"
#include "texts.h"
#include "icons/back.h"
#include "checkboxicon.h"
#include "globals.h"
#include "accessors/settingsaccessors.h"
#include "changevaluedisplay.h"
// forward declares
namespace {
class BoardcomputerHardwareSettingsMenu;
class LockscreenSettingsMenu;
} // namespace
using namespace espgui;
namespace {
using LockscreenPinDigit0ChangeScreen = makeComponent<
ChangeValueDisplay<int8_t>,
StaticText<TEXT_PINDIGIT0>,
LockscreenPinDigitAccessor<0>,
BackActionInterface<SwitchScreenAction<LockscreenSettingsMenu>>,
SwitchScreenAction<LockscreenSettingsMenu>
>;
using LockscreenPinDigit1ChangeScreen = makeComponent<
ChangeValueDisplay<int8_t>,
StaticText<TEXT_PINDIGIT1>,
LockscreenPinDigitAccessor<1>,
BackActionInterface<SwitchScreenAction<LockscreenSettingsMenu>>,
SwitchScreenAction<LockscreenSettingsMenu>
>;
using LockscreenPinDigit2ChangeScreen = makeComponent<
ChangeValueDisplay<int8_t>,
StaticText<TEXT_PINDIGIT2>,
LockscreenPinDigitAccessor<2>,
BackActionInterface<SwitchScreenAction<LockscreenSettingsMenu>>,
SwitchScreenAction<LockscreenSettingsMenu>
>;
using LockscreenPinDigit3ChangeScreen = makeComponent<
ChangeValueDisplay<int8_t>,
StaticText<TEXT_PINDIGIT3>,
LockscreenPinDigitAccessor<3>,
BackActionInterface<SwitchScreenAction<LockscreenSettingsMenu>>,
SwitchScreenAction<LockscreenSettingsMenu>
>;
class LockscreenSettingsMenu :
public MenuDisplay,
public StaticText<TEXT_LOCKSCREENSETTINGS>,
public BackActionInterface<SwitchScreenAction<BoardcomputerHardwareSettingsMenu>>
{
public:
LockscreenSettingsMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ALLOWPRESETSWITCH>, ToggleBoolAction, CheckboxIcon, LockscreenAllowPresetSwitchAccessor>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_PINDIGIT0, LockscreenPinDigitAccessor<0>>, SwitchScreenAction<LockscreenPinDigit0ChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_PINDIGIT1, LockscreenPinDigitAccessor<1>>, SwitchScreenAction<LockscreenPinDigit1ChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_PINDIGIT2, LockscreenPinDigitAccessor<2>>, SwitchScreenAction<LockscreenPinDigit2ChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_PINDIGIT3, LockscreenPinDigitAccessor<3>>, SwitchScreenAction<LockscreenPinDigit3ChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<BoardcomputerHardwareSettingsMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}
};
} // namespace

View File

@ -40,10 +40,10 @@ private:
};
StarfieldDisplay::StarfieldDisplay() :
za(cpputils::randomNumber<uint8_t>(256, espcpputils::esp_random_device{})),
zb(cpputils::randomNumber<uint8_t>(256, espcpputils::esp_random_device{})),
zc(cpputils::randomNumber<uint8_t>(256, espcpputils::esp_random_device{})),
zx(cpputils::randomNumber<uint8_t>(256, espcpputils::esp_random_device{}))
za(cpputils::randomNumber<uint8_t>(espcpputils::esp_random_device{})),
zb(cpputils::randomNumber<uint8_t>(espcpputils::esp_random_device{})),
zc(cpputils::randomNumber<uint8_t>(espcpputils::esp_random_device{})),
zx(cpputils::randomNumber<uint8_t>(espcpputils::esp_random_device{}))
{
}

View File

@ -56,6 +56,7 @@ using namespace std::chrono_literals;
#include "displays/menus/ledstripmenu.h"
#endif
#include "displays/menus/limitssettingsmenu.h"
#include "displays/menus/lockscreensettingsmenu.h"
#include "displays/menus/mainmenu.h"
#include "displays/menus/tempomatmodesettingsmenu.h"
#include "displays/menus/modessettingsmenu.h"

View File

@ -224,6 +224,11 @@ constexpr Settings::Ledstrip defaultLedstrip {
};
#endif
constexpr Settings::LockscreenSettings defaultLockscreen {
.allowPresetSwitch = true,
.pin = { 1, 2, 3, 4 }
};
constexpr Settings defaultSettings {
#ifdef FEATURE_BMS
.autoConnectBms = false,
@ -249,6 +254,7 @@ constexpr Settings defaultSettings {
#ifdef FEATURE_LEDSTRIP
.ledstrip = defaultLedstrip,
#endif
.lockscreen = defaultLockscreen
};
StringSettings makeDefaultStringSettings()

View File

@ -158,6 +158,11 @@ struct Settings
} ledstrip;
#endif
struct LockscreenSettings {
bool allowPresetSwitch;
std::array<int8_t, 4> pin;
} lockscreen;
template<typename T>
void executeForEveryCommonSetting(T &&callable);
@ -248,6 +253,9 @@ void Settings::executeForEveryCommonSetting(T &&callable)
callable("smallOffset", ledstrip.smallOffset);
callable("bigOffset", ledstrip.bigOffset);
#endif
callable("lockAlwPresetSw", lockscreen.allowPresetSwitch);
callable("lockscreenPin", lockscreen.pin);
}
template<typename T>

View File

@ -17,6 +17,7 @@
#include <fmt/core.h>
#include <cpputils.h>
#include <espchrono.h>
#include <futurecpp.h>
// local includes
#include "settings.h"
@ -276,6 +277,22 @@ template<> struct nvsGetterHelper<sntp_sync_mode_t> { static esp_err_t nvs_get(n
return err;
}};
#endif
template<> struct nvsGetterHelper<std::array<int8_t, 4>> { static esp_err_t nvs_get(nvs_handle handle, const char* key, std::array<int8_t, 4>* out_value)
{
uint32_t tempValue;
esp_err_t err = nvs_get_u32(handle, key, &tempValue);
if (err == ESP_OK)
*out_value = std::bit_cast<std::array<int8_t, 4>>(tempValue);
return err;
}};
template<> struct nvsGetterHelper<std::array<uint8_t, 4>> { static esp_err_t nvs_get(nvs_handle handle, const char* key, std::array<uint8_t, 4>* out_value)
{
uint32_t tempValue;
esp_err_t err = nvs_get_u32(handle, key, &tempValue);
if (err == ESP_OK)
*out_value = std::bit_cast<std::array<uint8_t, 4>>(tempValue);
return err;
}};
template<typename T>
bool SettingsPersister::load(T &settings)
@ -385,6 +402,14 @@ template<> struct nvsSetterHelper<sntp_sync_mode_t> { static esp_err_t nvs_set(n
return nvs_set_u8(handle, key, uint8_t(value));
}};
#endif
template<> struct nvsSetterHelper<std::array<int8_t, 4>> { static esp_err_t nvs_set(nvs_handle handle, const char* key, std::array<int8_t, 4> value)
{
return nvs_set_u32(handle, key, std::bit_cast<uint32_t>(value));
}};
template<> struct nvsSetterHelper<std::array<uint8_t, 4>> { static esp_err_t nvs_set(nvs_handle handle, const char* key, std::array<uint8_t, 4> value)
{
return nvs_set_u32(handle, key, std::bit_cast<uint32_t>(value));
}};
template<typename T>
bool SettingsPersister::save(T &settings)

View File

@ -243,6 +243,15 @@ constexpr char TEXT_SMALLOFFSET[] = "Small Offset";
constexpr char TEXT_BIGOFFSET[] = "Big Offset";
//constexpr char TEXT_BACK[] = "Back";
//LockscreenSettingsMenu
constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings";
constexpr char TEXT_ALLOWPRESETSWITCH[] = "Allow preset switch";
constexpr char TEXT_PINDIGIT0[] = "PIN digit0";
constexpr char TEXT_PINDIGIT1[] = "PIN digit1";
constexpr char TEXT_PINDIGIT2[] = "PIN digit2";
constexpr char TEXT_PINDIGIT3[] = "PIN digit3";
//constexpr char TEXT_BACK[] = "Back";
//ModesSettingsMenu
//constexpr char TEXT_MODESSETTINGS[] = "Modes settings";
constexpr char TEXT_DEFAULTMODESETTIGNS[] = "Default mode settings";
@ -271,6 +280,7 @@ constexpr char TEXT_NCRUISEMOTTGT[] = "nCruiseMotTgt";
//BoardcomputerHardwareSettingsMenu
//constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings";
//constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings";
constexpr char TEXT_CALIBRATE[] = "Calibrate";
constexpr char TEXT_SAMPLECOUNT[] = "sampleCount";
constexpr char TEXT_GASMIN[] = "gasMin";