EmlaLockSafe
PreferencesMenu.h
Go to the documentation of this file.
1
5
#pragma once
6
#include "../Tools.h"
7
#include "../UsedInterrupts.h"
8
#include "../configuration/Configuration.h"
9
10
#include <DialogYesNo.h>
11
#include <ESP.h>
12
#include <MenuView.h>
13
#include <SPIFFS.h>
14
15
namespace
views
{
19
class
PreferencesMenu
:
public
lcd::MenuView {
20
public
:
29
PreferencesMenu
(LiquidCrystal_PCF8574*
display
, RotaryEncoder*
encoder
,
const
int
& numberOfColumns,
const
int
& numberOfRows)
30
: lcd::MenuView(
display
,
"PreferencesMenu"
,
encoder
,
"Preferences"
, numberOfColumns, numberOfRows) {}
31
32
public
:
36
PreferencesMenu
(
const
PreferencesMenu
& other) =
delete
;
37
38
public
:
42
PreferencesMenu
(
PreferencesMenu
&& other)
noexcept
=
delete
;
43
44
protected
:
48
virtual
void
activate
() {
49
// is this the first time activate is called?
50
if
(menuItems.empty()) {
51
createMenuItem(
"Change Wifi Settings"
, [
this
](MenuItem*) {
52
configuration::Configuration::getSingleton
().
setWifiSettings
(
""
,
""
);
53
ESP.restart();
54
});
55
56
createMenuItem(
"Start Configuration Server"
, [
this
](MenuItem*) {
57
const
auto
& timeRestictions =
configuration::Configuration::getSingleton
().
getTimeRestrictions
();
58
if
(!timeRestictions.restrictConfigurationServer || timeRestictions.checkTime()) {
59
ViewStore::activateView
(
ViewStore::ConfigurationServerView
);
60
}
61
else
{
62
ViewStore::activateView
(
ViewStore::TimeRestrictedView
);
63
}
64
});
65
createMenuItem(
"Restore Factory Defaults"
, [
this
](MenuItem*) {
66
if
(lcd::DialogYesNo(
display
,
encoder
,
"Are you sure to\ndelete everything?"
, numberOfColumns, numberOfRows)
67
.showModal(
false
)) {
68
configuration::Configuration::getSingleton
().
restoreFactoryDefaults
();
69
display
->clear();
70
display
->setCursor(0, 0);
71
display
->print(
"The controller is"
);
72
display
->setCursor(0, 1);
73
display
->print(
"gooing to reboot..."
);
74
delay(2000);
75
ESP.restart();
76
}
77
});
78
79
createMenuItem(
"Back"
, [
this
](MenuItem*) {
80
activatePreviousView();
81
});
82
}
83
84
lcd::MenuView::activate();
85
}
86
};
87
}
// namespace views
configuration::Configuration::restoreFactoryDefaults
void restoreFactoryDefaults()
Reset all values to the default values and write configuration.
Definition:
Configuration.h:436
configuration::Configuration::getTimeRestrictions
const TimeRestrictions & getTimeRestrictions() const
get the timeout of display backlight in seconds
Definition:
Configuration.h:354
configuration::Configuration::getSingleton
static Configuration & getSingleton()
Get the Singleton object.
Definition:
Configuration.h:162
configuration::Configuration::setWifiSettings
void setWifiSettings(const String &ssid, const String &pwd)
Set the Wifi Settings.
Definition:
Configuration.h:368
views::PreferencesMenu
preferences menu
Definition:
PreferencesMenu.h:19
views::PreferencesMenu::PreferencesMenu
PreferencesMenu(PreferencesMenu &&other) noexcept=delete
Move constructor - not available otherwise we get problems with the callbacks.
views::PreferencesMenu::activate
virtual void activate()
called as soon as the view becomes active
Definition:
PreferencesMenu.h:48
views::PreferencesMenu::PreferencesMenu
PreferencesMenu(const PreferencesMenu &other)=delete
Copy constructor - not available.
views::PreferencesMenu::PreferencesMenu
PreferencesMenu(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder, const int &numberOfColumns, const int &numberOfRows)
Construct a new menu object.
Definition:
PreferencesMenu.h:29
views::ViewStore::activateView
static bool activateView(const ViewId &id)
activates the view described by the id
Definition:
ViewStore.h:98
views::ViewStore::ConfigurationServerView
@ ConfigurationServerView
Definition:
ViewStore.h:24
views::ViewStore::TimeRestrictedView
@ TimeRestrictedView
Definition:
ViewStore.h:36
display
views::ConfigurationServerView configurationServerView & display
Definition:
main.cpp:57
encoder
RotaryEncoder encoder(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_SWITCH)
views
Definition:
ConfigurationServerView.h:10
software
src
views
PreferencesMenu.h
Generated on Tue May 24 2022 15:32:38 for EmlaLockSafe by
1.9.4