EmlaLockSafe
HardwareTestView.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "../Tools.h"
8
9#include <RotaryEncoder.h>
10#include <ViewBase.h>
11#include <ds3231.h>
12
13namespace views {
17class HardwareTestView : public lcd::ViewBase {
18protected:
22 RotaryEncoder* encoder;
23
24public:
30 HardwareTestView(LiquidCrystal_PCF8574* display, RotaryEncoder* encoder)
31 : lcd::ViewBase(display, "HardwareTestView")
32 , encoder(encoder) {}
33
34public:
38 HardwareTestView(const HardwareTestView& other) = delete;
39
40public:
44 HardwareTestView(HardwareTestView&& other) noexcept = delete;
45
46protected:
50 virtual void activate() {
51 display->clear();
52 display->setCursor(0, 0);
53 display->print("Encoder Test");
54 }
55
56public:
62 virtual void tick(const bool& forceRedraw) {
63 auto direction = encoder->getDirection();
64 auto click = encoder->getNewClick();
65
66 // Display the state of the encoder
67 if (click) {
68 display->setCursor(0, 1);
69 display->print("Clicked");
70 delay(500);
71 display->setCursor(0, 1);
72 display->print(" ");
73 }
74
75 if (direction == RotaryEncoder::Direction::CLOCKWISE) {
76 display->setCursor(0, 1);
77 display->print("CLOCKWISE");
78 delay(500);
79 display->setCursor(0, 1);
80 display->print(" ");
81 }
82
83 if (direction == RotaryEncoder::Direction::COUNTERCLOCKWISE) {
84 display->setCursor(0, 1);
85 display->print("COUNTERCLOCKWISE");
86 delay(500);
87 display->setCursor(0, 1);
88 display->print(" ");
89 }
90
91 // Get current time
92 struct ts rtcTime;
93 DS3231_get(&rtcTime);
94
95 // convert RTC structure to tm structure
96 tm timeBuf;
97 char buf[21];
98 timeBuf.tm_year = rtcTime.year - 1900;
99 timeBuf.tm_mon = rtcTime.mon - 1;
100 timeBuf.tm_mday = rtcTime.mday;
101 timeBuf.tm_hour = rtcTime.hour;
102 timeBuf.tm_min = rtcTime.min;
103 timeBuf.tm_sec = rtcTime.sec;
104 strftime(buf, 21, "R %d.%m.%y %T", &timeBuf);
105 display->setCursor(0, 2);
106 display->print(buf);
107
108 static time_t lastTime = 0;
109 time_t now = time(NULL);
110 if (now != lastTime) {
111 strftime(buf, 21, "S %d.%m.%y %T", localtime_r(&now, &timeBuf));
112 display->setCursor(0, 3);
113 display->print(buf);
114 lastTime = now;
115
116 digitalWrite(COIL_PIN, now % 2);
117 }
118
119 Tools::tickWifiSymbol(display, forceRedraw);
120 }
121};
122} // namespace views
#define COIL_PIN
GPIO the coil of the safe is connected to.
Definition: HardwareConfiguration.h:10
static void tickWifiSymbol(LiquidCrystal_PCF8574 *display, bool forceRedraw)
tick routine updating the wifi signal strength icon
Definition: Tools.h:23
Main view testing all connected hardware.
Definition: HardwareTestView.h:17
virtual void activate()
called as soon as the view becomes active
Definition: HardwareTestView.h:50
HardwareTestView(LiquidCrystal_PCF8574 *display, RotaryEncoder *encoder)
Construct a vie object.
Definition: HardwareTestView.h:30
HardwareTestView(HardwareTestView &&other) noexcept=delete
Move constructor.
HardwareTestView(const HardwareTestView &other)=delete
Copy constructor - not available.
RotaryEncoder * encoder
pointer to the encoder instance
Definition: HardwareTestView.h:22
virtual void tick(const bool &forceRedraw)
called during the loop function
Definition: HardwareTestView.h:62
views::ConfigurationServerView configurationServerView & display
Definition: main.cpp:57
Definition: ConfigurationServerView.h:10