-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdisplays.cpp
More file actions
279 lines (252 loc) · 8.76 KB
/
displays.cpp
File metadata and controls
279 lines (252 loc) · 8.76 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Copyright (C) 2019-2021 OpenBikeSensor Contributors
* Contact: https://openbikesensor.org
*
* This file is part of the OpenBikeSensor firmware.
*
* The OpenBikeSensor firmware is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* OpenBikeSensor firmware is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the OpenBikeSensor firmware. If not,
* see <http://www.gnu.org/licenses/>.
*/
#include "displays.h"
#include "fonts/logos.h"
void DisplayDevice::showNumConfirmed() {
String val = String(confirmedMeasurements);
if (confirmedMeasurements <= 9) {
val = "0" + val;
}
this->prepareTextOnGrid(2, 4, val, MEDIUM_FONT);
this->prepareTextOnGrid(3, 5, "conf");
}
void DisplayDevice::showNumButtonPressed() {
String val = String(numButtonReleased);
if (numButtonReleased <= 9) {
val = "0" + val;
}
this->prepareTextOnGrid(0, 4, val, MEDIUM_FONT);
this->prepareTextOnGrid(1, 5, "press");
}
void DisplayDevice::displaySimple(uint16_t value) {
if (value == MAX_SENSOR_VALUE) {
this->prepareTextOnGrid(0, 0,
"", HUGE_FONT, -7, 0);
} else {
this->prepareTextOnGrid(0, 0,
ObsUtils::to3DigitString(value), HUGE_FONT, -7, 0);
}
this->prepareTextOnGrid(3, 2, "cm", MEDIUM_FONT, -7, -5);
}
bool startedShutdownDisplay = false;
bool DisplayDevice::handleShutdownDisplay()
{
bool updated = false;
#ifdef OBSPRO
bool buttonPressed = button.getState();
if (buttonPressed && button.getCurrentStateMillis() > 3000)
{
auto pressTimeMs = button.getCurrentStateMillis() - 3000;
// black out the display from top to bottom for so that after 7000 ms the whole display is black
auto linesToFill = (pressTimeMs * 64) / (BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS - 3000);
m_display->drawBox(0, 0, 128, linesToFill);
startedShutdownDisplay = true;
} else if (startedShutdownDisplay) {
startedShutdownDisplay = false;
clear();
updated = true;
}
#endif
return updated;
}
void DisplayDevice::showValues(
uint16_t sensor1MinDistance, const char* sensor1Location, uint16_t sensor1RawDistance,
uint16_t sensor2MinDistance, const char* sensor2Location, uint16_t sensor2RawDistance, uint16_t sensor2Distance,
uint16_t minDistanceToConfirm, int16_t batteryPercentage,
int16_t TemperaturValue, int lastMeasurements, boolean insidePrivacyArea,
double speed, uint8_t satellites) {
handleHighlight();
uint16_t value1 = sensor1MinDistance;
if (minDistanceToConfirm != MAX_SENSOR_VALUE) {
value1 = minDistanceToConfirm;
}
if (config.displayConfig & DisplaySimple) {
displaySimple(value1);
} else {
if (config.displayConfig & DisplayLeft) {
String loc1 = sensor1Location;
if (insidePrivacyArea) {
loc1 = "(" + loc1 + ")";
}
this->prepareTextOnGrid(0, 0, loc1);
if (value1 == MAX_SENSOR_VALUE) {
this->prepareTextOnGrid(0, 1, "---", LARGE_FONT);
} else {
this->prepareTextOnGrid(0, 1,
ObsUtils::to3DigitString(value1), LARGE_FONT);
}
}
// Show sensor2, when DisplayRight is configured
if (config.displayConfig & DisplayRight) {
uint16_t value2 = sensor2Distance;
String loc2 = sensor2Location;
this->prepareTextOnGrid(3, 0, loc2);
if (value2 == MAX_SENSOR_VALUE || value2 == 0) {
this->prepareTextOnGrid(2, 1, "---", LARGE_FONT, 5, 0);
} else {
this->prepareTextOnGrid(2, 1,
ObsUtils::to3DigitString(value2), LARGE_FONT, 5, 0);
}
}
} // NOT SIMPLE
if (config.displayConfig & DisplayDistanceDetail) {
const int bufSize = 64;
char buffer[bufSize];
// #ifdef NERD_SENSOR_DISTANCE
snprintf(buffer, bufSize - 1, "%03d|%02d|%03d", sensor1RawDistance,
lastMeasurements, sensor2RawDistance);
// #endif
#ifdef NERD_HEAP
snprintf(buffer, bufSize - 1, "%03d|%02d|%uk", sensor1RawDistance,
lastMeasurements, ESP.getFreeHeap() / 1024);
#endif
#ifdef NERD_VOLT
snprintf(buffer, bufSize - 1, "%03d|%02d|%3.2fV", sensor1RawDistance,
lastMeasurements, voltageMeter->read());
#endif
#ifdef NERD_GPS
snprintf(buffer, bufSize - 1, "%02ds|%s|%03u",
satellites,
gps.getHdopAsString().c_str(), gps.getLastNoiseLevel() );
#endif
this->prepareTextOnGrid(0, 4, buffer, MEDIUM_FONT);
} else if (config.displayConfig & DisplayNumConfirmed) {
showNumButtonPressed();
showNumConfirmed();
} else {
// Show GPS info, when DisplaySatellites is configured
if (config.displayConfig & DisplaySatellites) {
showGPS(satellites);
}
// Show velocity, when DisplayVelocity is configured
if (config.displayConfig & DisplayVelocity) {
showSpeed(speed);
}
}
if (batteryPercentage >= -1) {
showBatterieValue(batteryPercentage);
}
if (!(config.displayConfig & DisplaySimple)){
if(BMP280_active == true)
showTemperatureValue(TemperaturValue);
}
handleShutdownDisplay();
m_display->updateDisplay();
}
void DisplayDevice::showGPS(uint8_t sats) {
String val = String(sats);
if (sats <= 9) {
val = "0" + val;
}
this->prepareTextOnGrid(2, 4, val, MEDIUM_FONT);
this->prepareTextOnGrid(3, 5, "sats");
}
void DisplayDevice::showBatterieValue(int16_t input_val){
uint8_t x_offset_batterie_logo = 65;
uint8_t y_offset_batterie_logo = 2;
int8_t xlocation = 2;
if ((config.displayConfig & DisplaySimple)){
x_offset_batterie_logo += 32;
xlocation += 1;
}
if(input_val >= 0){
String val = String(input_val);
//showLogo(true);
this->showTextOnGrid(xlocation, 0, val + "%", TINY_FONT, 6, 0);
if(input_val > 90){
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo1);
}else if (input_val > 70)
{
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo2);
}else if (input_val> 50)
{
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo3);
}else if (input_val > 30)
{
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo4);
}else if (input_val >10)
{
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo5);
}else
{
cleanBattery(x_offset_batterie_logo, y_offset_batterie_logo);
m_display->drawXBM(x_offset_batterie_logo, y_offset_batterie_logo, 8, 9, BatterieLogo6);
}
}
}
void DisplayDevice::showTemperatureValue(int16_t input_val){
uint8_t x_offset_temp_logo = 30;
uint8_t y_offset_temp_logo = 2;
cleanTemperatur(x_offset_temp_logo,y_offset_temp_logo);
m_display->drawXBM(x_offset_temp_logo, y_offset_temp_logo, 8, 9, TempLogo);
String val = String(input_val);
this->showTextOnGrid(1, 0, val + "°C", TINY_FONT);
}
void DisplayDevice::showSpeed(double velocity) {
const int bufSize = 4;
char buffer[bufSize];
if (velocity >= 0) {
snprintf(buffer, bufSize - 1, "%02d", (int) velocity);
} else {
snprintf(buffer, bufSize - 1, "--");
}
this->prepareTextOnGrid(0, 4, buffer, MEDIUM_FONT);
this->prepareTextOnGrid(1, 5, "km/h");
}
uint8_t DisplayDevice::currentLine() const {
return mCurrentLine;
}
uint8_t DisplayDevice::newLine() {
if (mCurrentLine >= 5) {
scrollUp();
}
return ++mCurrentLine;
}
uint8_t DisplayDevice::scrollUp() {
for (uint8_t i = 0; i < 5; i++) {
prepareTextOnGrid(2, i, obsDisplay->get_gridTextofCell(2, i + 1));
}
m_display->updateDisplay();
return mCurrentLine--;
}
uint8_t DisplayDevice::startLine() {
return mCurrentLine = 0;
}
void DisplayDevice::highlight(uint32_t highlightTimeMillis) {
mHighlightTill = millis() + highlightTimeMillis;
if (!mHighlighted) {
setInversion(!mInverted);
mHighlighted = true;
}
}
void DisplayDevice::handleHighlight() {
if (mHighlighted && mHighlightTill < millis()) {
setInversion(mInverted);
mHighlighted = false;
}
}