-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplayManager.cpp
More file actions
224 lines (187 loc) · 10.7 KB
/
DisplayManager.cpp
File metadata and controls
224 lines (187 loc) · 10.7 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
+----------------------------------------------------------------------+
| LiFeBlue Bluetooth Interface |
+----------------------------------------------------------------------+
| Copyright (c) 2017-2019 Internet Technology Solutions, LLC, |
+----------------------------------------------------------------------+
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. You |
| may obtain a copy of the License at: |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Authors: John Coggeshall <john@thissmarthouse.com> |
+----------------------------------------------------------------------+
*/
#include "DisplayManager.h"
const unsigned char logo [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x89, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe4, 0x71, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0, 0xfc, 0x4f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x23, 0xfe, 0x37, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x8f, 0xff, 0x89, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x1f, 0xff, 0xe2, 0x7f, 0xff, 0xff, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe4, 0x7f, 0xff, 0xf1, 0xbf, 0xff, 0xfc, 0x3c, 0x3f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x91, 0xff, 0xff, 0xfc, 0x4f, 0xff, 0xf8, 0xff, 0x9f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x63, 0xff, 0xff, 0xff, 0x13, 0xff, 0xff, 0x80, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x8f, 0xff, 0xff, 0xff, 0x8d, 0xff, 0xfe, 0x3c, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf2, 0x3f, 0xff, 0xff, 0xff, 0xe2, 0x7f, 0xfe, 0xe7, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0x7f, 0xff, 0xff, 0xff, 0xf0, 0xbf, 0xff, 0x81, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x91, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x4f, 0xff, 0x81, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x47, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0xfe, 0x18, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfd, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x85, 0xfe, 0x3c, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf2, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe2, 0x7e, 0x3c, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe8, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xf8, 0x9e, 0x3c, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xb1, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xfc, 0x6e, 0x18, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x47, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0x12, 0x00, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xfd, 0x0f, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xc4, 0x00, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xf2, 0x3f, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xe3, 0x00, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xc8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xc0, 0x7f, 0xff,
0xff, 0xff, 0xff, 0xa1, 0xff, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xfe, 0x20, 0x7f, 0xff,
0xff, 0xff, 0xfe, 0x47, 0xff, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xff, 0x18, 0x7f, 0xff,
0xff, 0xff, 0xf9, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xff, 0xc4, 0x7f, 0xff,
0xff, 0xff, 0xf6, 0x3f, 0xff, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x3f, 0xff,
0xff, 0xff, 0xc8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x20, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xdf, 0xff,
0xff, 0xff, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x27, 0xff,
0xff, 0xfe, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8b, 0xff,
0xff, 0xf9, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc4, 0xff,
0xff, 0xf4, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x3f,
0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x5f,
0xff, 0xb3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x07, 0xff, 0xff,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c0, 0x1e, 0x1f, 0xf8, 0x03, 0x47, 0xe2, 0xc7, 0x1c, 0x06, 0x1f,
0xdf, 0xe1, 0x88, 0x06, 0x31, 0xc0, 0x1e, 0x1f, 0xf8, 0x63, 0x67, 0xe6, 0xc7, 0x1f, 0xc6, 0x1f,
0x8f, 0xe1, 0x8c, 0x86, 0x31, 0xc0, 0x3e, 0x1f, 0xf8, 0x63, 0x21, 0x84, 0xc7, 0x1f, 0xc6, 0x1f,
0xff, 0xe1, 0x8c, 0x86, 0x10, 0xc4, 0x3e, 0x1f, 0xf8, 0x63, 0xb0, 0x0d, 0xc7, 0x1f, 0xc6, 0x1f,
0xff, 0xe1, 0x8c, 0x86, 0x00, 0xc6, 0x3e, 0x1f, 0xf8, 0x63, 0x9c, 0x39, 0xc7, 0x1f, 0xc6, 0x1f,
0xfe, 0x01, 0x8d, 0x86, 0x00, 0xc6, 0x3e, 0x1f, 0xf8, 0x63, 0xc7, 0xe3, 0xc2, 0x1c, 0x06, 0x01,
0x8e, 0x01, 0x8f, 0x84, 0x30, 0xc6, 0x1e, 0x1f, 0xf8, 0x63, 0xf0, 0x0f, 0xc0, 0x1c, 0x06, 0x01,
0xfe, 0x01, 0x8f, 0x84, 0x38, 0xc6, 0x1e, 0x1f, 0xf8, 0x61, 0xfc, 0x3f, 0xc0, 0x1c, 0x06, 0x01,
0xff, 0x07, 0x8f, 0xcc, 0x78, 0xc7, 0x1f, 0x1f, 0xf8, 0xe3, 0xff, 0xff, 0xf0, 0x7c, 0x1e, 0x03
};
DisplayManager *DisplayManager::m_instance = NULL;
DisplayManager::DisplayManager()
{
Wire.begin(OLED_SDA_PIN, OLED_SCL_PIN);
display = new Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN);
Serial.printf("- Initialized SSD1306 (SDA: %d, SCL: %d, RST: %d, Address: 0x%x)\n", OLED_SDA_PIN, OLED_SCL_PIN, OLED_RESET_PIN, OLED_ADDRESS);
batteryManager = BatteryManager::instance();
}
DisplayManager *DisplayManager::instance()
{
if(!m_instance) {
m_instance = new DisplayManager();
}
return m_instance;
}
void DisplayManager::setup()
{
if(!display->begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) {
Serial.println("SSD1306 Failed to initailize");
for(;;);
}
display->clearDisplay();
display->drawBitmap(0, 3, logo, 128, 58, 1);
display->setTextSize(1);
display->setTextColor(WHITE);
display->setCursor(0, 0);
display->cp437(true);
display->display();
delay(5000);
display->clearDisplay();
display->display();
}
void DisplayManager::scanningScreen(uint8_t percent)
{
display->clearDisplay();
display->setCursor(0, 20);
display->print("Searching....");
drawProgress(0, 30, 120, 20, percent);
display->display();
}
void DisplayManager::wifiConnectScreen(uint8_t percent)
{
display->clearDisplay();
display->setCursor(0,20);
display->print("Connecting WiFi..");
drawProgress(0, 30, 120, 20, percent);
display->display();
}
void DisplayManager::statusScreen()
{
batteryInfo_t *batteryInfo;
uint8_t totalCells;
if(batteryManager->getTotalBatteries() == 0) {
display->clearDisplay();
display->setCursor(0,0);
display->print("No Batteries Found");
display->display();
return;
}
if(currentBattery >= batteryManager->getTotalBatteries()) {
currentBattery = 0;
}
batteryInfo = batteryManager->getBattery(currentBattery);
if (batteryInfo->is_valid) { // Check if the battery buffer is valid --JR
display->clearDisplay();
display->setCursor(0, 0);
display->println("LiFeBlue Monitor");
display->printf("%s RSSI:%ddb", batteryInfo->bname, batteryInfo->device->getRSSI());
display->setCursor(0,20);
display->printf("V: %.2fV\nC: %.2fA\nSoC: %u%%\nT: %.1fC",
(float)batteryInfo->voltage / 1000,
(float)batteryInfo->current / 1000,
batteryInfo->soc,
(float)batteryInfo->temp / 10);
totalCells = batteryManager->getTotalCells();
if(totalCells > 0) {
display->setCursor(65, 20);
for(int i = 0; (i < 5) && (i < totalCells); i++) {
display->printf("%d: %umV\n", i+1, batteryInfo->cells[i]);
display->setCursor(65, 20+ ((i+1) * 8));
}
}
if(WiFi.status() == WL_CONNECTED) {
display->setCursor(0, 56);
display->print(WiFi.localIP().toString().c_str());
//display->setCursor(100, 0); // Fix the RSSI X start position to make room for the % sign so it does not wrap.Was 110 -> 100
//The % Was wrapping to the start of the second line and overwriting the first character. -- JR
display->print(" ");
//display->print(2 * (WiFi.RSSI() + 100)); // WiFi .RSSI returns 0 to -100db value --JR
display->print(WiFi.RSSI());
display->print("db"); // Changed this to read db instead of %
}
display->display();
currentBattery++;
}
}
void DisplayManager::drawProgress(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t percent)
{
float bar;
percent = (percent > 100) ? 100 : percent;
percent = (percent < 0) ? 0 : percent;
bar = ((float)(width - 1) / 100) * percent;
display->drawRect(x, y, width, height, WHITE);
display->fillRect(x + 2, y + 2, bar, height - 4, WHITE);
}