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
11
namespace
views
{
15
class
EmlalockUnlockKeyMenu
:
public
lcd::MenuView {
16
public
:
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
31
public
:
35
EmlalockUnlockKeyMenu
(
const
EmlalockUnlockKeyMenu
& other) =
delete
;
36
37
public
:
41
EmlalockUnlockKeyMenu
(
EmlalockUnlockKeyMenu
&& other)
noexcept
=
delete
;
42
43
protected
:
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
configuration::Configuration::generateNewEmergencyKey
const String & generateNewEmergencyKey()
Generates a new key and stores it to the file system.
Definition:
Configuration.h:420
configuration::Configuration::getSingleton
static Configuration & getSingleton()
Get the Singleton object.
Definition:
Configuration.h:162
configuration::Configuration::getEmergencyKey
const String & getEmergencyKey() const
get the emergency key of the safe
Definition:
Configuration.h:299
views::EmlalockUnlockKeyMenu
Menu for showing / changing the unlock key.
Definition:
EmlalockUnlockKeyMenu.h:15
views::EmlalockUnlockKeyMenu::EmlalockUnlockKeyMenu
EmlalockUnlockKeyMenu(EmlalockUnlockKeyMenu &&other) noexcept=delete
Move constructor - not available otherwise we get problems with the callbacks.
views::EmlalockUnlockKeyMenu::EmlalockUnlockKeyMenu
EmlalockUnlockKeyMenu(const EmlalockUnlockKeyMenu &other)=delete
Copy constructor - not available.
views::EmlalockUnlockKeyMenu::EmlalockUnlockKeyMenu
EmlalockUnlockKeyMenu(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder, const int &numberOfColumns, const int &numberOfRows)
Construct a new menu object.
Definition:
EmlalockUnlockKeyMenu.h:25
views::EmlalockUnlockKeyMenu::activate
virtual void activate()
called as soon as the view becomes active
Definition:
EmlalockUnlockKeyMenu.h:47
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
EmlalockUnlockKeyMenu.h
Generated on Tue May 24 2022 15:32:38 for EmlaLockSafe by
1.9.4