EmlaLockSafe
TimeRestrictedView.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "../configuration/Configuration.h"
8
9#include <ViewBase.h>
10
11namespace views {
15class TimeRestrictedView : public lcd::ViewBase {
16protected:
21
22public:
28 TimeRestrictedView(LiquidCrystal_PCF8574* display)
29 : lcd::ViewBase(display, "TimeRestrictedView") {}
30
31public:
35 TimeRestrictedView(const TimeRestrictedView& other) = delete;
36
37public:
41 TimeRestrictedView(TimeRestrictedView&& other) noexcept = delete;
42
43protected:
47 virtual void activate() {
48 getBacklightTimeoutManager().delayTimeout();
49 activationMillis = millis();
50 tick(true);
51 }
52
53public:
59 virtual void tick(const bool& forceRedraw) {
60 getBacklightTimeoutManager().delayTimeout();
61 if (activationMillis + 10000 < millis()) {
62 activatePreviousView();
63 }
64
65 // Stuff which never changes
66 if (forceRedraw) {
68
69 display->clear();
70 display->setCursor(0, 0);
71 display->print("Open Time Restricted");
72
73 display->setCursor(0, 1);
74 int h = restrictions.startTime / 3600;
75 int m = (restrictions.startTime / 60) % 60;
76 display->printf("Start Time: %02d:%02d", h, m);
77 display->setCursor(0, 2);
78 h = restrictions.endTime / 3600;
79 m = (restrictions.startTime / 60) % 60;
80 display->printf("End Time: %02d:%02d", h, m);
81
82 display->setCursor(0, 3);
83 display->print("Current Time: 00:00");
84 }
85
86 // current time
87 static time_t lastDisplayedCurrentTime = 0;
88 time_t currentTime = time(NULL);
89 if (forceRedraw || (lastDisplayedCurrentTime / 60 != currentTime / 60)) {
90 char buf[21];
91 tm tmBuf;
92 lastDisplayedCurrentTime = currentTime;
93 strftime(buf, 6, "%R", localtime_r(&currentTime, &tmBuf));
94 display->setCursor(15, 3);
95 display->print(buf);
96 }
97 }
98};
99} // namespace views
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 should be opened but the time is not within the allowed range.
Definition: TimeRestrictedView.h:15
TimeRestrictedView(LiquidCrystal_PCF8574 *display)
Construct the view.
Definition: TimeRestrictedView.h:28
long activationMillis
Time when the view was activated.
Definition: TimeRestrictedView.h:20
virtual void tick(const bool &forceRedraw)
called during the loop function
Definition: TimeRestrictedView.h:59
TimeRestrictedView(const TimeRestrictedView &other)=delete
Copy constructor - not available.
TimeRestrictedView(TimeRestrictedView &&other) noexcept=delete
Move constructor.
virtual void activate()
called as soon as the view becomes active
Definition: TimeRestrictedView.h:47
views::ConfigurationServerView configurationServerView & display
Definition: main.cpp:57
Definition: ConfigurationServerView.h:10