Repository navigation
Expand file tree
/
Copy patholed.cpp
More file actions
113 lines (87 loc) · 1.82 KB
/
Copy patholed.cpp
File metadata and controls
113 lines (87 loc) · 1.82 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
#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"
Adafruit_SSD1306 display(
OLED_WIDTH,
OLED_HEIGHT,
&Wire,
-1
);
bool oledAvailable = false;
namespace {
constexpr uint32_t kProvisionRotateMs = 3500;
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 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);
}