EmlaLockSafe
HygieneOpeningMenu.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "../LockState.h"
8#include "ViewStore.h"
9
10#include <MenuView.h>
11
12namespace views {
16class HygieneOpeningMenu : public lcd::MenuView {
17public:
26 HygieneOpeningMenu(LiquidCrystal_PCF8574* display, RotaryEncoder* encoder, const int& numberOfColumns, const int& numberOfRows)
27 : lcd::MenuView(display, "HygieneOpeningMenu", encoder, "Hygiene Opening", numberOfColumns, numberOfRows) {}
28
29public:
33 HygieneOpeningMenu(const HygieneOpeningMenu& other) = delete;
34
35public:
39 HygieneOpeningMenu(HygieneOpeningMenu&& other) noexcept = delete;
40
41protected:
45 virtual void activate() {
46 // is this the first time activate is called?
47 if (menuItems.empty()) {
48 // create menu items
49 createMenuItem("Open Safe", [](MenuItem*) {
51 if (!timeRestictions.restrictHygieneOpeningTimes || timeRestictions.checkTime()) {
53 }
54 else {
56 }
57 });
58 createMenuItem("Emlalock Unlock Key", [](MenuItem*) {
60 });
61 createMenuItem("Time Left: 00:00:00", [](MenuItem*) {});
62 }
63 lcd::MenuView::activate();
64 }
65
66public:
72 virtual void tick(const bool& forceRedraw) {
73 // updated the view of the menu
74 lcd::MenuView::tick(forceRedraw);
75
76 auto direction = encoder->getDirection();
77 auto click = encoder->getNewClick();
78 char buf[21];
79
80 if (click || (direction != RotaryEncoder::Direction::NOROTATION)) {
81 if (!getBacklightTimeoutManager().delayTimeout()) {
82 return;
83 }
84 }
85 getBacklightTimeoutManager().tick(display);
86
87 // should the time left be displayed? If yes, how
88 static time_t lastDisplayedTime = 0;
89 time_t timeLeft = 0;
90 if (LockState::getCleaningEndDate() > time(NULL)) {
91 timeLeft = LockState::getCleaningEndDate() - time(NULL);
92 }
93
94 // redraw required?
95 if (forceRedraw || (lastDisplayedTime != timeLeft)) {
96 lastDisplayedTime = timeLeft;
97
98 int sec = timeLeft % 60;
99 timeLeft = timeLeft / 60;
100 int min = timeLeft % 60;
101 timeLeft = timeLeft / 60;
102 int hour = timeLeft;
103
104 sprintf(buf, "Time Left: %02d:%02d:%02d", hour, min, sec);
105
106 menuItems.back().setText(buf);
107 }
108 }
109};
110} // namespace views
static const time_t & getCleaningEndDate()
Get the End Date of the current cleaning opening (or 0)
Definition: LockState.h:416
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
View used when the safe is unlocked for a hygiene opening.
Definition: HygieneOpeningMenu.h:16
virtual void activate()
called as soon as the view becomes active
Definition: HygieneOpeningMenu.h:45
HygieneOpeningMenu(const HygieneOpeningMenu &other)=delete
Copy constructor - not available.
HygieneOpeningMenu(HygieneOpeningMenu &&other) noexcept=delete
Move constructor.
HygieneOpeningMenu(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder, const int &numberOfColumns, const int &numberOfRows)
Construct a new hygiene opening menu object.
Definition: HygieneOpeningMenu.h:26
virtual void tick(const bool &forceRedraw)
called during the loop function
Definition: HygieneOpeningMenu.h:72
static bool activateView(const ViewId &id)
activates the view described by the id
Definition: ViewStore.h:98
@ UnlockSafeView
Definition: ViewStore.h:38
@ TimeRestrictedView
Definition: ViewStore.h:36
@ EmlalockUnlockKeyMenu
Definition: ViewStore.h:28
views::ConfigurationServerView configurationServerView & display
Definition: main.cpp:57
RotaryEncoder encoder(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_SWITCH)
Definition: ConfigurationServerView.h:10