-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChronoGui.cpp
262 lines (212 loc) · 8.19 KB
/
ChronoGui.cpp
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
/*
* ChronoGui.cpp
*
* Created on: 12/lug/2014
* Author: Tongo
*/
#include "ChronoGui.h"
#include "MainFont.h"
#include "LapTimeFont.h"
#include "fonts/Arial_bold_14.h"
#define TOP_ROW_X 0
#define TOP_ROW_Y 30
#define TOP_ROW_L 320
#define TOP_ROW_SEPARATOR_X 110
#define TOP_ROW_SEPARATOR_Y 0
#define TOP_ROW_SEPARATOR_H 30
#define BOTTOM_ROW_X 0
#define BOTTOM_ROW_Y 210
#define BOTTOM_ROW_L 320
#define BOTTOM_ROW_SEPARATOR_1_X 80
#define BOTTOM_ROW_SEPARATOR_1_Y 210
#define BOTTOM_ROW_SEPARATOR_1_H 30
#define BOTTOM_ROW_SEPARATOR_2_X 250
#define BOTTOM_ROW_SEPARATOR_2_Y 210
#define BOTTOM_ROW_SEPARATOR_2_H 30
#define GPS_INDICATOR_X 15
#define GPS_INDICATOR_Y 15
#define GPS_INDICATOR_R 10
#define GPS_SAT_TEXTBOX_X 50
#define GPS_SAT_TEXTBOX_Y 4
#define GPS_SAT_TEXTBOX_COL 85
#define GPS_SAT_TEXTBOX_ROW 26
#define LAP_TIME_TEXTBOX_X 24
#define LAP_TIME_TEXTBOX_Y 104
#define LAP_TIME_TEXTBOX_COL 215
#define LAP_TIME_TEXTBOX_ROW 145
#define LAP_COUNT_TEXTBOX_X 10
#define LAP_COUNT_TEXTBOX_Y 220
#define LAP_COUNT_TEXTBOX_COL 75
#define LAP_COUNT_TEXTBOX_ROW 235
#define LAP_DELAY_STATE_TEXTBOX_X 235
#define LAP_DELAY_STATE_TEXTBOX_Y 220
#define LAP_DELAY_STATE_TEXTBOX_COL 245
#define LAP_DELAY_STATE_TEXTBOX_ROW 235
#define LAP_DELAY_TEXTBOX_X 85
#define LAP_DELAY_TEXTBOX_Y 220
#define LAP_DELAY_TEXTBOX_COL 235
#define LAP_DELAY_TEXTBOX_ROW 235
#define TRACK_NAME_TEXTBOX_X 130
#define TRACK_NAME_TEXTBOX_Y 4
#define TRACK_NAME_TEXTBOX_COL 309
#define TRACK_NAME_TEXTBOX_ROW 26
#define PREV_TRACK_ROW_X1 112
#define PREV_TRACK_ROW_Y1 15
#define PREV_TRACK_ROW_X2 122
#define PREV_TRACK_ROW_Y2 10
#define PREV_TRACK_ROW_X3 122
#define PREV_TRACK_ROW_Y3 20
#define NEXT_TRACK_ROW_X1 320
#define NEXT_TRACK_ROW_Y1 15
#define NEXT_TRACK_ROW_X2 310
#define NEXT_TRACK_ROW_Y2 10
#define NEXT_TRACK_ROW_X3 310
#define NEXT_TRACK_ROW_Y3 20
ChronoGui::ChronoGui() {
this->tft = NULL;
this->timeTextBox = NULL;
}
void ChronoGui::initTft(ILI9341_due* tft) {
Serial.println("ChronoGui INIT - START");
this->tft = tft;
this->tft->setRotation(iliRotation270);
//this->tft->setRotation(3); // Landscape right
this->tft->fillScreen(ILI9341_BLACK);
// TOP SEPARATOR ROW
this->tft->ILI9341_due::drawFastHLine(TOP_ROW_X, TOP_ROW_Y, TOP_ROW_L, ILI9341_WHITE);
this->tft->ILI9341_due::drawFastVLine(TOP_ROW_SEPARATOR_X, TOP_ROW_SEPARATOR_Y, TOP_ROW_SEPARATOR_H, ILI9341_WHITE);
this->tft->ILI9341_due::drawFastHLine(BOTTOM_ROW_X, BOTTOM_ROW_Y, BOTTOM_ROW_L, ILI9341_WHITE);
this->tft->ILI9341_due::drawFastVLine(BOTTOM_ROW_SEPARATOR_1_X, BOTTOM_ROW_SEPARATOR_1_Y, BOTTOM_ROW_SEPARATOR_1_H, ILI9341_WHITE);
this->tft->ILI9341_due::drawFastVLine(BOTTOM_ROW_SEPARATOR_2_X, BOTTOM_ROW_SEPARATOR_2_Y, BOTTOM_ROW_SEPARATOR_2_H, ILI9341_WHITE);
// GPS satellite number
this->gpsSatTextBox = new ILI9341_due_gText(this->tft);
this->gpsSatTextBox->defineArea(GPS_SAT_TEXTBOX_X, GPS_SAT_TEXTBOX_Y, GPS_SAT_TEXTBOX_COL, GPS_SAT_TEXTBOX_ROW);
this->gpsSatTextBox->selectFont(Arial_bold_14);
this->gpsSatTextBox->setFontLetterSpacing(5);
this->gpsSatTextBox->setFontColor(ILI9341_WHITE, ILI9341_BLACK);
// Track name
this->trackNameTextBox = new ILI9341_due_gText(this->tft);
this->trackNameTextBox->defineArea(TRACK_NAME_TEXTBOX_X, TRACK_NAME_TEXTBOX_Y, TRACK_NAME_TEXTBOX_COL, TRACK_NAME_TEXTBOX_ROW);
this->trackNameTextBox->selectFont(Arial_bold_14);
this->trackNameTextBox->setFontLetterSpacing(5);
this->trackNameTextBox->setFontColor(ILI9341_WHITE, ILI9341_BLACK);
// Prev - Next Track triangle button
this->tft->drawTriangle(PREV_TRACK_ROW_X1, PREV_TRACK_ROW_Y1, PREV_TRACK_ROW_X2, PREV_TRACK_ROW_Y2, PREV_TRACK_ROW_X3, PREV_TRACK_ROW_Y3, ILI9341_WHITE);
this->tft->drawTriangle(NEXT_TRACK_ROW_X1, NEXT_TRACK_ROW_Y1, NEXT_TRACK_ROW_X2, NEXT_TRACK_ROW_Y2, NEXT_TRACK_ROW_X3, NEXT_TRACK_ROW_Y3, ILI9341_WHITE);
// Time box
this->timeTextBox = new ILI9341_due_gText(this->tft);
this->timeTextBox->defineArea(LAP_TIME_TEXTBOX_X, LAP_TIME_TEXTBOX_Y, LAP_TIME_TEXTBOX_COL, LAP_TIME_TEXTBOX_ROW);
this->timeTextBox->selectFont(lapTimeFont);
this->timeTextBox->setFontLetterSpacing(5);
this->timeTextBox->setFontColor(ILI9341_WHITE, ILI9341_BLACK);
// Lap counter
this->lapCountTextBox = new ILI9341_due_gText(this->tft);
this->lapCountTextBox->defineArea(LAP_COUNT_TEXTBOX_X, LAP_COUNT_TEXTBOX_Y, LAP_COUNT_TEXTBOX_COL, LAP_COUNT_TEXTBOX_ROW);
this->lapCountTextBox->selectFont(Arial_bold_14);
this->lapCountTextBox->setFontLetterSpacing(5);
this->lapCountTextBox->setFontColor(ILI9341_WHITE, ILI9341_BLACK);
// Lap delay State
this->lapDelayStateTextBox = new ILI9341_due_gText(this->tft);
this->lapDelayStateTextBox->defineArea(LAP_DELAY_STATE_TEXTBOX_X, LAP_DELAY_STATE_TEXTBOX_Y, LAP_DELAY_STATE_TEXTBOX_COL, LAP_DELAY_STATE_TEXTBOX_ROW);
this->lapDelayStateTextBox->selectFont(Arial_bold_14);
this->lapDelayStateTextBox->setFontLetterSpacing(5);
this->lapDelayStateTextBox->setFontColor(ILI9341_WHITE, ILI9341_BLACK);
// Lap delay BEST / LAST
this->lapDelayTextBox = new ILI9341_due_gText(this->tft);
this->lapDelayTextBox->defineArea(LAP_DELAY_TEXTBOX_X, LAP_DELAY_TEXTBOX_Y, LAP_DELAY_TEXTBOX_COL, LAP_DELAY_TEXTBOX_ROW);
this->lapDelayTextBox->selectFont(Arial_bold_14);
this->lapDelayTextBox->setFontLetterSpacing(5);
Serial.println("ChronoGui INIT - FINISH");
}
void ChronoGui::updateLapTime(long lapTime) {
uint16_t mins = 0;
uint16_t secs = 0;
uint16_t cents = 0;
cents = lapTime / 10;
secs = lapTime / 1000; //convect milliseconds to seconds
mins = secs / 60; //convert seconds to minutes
cents = cents - (secs * 100);
secs = secs - (mins * 60); //subtract the coverted seconds to minutes in order to display 59 secs max
cents = cents / 10;
char textBuff[20];
char secBuffer[2];
char centsBuffer[2];
sprintf(textBuff, "%d", mins);
strcat (textBuff, "\'");
sprintf(secBuffer, "%d", secs);
if(secs < 10) {
strcat (textBuff, "0");
}
strcat (textBuff, secBuffer);
strcat (textBuff, "\"");
sprintf(centsBuffer, "%d", cents);
strcat (textBuff, centsBuffer);
this->timeTextBox->drawString(textBuff, gTextAlignTopLeft);
}
void ChronoGui::updateLapNumber(int lapCount) {
this->lapCountTextBox->clearArea(ILI9341_BLACK);
if(lapCount > 0) {
char textBuff[6];
sprintf(textBuff, "%d lap", lapCount);
this->lapCountTextBox->drawString(textBuff, gTextAlignMiddleRight);
} else {
this->lapCountTextBox->drawString("--", gTextAlignMiddleRight);
}
}
void ChronoGui::updateGpsFixState(bool gpsState) {
if(gpsState) {
this->tft->fillCircle(GPS_INDICATOR_X, GPS_INDICATOR_Y, GPS_INDICATOR_R, ILI9341_GREEN);
} else {
this->tft->fillCircle(GPS_INDICATOR_X, GPS_INDICATOR_Y, GPS_INDICATOR_R, ILI9341_RED);
}
this->tft->drawCircle(GPS_INDICATOR_X, GPS_INDICATOR_Y, GPS_INDICATOR_R, ILI9341_WHITE);
}
void ChronoGui::updateGpsSatelliteNumber(int8_t satelliteNumber) {
this->gpsSatTextBox->clearArea(ILI9341_BLACK);
if(satelliteNumber > 0) {
char textBuff[7];
sprintf(textBuff, "%d sat", satelliteNumber);
this->gpsSatTextBox->drawString(textBuff, gTextAlignMiddleRight);
} else {
this->gpsSatTextBox->drawString(":(", gTextAlignMiddleRight);
}
}
void ChronoGui::updateTrackName(char* trackName) {
this->trackNameTextBox->clearArea(ILI9341_BLACK);
this->trackNameTextBox->drawString(trackName, gTextAlignMiddleCenter);
}
void ChronoGui::updateLapDelayState(bool bestLapDelay) {
if(bestLapDelay) {
this->lapDelayStateTextBox->drawString("B", gTextAlignMiddleRight);
} else {
this->lapDelayStateTextBox->drawString("L", gTextAlignMiddleRight);
}
}
void ChronoGui::updateLapDelay(long delay) {
bool positive = (delay > 0);
delay = abs(delay);
uint16_t secs = 0;
uint16_t cents = 0;
secs = delay / 1000;
cents = delay / 10;
cents = cents - (secs * 100);
char textBuff[10];
char centsBuffer[2];
if(positive) {
this->lapDelayTextBox->setFontColor(ILI9341_RED, ILI9341_BLACK);
sprintf(textBuff, "+ %d.", secs);
} else {
this->lapDelayTextBox->setFontColor(ILI9341_GREEN, ILI9341_BLACK);
sprintf(textBuff, "- %d.", secs);
}
sprintf(centsBuffer, "%d", cents);
if(cents < 10) {
strcat (textBuff, "0");
}
strcat (textBuff, centsBuffer);
this->lapDelayTextBox->clearArea(ILI9341_BLACK);
this->lapDelayTextBox->drawString(textBuff, gTextAlignMiddleCenter);
}
void ChronoGui::updateGearCounter(uint8_t gear) {
// TODO
}