EmlaLockSafe
WifiConnectingView.h
Go to the documentation of this file.
1
5
#pragma once
6
7
#include "../Tools.h"
8
#include "../configuration/Configuration.h"
9
10
#include <MenuView.h>
11
#include <ViewBase.h>
12
#include <WiFi.h>
13
#include <time.h>
14
15
namespace
views
{
19
class
WifiConnectingView
:
public
lcd::ViewBase {
20
public
:
26
WifiConnectingView
(LiquidCrystal_PCF8574*
display
)
27
: lcd::ViewBase(
display
,
"WifiConnectingView"
) {}
28
29
public
:
33
WifiConnectingView
(
const
WifiConnectingView
& other) =
delete
;
34
35
public
:
39
WifiConnectingView
(
WifiConnectingView
&& other)
noexcept
=
delete
;
40
41
protected
:
45
virtual
void
activate
() {
46
display
->clear();
47
display
->setCursor(0, 0);
48
display
->print(
"Connecting to wifi:"
);
49
50
display
->setCursor(0, 1);
51
display
->print(
configuration::Configuration::getSingleton
().getSsid());
52
53
// Start connecting
54
WiFi.disconnect();
55
WiFi.setHostname(
"EmlalockSafe"
);
56
WiFi.mode(WIFI_STA);
57
WiFi.begin(
configuration::Configuration::getSingleton
().getSsid().c_str(),
58
configuration::Configuration::getSingleton
().getPwd().c_str());
59
WiFi.setAutoReconnect(
true
);
60
61
// Play an animation while the connection is established
62
int
counter = 0;
63
Tools::waitAnimation
(
display
, [&counter]() ->
bool
{
64
counter++;
65
if
(counter % 25 == 0) {
66
// if we've waited for over 2.5s (25 loops), restart wifi....
67
// this is required because of an bug in the ESP32 arduino core.
68
WiFi.disconnect();
69
WiFi.setHostname(
"EmlalockSafe"
);
70
WiFi.mode(WIFI_STA);
71
WiFi.begin(
configuration::Configuration::getSingleton
().getSsid().c_str(),
72
configuration::Configuration::getSingleton
().getPwd().c_str());
73
WiFi.setAutoReconnect(
true
);
74
}
75
return
WiFi.status() != WL_CONNECTED;
76
});
77
78
display
->clear();
79
display
->setCursor(0, 0);
80
display
->print(
"Setting Timezone:"
);
81
// configure NTP
82
configTzTime(
configuration::Configuration::getSingleton
().getTimezone().c_str(),
83
"pool.ntp.org"
,
84
"time.nist.gov"
,
85
"time.google.com"
);
86
87
// go back to previous view
88
activatePreviousView();
89
}
90
91
public
:
97
virtual
void
tick
(
const
bool
& forceRedraw) {
98
// not used since activate blocks and immediately returns to the previous
99
// view
100
}
101
};
// namespace views
102
}
// namespace views
Tools::waitAnimation
static void waitAnimation(LiquidCrystal_PCF8574 *display, std::function< bool()> stillActive)
Shows the animation while waiting until the callback returns false.
Definition:
Tools.h:69
configuration::Configuration::getSingleton
static Configuration & getSingleton()
Get the Singleton object.
Definition:
Configuration.h:162
views::WifiConnectingView
View displayed while connection to the access point.
Definition:
WifiConnectingView.h:19
views::WifiConnectingView::tick
virtual void tick(const bool &forceRedraw)
called during the loop function
Definition:
WifiConnectingView.h:97
views::WifiConnectingView::WifiConnectingView
WifiConnectingView(LiquidCrystal_PCF8574 *display)
Construct the view object.
Definition:
WifiConnectingView.h:26
views::WifiConnectingView::WifiConnectingView
WifiConnectingView(WifiConnectingView &&other) noexcept=delete
Move constructor - not available.
views::WifiConnectingView::WifiConnectingView
WifiConnectingView(const WifiConnectingView &other)=delete
Copy constructor - not available.
views::WifiConnectingView::activate
virtual void activate()
called as soon as the view becomes active
Definition:
WifiConnectingView.h:45
display
views::ConfigurationServerView configurationServerView & display
Definition:
main.cpp:57
views
Definition:
ConfigurationServerView.h:10
software
src
views
WifiConnectingView.h
Generated on Tue May 24 2022 15:32:38 for EmlaLockSafe by
1.9.4