Moved settings.lockscreen
This commit is contained in:
@ -216,10 +216,10 @@ struct BatteryWHperKMAccessor : public NewSettingsAccessor<uint16_t> { ConfigWra
|
||||
struct BatteryApplyCalibrationAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.battery.applyCalibration; } };
|
||||
|
||||
// Lockscreen
|
||||
struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } };
|
||||
struct LockscreenAllowPresetSwitchAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.lockscreen.allowPresetSwitch; } };
|
||||
template<uint8_t index>
|
||||
struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings<int8_t> { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } };
|
||||
struct LockscreenKeepLockedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.keepLockedAfterReboot; } };
|
||||
struct LockscreenPinDigitAccessor : public NewSettingsAccessor<int8_t> { ConfigWrapper<int8_t> &getConfig() const override { return configs.lockscreen.pin[index].digit; } };
|
||||
struct LockscreenKeepLockedAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.lockscreen.keepLockedAfterReboot; } };
|
||||
|
||||
// Handbremse
|
||||
struct HandbremsEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.handbremse.enable; } };
|
||||
|
@ -14,6 +14,18 @@
|
||||
#include "ledstripdefines.h"
|
||||
#endif
|
||||
|
||||
bool isValidPin(std::array<int8_t,4> enteredPin)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (enteredPin[i] != configs.lockscreen.pin[i].digit.value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Lockscreen::start()
|
||||
{
|
||||
Base::start();
|
||||
@ -27,10 +39,9 @@ void Lockscreen::start()
|
||||
currentMode = &m_mode;
|
||||
|
||||
isLocked = true;
|
||||
if (settings.lockscreen.keepLockedAfterReboot && !settings.lockscreen.locked)
|
||||
if (configs.lockscreen.keepLockedAfterReboot.value && !configs.lockscreen.locked.value)
|
||||
{
|
||||
settings.lockscreen.locked = true;
|
||||
saveSettings();
|
||||
configs.write_config(configs.lockscreen.locked, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +96,7 @@ void Lockscreen::redraw()
|
||||
|
||||
if (!m_back_pressed && ++m_currentIndex>=4)
|
||||
{
|
||||
if (m_numbers == settings.lockscreen.pin)
|
||||
if (isValidPin(m_numbers))
|
||||
{
|
||||
if (!gas || !brems || *gas > 200.f || *brems > 200.f)
|
||||
espgui::switchScreen<PotisCalibrateDisplay>(true);
|
||||
@ -148,17 +159,16 @@ void Lockscreen::stop()
|
||||
isLocked = false;
|
||||
if (!(!gas || !brems || *gas > 200.f || *brems > 200.f))
|
||||
{
|
||||
if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked)
|
||||
if (configs.lockscreen.keepLockedAfterReboot.value && configs.lockscreen.locked.value)
|
||||
{
|
||||
settings.lockscreen.locked = false;
|
||||
saveSettings();
|
||||
configs.write_config(configs.lockscreen.locked, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Lockscreen::buttonPressed(espgui::Button button)
|
||||
{
|
||||
if (settings.lockscreen.allowPresetSwitch ||
|
||||
if (configs.lockscreen.allowPresetSwitch.value ||
|
||||
!cpputils::is_in(button, BobbyButton::Profile0, BobbyButton::Profile1, BobbyButton::Profile2, BobbyButton::Profile3))
|
||||
Base::buttonPressed(button);
|
||||
|
||||
|
@ -198,11 +198,10 @@ void PotisCalibrateDisplay::buttonPressed(espgui::Button button)
|
||||
case Status::Begin:
|
||||
if (m_bootup)
|
||||
espgui::switchScreen<StatusDisplay>();
|
||||
else if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked)
|
||||
else if (configs.lockscreen.keepLockedAfterReboot.value && configs.lockscreen.locked.value)
|
||||
{
|
||||
espgui::switchScreen<MainMenu>();
|
||||
settings.lockscreen.locked = false;
|
||||
saveSettings();
|
||||
configs.write_config(configs.lockscreen.locked, false);
|
||||
}
|
||||
else
|
||||
espgui::switchScreen<BoardcomputerHardwareSettingsMenu>();
|
||||
|
@ -79,7 +79,7 @@ extern "C" void app_main()
|
||||
{
|
||||
espgui::switchScreen<ButtonCalibrateDisplay>(true);
|
||||
}
|
||||
else if (settings.lockscreen.keepLockedAfterReboot && settings.lockscreen.locked)
|
||||
else if (configs.lockscreen.keepLockedAfterReboot.value && configs.lockscreen.locked.value)
|
||||
{
|
||||
espgui::switchScreen<Lockscreen>();
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
// local includes
|
||||
#include "ledstrip.h"
|
||||
#include "unifiedmodelmode.h"
|
||||
#include "displays/lockscreen.h"
|
||||
|
||||
using namespace espconfig;
|
||||
|
||||
@ -83,6 +85,15 @@ public:
|
||||
ConfigWrapper<std::string> url;
|
||||
};
|
||||
|
||||
class ConfiguredLockscreenDigit
|
||||
{
|
||||
public:
|
||||
ConfiguredLockscreenDigit(const char *digitKey) :
|
||||
digit{0, DoReset, MinMaxOrZeroValue<int8_t, 1,9>, digitKey }
|
||||
{}
|
||||
ConfigWrapper<int8_t> digit;
|
||||
};
|
||||
|
||||
class ConfigContainer
|
||||
{
|
||||
using mac_t = wifi_stack::mac_t;
|
||||
@ -248,7 +259,18 @@ public:
|
||||
ConfigWrapper<int16_t> back50VoltCalibration {5000, DoReset, {}, "batB50VCal" };
|
||||
ConfigWrapper<bool> applyCalibration {true, DoReset, {}, "applyBatCal" };
|
||||
} battery;
|
||||
// end old settings
|
||||
|
||||
struct {
|
||||
ConfigWrapper<bool> allowPresetSwitch {true, DoReset, {}, "lockAlwPresetSw" };
|
||||
ConfigWrapper<bool> keepLockedAfterReboot {false, DoReset, {}, "keepLocked" };
|
||||
ConfigWrapper<bool> locked {false, DoReset, {}, "currentlyLocked" };
|
||||
std::array<ConfiguredLockscreenDigit, 4> pin {
|
||||
ConfiguredLockscreenDigit {"lockscreenPin0"},
|
||||
ConfiguredLockscreenDigit {"lockscreenPin1"},
|
||||
ConfiguredLockscreenDigit {"lockscreenPin2"},
|
||||
ConfiguredLockscreenDigit {"lockscreenPin3"}
|
||||
};
|
||||
} lockscreen;
|
||||
|
||||
struct {
|
||||
ConfigWrapper<bool> bleEnabled {true, DoReset, {}, "bleEnabled" };
|
||||
@ -496,7 +518,15 @@ public:
|
||||
x(battery.back30VoltCalibration) \
|
||||
x(battery.front50VoltCalibration) \
|
||||
x(battery.back50VoltCalibration) \
|
||||
x(battery.applyCalibration)
|
||||
x(battery.applyCalibration) \
|
||||
\
|
||||
x(lockscreen.allowPresetSwitch) \
|
||||
x(lockscreen.keepLockedAfterReboot) \
|
||||
x(lockscreen.locked) \
|
||||
x(lockscreen.pin[0].digit) \
|
||||
x(lockscreen.pin[1].digit) \
|
||||
x(lockscreen.pin[2].digit) \
|
||||
x(lockscreen.pin[3].digit)
|
||||
//x(bleSettings.bleEnabled)
|
||||
|
||||
template<typename T>
|
||||
|
@ -130,13 +130,6 @@ constexpr Settings::Handbremse defaultHandbremse {
|
||||
.visualize = true,
|
||||
};
|
||||
|
||||
constexpr Settings::LockscreenSettings defaultLockscreen {
|
||||
.allowPresetSwitch = true,
|
||||
.keepLockedAfterReboot = false,
|
||||
.locked = false,
|
||||
.pin = { 1, 2, 3, 4 }
|
||||
};
|
||||
|
||||
constexpr Settings::Hybrid defaultHybrid {
|
||||
.hybridMode = UnifiedModelMode::FocTorque,
|
||||
.enable = false,
|
||||
@ -169,7 +162,6 @@ constexpr Settings defaultSettings {
|
||||
.larsmMode = defaultLarsmMode,
|
||||
.motortestMode = defaultMotortestMode,
|
||||
.hybrid = defaultHybrid,
|
||||
.lockscreen = defaultLockscreen,
|
||||
.savedStatistics = defaultSavedStatistics,
|
||||
.handbremse = defaultHandbremse,
|
||||
#ifdef FEATURE_ESPNOW
|
||||
|
@ -71,20 +71,13 @@ struct Settings
|
||||
uint16_t maxPwm; // profileSetting
|
||||
} motortestMode;
|
||||
|
||||
struct Hybrid {
|
||||
struct Hybrid { // wont convert
|
||||
UnifiedModelMode hybridMode;
|
||||
bool enable;
|
||||
int16_t activationLimit;
|
||||
int16_t deactivationLimit;
|
||||
} hybrid;
|
||||
|
||||
struct LockscreenSettings {
|
||||
bool allowPresetSwitch;
|
||||
bool keepLockedAfterReboot;
|
||||
bool locked;
|
||||
std::array<int8_t, 4> pin;
|
||||
} lockscreen;
|
||||
|
||||
struct SavedStatistics {
|
||||
uint32_t totalCentimeters;
|
||||
} savedStatistics;
|
||||
@ -119,11 +112,6 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
||||
callable("hybridAcL", hybrid.activationLimit);
|
||||
callable("hybridDeacL", hybrid.deactivationLimit);
|
||||
|
||||
callable("lockAlwPresetSw", lockscreen.allowPresetSwitch);
|
||||
callable("keepLocked", lockscreen.keepLockedAfterReboot);
|
||||
callable("currentlyLocked", lockscreen.locked);
|
||||
callable("lockscreenPin", lockscreen.pin);
|
||||
|
||||
callable("totalCentimeter", savedStatistics.totalCentimeters);
|
||||
|
||||
callable("handBremsE", handbremse.enable);
|
||||
|
Reference in New Issue
Block a user