EmlaLockSafe
EmlalockUnlockKeyMenu.h
Go to the documentation of this file.
1
5#pragma once
6#include "../configuration/Configuration.h"
7
8#include <DialogYesNo.h>
9#include <MenuView.h>
10
11namespace views {
15class EmlalockUnlockKeyMenu : public lcd::MenuView {
16public:
25 EmlalockUnlockKeyMenu(LiquidCrystal_PCF8574* display,
26 RotaryEncoder* encoder,
27 const int& numberOfColumns,
28 const int& numberOfRows)
29 : lcd::MenuView(display, "EmlalockUnlockKeyMenu", encoder, "Emlalock Unlock Key", numberOfColumns, numberOfRows) {}
30
31public:
36
37public:
41 EmlalockUnlockKeyMenu(EmlalockUnlockKeyMenu&& other) noexcept = delete;
42
43protected:
47 virtual void activate() {
48 // is this the first time activate is called?
49 if (menuItems.empty()) {
50 // Menu item just showing the current key
51 String keyItemText = "Current Key: " + configuration::Configuration::getSingleton().getEmergencyKey();
52 createMenuItem(keyItemText, [this](MenuItem*) {});
53
54 // Menu item which allows to generate a new key
55 createMenuItem("Generate new key", [this](MenuItem*) {
56 if (lcd::DialogYesNo(display,
57 encoder,
58 "Are you sure?\nThe old key wont't\nbe valid anymore.",
59 numberOfColumns,
60 numberOfRows)
61 .showModal(false)) {
62 // update the menu item
63 String keyItemText = "Current key: " + configuration::Configuration::getSingleton().generateNewEmergencyKey();
64 menuItems.front().setText(keyItemText);
65 }
66 });
67
68 // Item for going back to the previous menu.
69 createMenuItem("Back", [this](MenuItem*) {
70 activatePreviousView();
71 });
72 }
73
74 lcd::MenuView::activate();
75 }
76};
77} // namespace views
const String & generateNewEmergencyKey()
Generates a new key and stores it to the file system.
Definition: Configuration.h:420
static Configuration & getSingleton()
Get the Singleton object.
Definition: Configuration.h:162
const String & getEmergencyKey() const
get the emergency key of the safe
Definition: Configuration.h:299
Menu for showing / changing the unlock key.
Definition: EmlalockUnlockKeyMenu.h:15
EmlalockUnlockKeyMenu(EmlalockUnlockKeyMenu &&other) noexcept=delete
Move constructor - not available otherwise we get problems with the callbacks.
EmlalockUnlockKeyMenu(const EmlalockUnlockKeyMenu &other)=delete
Copy constructor - not available.
EmlalockUnlockKeyMenu(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder, const int &numberOfColumns, const int &numberOfRows)
Construct a new menu object.
Definition: EmlalockUnlockKeyMenu.h:25
virtual void activate()
called as soon as the view becomes active
Definition: EmlalockUnlockKeyMenu.h:47
views::ConfigurationServerView configurationServerView & display
Definition: main.cpp:57
RotaryEncoder encoder(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_SWITCH)
Definition: ConfigurationServerView.h:10