Repository navigation
Expand file tree
/
Copy patholed.cpp
More file actions
156 lines (122 loc) · 2.64 KB
/
Copy patholed.cpp
File metadata and controls
156 lines (122 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "pins.h"
#include "display/eyes.h"
#include "display/oled.h"
#include "display/oled_internal.h"
#include "network/wifi_connect.h"
#include "settings/settings.h"
Adafruit_SSD1306 display(
OLED_WIDTH,
OLED_HEIGHT,
&Wire,
-1
);
bool oledAvailable = false;
namespace {
constexpr uint32_t kProvisionRotateMs = 3500;
constexpr uint32_t kStatusThenIdleHoldMs = 3000;
uint32_t lastProvisionRotateMs = 0;
uint8_t provisionStep = 0;
} // namespace
void showProvisioningOled(
const char* line1,
const char* line2
) {
stopEyes();
wakeOled();
lastProvisionRotateMs = 0;
showOledText(line1, line2);
}
void updateProvisioningOled(uint32_t nowMs) {
if (!oledAvailable || !wifiProvisioningMode()) {
return;
}
wakeOled();
if (lastProvisionRotateMs != 0 &&
nowMs - lastProvisionRotateMs < kProvisionRotateMs) {
return;
}
lastProvisionRotateMs = nowMs;
provisionStep = static_cast<uint8_t>((provisionStep + 1) % 2);
if (provisionStep == 0) {
showOledText("Join this WiFi", wifiApSsid());
} else {
showOledText("Then open", wifiApIpText());
}
}
void showOledText(
const char* line1,
const char* line2
) {
if (!oledAvailable) {
return;
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 4);
display.println(line1);
if (line2 != nullptr) {
display.setCursor(0, 18);
display.println(line2);
}
display.display();
}
void showIdleScreen() {
startEyes();
}
void showBootIpThenIdle(const char* ip) {
showBootIp(ip);
delay(kStatusThenIdleHoldMs);
showIdleScreen();
}
void showTextThenIdle(const char* line1, const char* line2) {
stopEyes();
showOledText(line1, line2);
delay(kStatusThenIdleHoldMs);
showIdleScreen();
}
void blankOled() {
if (!oledAvailable) {
return;
}
display.clearDisplay();
display.display();
}
void sleepOled() {
if (!oledAvailable) {
return;
}
display.ssd1306_command(SSD1306_DISPLAYOFF);
}
void wakeOled() {
if (!oledAvailable) {
return;
}
display.ssd1306_command(SSD1306_DISPLAYON);
}
void applyOledRotation() {
if (!oledAvailable) {
return;
}
display.setRotation(settingsOledRotate180() ? 2 : 0);
}
void showOledOrientationTest(bool rotate180) {
if (!oledAvailable) {
return;
}
stopEyes();
wakeOled();
display.setRotation(rotate180 ? 2 : 0);
showOledText("THIS WAY UP");
}
void restoreProvisioningOled() {
if (!wifiProvisioningMode()) {
return;
}
applyOledRotation();
showProvisioningOled("Join this WiFi", wifiApSsid());
}