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
15namespace views {
19class PreferencesMenu : public lcd::MenuView {
20public:
29 PreferencesMenu(LiquidCrystal_PCF8574* display, RotaryEncoder* encoder, const int& numberOfColumns, const int& numberOfRows)
30 : lcd::MenuView(display, "PreferencesMenu", encoder, "Preferences", numberOfColumns, numberOfRows) {}
31
32public:
36 PreferencesMenu(const PreferencesMenu& other) = delete;
37
38public:
42 PreferencesMenu(PreferencesMenu&& other) noexcept = delete;
43
44protected:
48 virtual void activate() {
49 // is this the first time activate is called?
50 if (menuItems.empty()) {
51 createMenuItem("Change Wifi Settings", [this](MenuItem*) {
53 ESP.restart();
54 });
55
56 createMenuItem("Start Configuration Server", [this](MenuItem*) {
58 if (!timeRestictions.restrictConfigurationServer || timeRestictions.checkTime()) {
60 }
61 else {
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)) {
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
void restoreFactoryDefaults()
Reset all values to the default values and write configuration.
Definition: Configuration.h:436
const TimeRestrictions & getTimeRestrictions() const
get the timeout of display backlight in seconds
Definition: Configuration.h:354
static Configuration & getSingleton()
Get the Singleton object.
Definition: Configuration.h:162
void setWifiSettings(const String &ssid, const String &pwd)
Set the Wifi Settings.
Definition: Configuration.h:368
preferences menu
Definition: PreferencesMenu.h:19
PreferencesMenu(PreferencesMenu &&other) noexcept=delete
Move constructor - not available otherwise we get problems with the callbacks.
virtual void activate()
called as soon as the view becomes active
Definition: PreferencesMenu.h:48
PreferencesMenu(const PreferencesMenu &other)=delete
Copy constructor - not available.
PreferencesMenu(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder, const int &numberOfColumns, const int &numberOfRows)
Construct a new menu object.
Definition: PreferencesMenu.h:29
static bool activateView(const ViewId &id)
activates the view described by the id
Definition: ViewStore.h:98
@ ConfigurationServerView
Definition: ViewStore.h:24
@ TimeRestrictedView
Definition: ViewStore.h:36
views::ConfigurationServerView configurationServerView & display
Definition: main.cpp:57
RotaryEncoder encoder(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_SWITCH)
Definition: ConfigurationServerView.h:10