-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay.cpp
More file actions
740 lines (636 loc) · 19.4 KB
/
display.cpp
File metadata and controls
740 lines (636 loc) · 19.4 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
#include "Arduino.h"
#include "display.hh"
#include "messaging.hh"
#include "featherwing_touch.hh"
#include "state.hh"
#include <SPI.h>
#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char *sbrk(int incr);
#else // __ARM__
extern char *__brkval;
#endif // __arm__
int freeMemory()
{
char top;
#ifdef __arm__
return &top - reinterpret_cast<char *>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
return &top - __brkval;
#else // __arm__
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__
}
template <typename T>
int sgn(T val)
{
return (T(0) < val) - (val < T(0));
}
#define HX8357_CUST_GRAY 0x9CD3
#define CANVAS_NUM_H 45
#define CANVAS_NUM_W 160
#define CANVAS_NUM_UL_X 5
#define CANVAS_NUM_UL_Y 35
#define CANVAS_NUM_LARGE_H 50
#define CANVAS_NUM_LARGE_W 160
#define CANVAS_NUM_LARGE_UL_X 5
#define CANVAS_NUM_LARGE_UL_Y 45
#define CANVAS_CENTER_H 60
#define CANVAS_CENTER_W 200
#define CANVAS_LABEL_H 20
#define CANVAS_LABEL_W 160
#define RADIO_BUTTON_H 30
#define RADIO_BUTTON_V 50
#define RADIO_BUTTON_RAD 1
#define RADIO_BUTTON_POS_Y 90
#define RADIO_BUTTON_TXTPOS_Y (RADIO_BUTTON_POS_Y + 20)
#define DATA_RADIO_ACT_POS_X 0
#define DATA_RADIO_ACT_POS_Y 25
#define LABEL_RADIO_ACT_POS_X 0
#define LABEL_RADIO_ACT_POS_Y 5
#define DATA_RADIO_STANDBY_POS_X 160
#define DATA_RADIO_STANDBY_POS_Y 25
#define LABEL_RADIO_STANDBY_POS_X 160
#define LABEL_RADIO_STANDBY_POS_Y 5
#define DATA_ALT_POS_X 0
#define DATA_ALT_POS_Y 180
#define LABEL_ALT_POS_X 0
#define LABEL_ALT_POS_Y 160
#define DATA_SPEED_POS_X 160
#define DATA_SPEED_POS_Y 180
#define LABEL_SPEED_POS_X 160
#define LABEL_SPEED_POS_Y 160
#define DATA_HDG_POS_X 0
#define DATA_HDG_POS_Y 265
#define LABEL_HDG_POS_X 0
#define LABEL_HDG_POS_Y 245
#define DATA_IAS_POS_X 160
#define DATA_IAS_POS_Y 265
#define LABEL_IAS_POS_X 160
#define LABEL_IAS_POS_Y 245
#define DATA_XPDR_POS_X 0
#define DATA_XPDR_POS_Y 360
#define LABEL_XPDR_POS_X 0
#define LABEL_XPDR_POS_Y 340
#define DATA_BARO_POS_X 160
#define DATA_BARO_POS_Y 360
#define LABEL_BARO_POS_X 160
#define LABEL_BARO_POS_Y 340
#define CENTER_LABEL_POS_X 60
#define CENTER_LABEL_POS_Y 160
#define DECIMAL_PAD 5
#define DEBUG_STR_LENGTH 25
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
Display::Display() : cCenter(CANVAS_CENTER_W, CANVAS_CENTER_H),
lcd(TFT_CS, TFT_DC, TFT_RST),
ts(STMPE_CS)
{
}
void Display::initDisplay()
{
// LCD SETUP
lcd.begin();
lcd.fillScreen(HX8357_BLACK); // initialize the lcd
lcd.setRotation(0);
lcd.setTextSize(1);
// Start Touch Screen
ts.begin();
cCenter.fillScreen(HX8357_BLACK);
cCenter.setFont(font_var_title.normal);
cCenter.setCursor(5, 50);
cCenter.print(F("Initializing"));
lcd.drawBitmap(CENTER_LABEL_POS_X, CENTER_LABEL_POS_Y, cCenter.getBuffer(), CANVAS_CENTER_W, CANVAS_CENTER_H, HX8357_WHITE);
}
TouchEvent Display::processTouch()
{
int8_t nav_sel = -1;
int8_t crs_sel = -1;
int8_t speed_sel = -1;
int8_t baro_sel = -1;
if (!ts.bufferEmpty())
{
while (!ts.bufferEmpty())
{
TS_Point p = ts.getPoint();
p.x = map(p.x, TS_MINX, TS_MAXX, 0, lcd.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, lcd.height());
if (p.y > RADIO_BUTTON_POS_Y && p.y < (RADIO_BUTTON_POS_Y + RADIO_BUTTON_H))
{
for (int i = 0; i < 5; i++)
{
if (p.x > (15 + (RADIO_BUTTON_V + 10) * i) && p.x < (5 + (RADIO_BUTTON_V + 10) * (i + 1)))
{
if (state.debug)
lcd.drawCircle(p.x, p.y, 1, HX8357_CYAN);
nav_sel = i;
}
}
}
// CRS Selector
else if (p.y > 235 && p.y < 320 && p.x < 160)
{
if (state.debug)
lcd.drawCircle(p.x, p.y, 1, HX8357_CYAN);
crs_sel = 1;
}
// Baro Selector
else if (p.y > 340 && p.y < 415 && p.x > 160)
{
if (state.debug)
lcd.drawCircle(p.x, p.y, 1, HX8357_CYAN);
baro_sel = 1;
}
}
if (nav_sel > -1 && (nav_sel != state.radio.sel))
{
state.radio.sel = nav_sel;
update.radio_select_buttons = true;
return TouchEvent(TouchEventType::NAV_BUTTON, state.radio.sel);
}
else if (crs_sel > -1)
{
state.nav.crs_sel = (state.nav.crs_sel + 1) % this->crs_labels;
update.hdg = true;
return TouchEvent(TouchEventType::CRS_BUTTON, state.nav.crs_sel);
}
else if (baro_sel > -1)
{
state.nav.baro_mode_sel = (state.nav.baro_mode_sel + 1) % this->baro_labels;
update.baro = true;
return TouchEvent(TouchEventType::BARO_BUTTON, state.nav.baro_mode_sel);
}
else
{
return TouchEvent();
}
}
else
{
return TouchEvent();
}
}
void Display::clearTouch()
{
while (!ts.bufferEmpty())
{
ts.getPoint();
}
}
void Display::printSplash(String str)
{
state.display_static = false;
lcd.fillScreen(HX8357_BLACK);
cCenter.fillScreen(HX8357_BLACK);
cCenter.setFont(font_var_title.normal);
cCenter.setCursor(5, 50);
cCenter.print(str);
lcd.drawBitmap(CENTER_LABEL_POS_X, CENTER_LABEL_POS_Y, cCenter.getBuffer(), CANVAS_CENTER_W, CANVAS_CENTER_H, HX8357_WHITE);
}
void Display::printStatic()
{
lcd.fillScreen(HX8357_BLACK); // initialize the lcd
lcd.setTextColor(HX8357_GREEN);
lcd.setFont(font_var_lbl.normal);
this->drawLabel(LABEL_RADIO_ACT_POS_X, LABEL_RADIO_ACT_POS_Y, F("Active"));
this->drawLabel(LABEL_RADIO_STANDBY_POS_X, LABEL_RADIO_STANDBY_POS_Y, F("Standby"));
lcd.drawFastHLine(0, 145, 320, HX8357_WHITE);
this->drawLabel(LABEL_ALT_POS_X, LABEL_ALT_POS_Y, F("Altitude"));
lcd.drawFastHLine(0, 230, 320, HX8357_WHITE);
lcd.drawFastHLine(0, 325, 320, HX8357_WHITE);
this->drawLabel(LABEL_XPDR_POS_X, LABEL_XPDR_POS_Y, F("XPDR"));
lcd.drawFastHLine(0, 410, 320, HX8357_WHITE);
state.display_static = true;
state.display_off = false;
}
void Display::drawRadioSelectButton(uint8_t active)
{
uint16_t colors[5] = {HX8357_CUST_GRAY, HX8357_CUST_GRAY, HX8357_CUST_GRAY, HX8357_CUST_GRAY, HX8357_CUST_GRAY};
colors[active] = HX8357_WHITE;
lcd.setTextColor(HX8357_BLACK);
lcd.setFont(font_var_lbl_b.normal);
uint8_t button_pos_v = 0;
for (int i = 0; i < 5; i++)
{
button_pos_v = 15 + (RADIO_BUTTON_V + 10) * i;
lcd.fillRoundRect(button_pos_v, RADIO_BUTTON_POS_Y, RADIO_BUTTON_V, RADIO_BUTTON_H, RADIO_BUTTON_RAD, colors[i]);
lcd.setCursor(button_pos_v + 5, RADIO_BUTTON_TXTPOS_Y);
lcd.print(F(RADIO_BUTTON_LABEL[i]));
}
update.radio_select_buttons = false;
}
void Display::drawLabel(uint16_t x, uint16_t y, const char *label)
{
GFXcanvas1 canvas(CANVAS_LABEL_W, CANVAS_LABEL_H);
canvas.setFont(font_var_lbl.normal);
canvas.setCursor(5, 15);
canvas.printf("%s", label);
lcd.drawBitmap(x, y, canvas.getBuffer(), CANVAS_LABEL_W, CANVAS_LABEL_H, HX8357_GREEN, HX8357_BLACK);
}
void Display::drawLabel(uint16_t x, uint16_t y, String label)
{
this->drawLabel(x, y, label.c_str());
}
void Display::redraw(bool full)
{
if (update.radio_active || full)
drawRadioActive();
if (update.radio_standby || full)
drawRadioStandby();
if (update.radio_select_buttons || full)
drawRadioSelectButton(state.radio.sel);
if (update.alt || full)
drawAltitude();
if (update.vs_lbl || full)
drawVSLabel();
if (update.vs || full)
drawVS();
if (update.ias_lbl || full)
drawIASLabel();
if (update.ias || full)
drawIAS();
if (update.hdg || full)
drawHeading();
if (update.hdg_lbl || full)
drawHeadingLabel();
if (update.xpdr || full)
drawTransponderCode();
if (update.baro || full)
drawBarometer();
}
void Display::updateAltitude()
{
update.alt = true;
}
void Display::drawAltitude()
{
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
canvas.setFont(font_mono_val_s.normal);
canvas.setCursor(CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y);
if (state.nav.alt.value != 0)
{
canvas.printf("%5i", (uint16_t)state.nav.alt.value);
}
else
{
printDash(5, &canvas, &font_mono_val_s);
}
if (state.nav.alt.dot == true)
{
canvas.setFont(font_mono_val_s.dot);
canvas.printf(SYM_DOT);
}
lcd.drawBitmap(DATA_ALT_POS_X, DATA_ALT_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_WHITE, HX8357_BLACK);
update.alt = false;
}
void Display::updateVS()
{
update.vs = true;
}
void Display::updateVSLabel()
{
update.vs_lbl = true;
update.vs = true;
}
void Display::drawVSLabel()
{
if (state.nav.vs.label.length() > 0)
{
this->drawLabel(LABEL_SPEED_POS_X, LABEL_SPEED_POS_Y, state.nav.vs.label);
}
else
{
this->drawLabel(LABEL_SPEED_POS_X, LABEL_SPEED_POS_Y, VS_LABEL[0]);
}
update.vs_lbl = false;
}
void Display::drawVS()
{
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
canvas.setFont(font_mono_val_s.normal);
canvas.setCursor(CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y);
if (state.nav.vs.dashes)
{
printDash(5, &canvas, &font_mono_val_s);
}
else if (fabsf(state.nav.vs.value) > 10.0) // VS
{
this->trimDecimal(state.nav.vs.value, 4, 0, false, true, CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y, &canvas, &font_mono_val_s);
}
else // FPA
{
this->trimDecimal(state.nav.vs.value, 1, 1, false, true, CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y, &canvas, &font_mono_val_s);
}
lcd.drawBitmap(DATA_SPEED_POS_X, DATA_SPEED_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_CYAN, HX8357_BLACK);
update.vs = false;
}
void Display::updateIAS()
{
update.ias = true;
}
void Display::updateIASLabel()
{
update.ias_lbl = true;
update.ias = true;
}
void Display::drawIASLabel()
{
if (state.nav.ias.label.length() > 0)
{
this->drawLabel(LABEL_IAS_POS_X, LABEL_IAS_POS_Y, state.nav.ias.label);
}
else
{
this->drawLabel(LABEL_IAS_POS_X, LABEL_IAS_POS_Y, IAS_LABEL[0]);
}
update.ias_lbl = false;
}
void Display::drawIAS()
{
GFXcanvas1 canvas(CANVAS_NUM_LARGE_W, CANVAS_NUM_LARGE_H);
canvas.setFont(font_mono_val_l.normal);
canvas.setCursor(CANVAS_NUM_LARGE_UL_X, CANVAS_NUM_LARGE_UL_Y);
if (state.nav.ias.value > 0 and state.nav.ias.value <= 2)
{
this->trimDecimal(state.nav.ias.value, 1, 2, false, false, CANVAS_NUM_LARGE_UL_X, CANVAS_NUM_LARGE_UL_Y, &canvas, &font_mono_val_l);
}
else if (state.nav.ias.value > 2)
{
canvas.printf("%3i", (uint16_t)state.nav.ias.value); // IAS
}
else
{
printDash(3, &canvas, &font_mono_val_l);
}
if (state.nav.ias.dot == true)
{
canvas.setFont(font_mono_val_l.dot);
canvas.printf(SYM_DOT);
}
lcd.drawBitmap(DATA_IAS_POS_X, DATA_IAS_POS_Y, canvas.getBuffer(), CANVAS_NUM_LARGE_W, CANVAS_NUM_LARGE_H, HX8357_CYAN, HX8357_BLACK);
update.ias = false;
}
void Display::updateHeading()
{
update.hdg = true;
}
void Display::updateHeadingLabel()
{
update.hdg_lbl = true;
}
void Display::drawHeading()
{
int16_t print_hdg;
if (state.nav.hdg.value == 0)
print_hdg = 360;
else
print_hdg = state.nav.hdg.value;
GFXcanvas1 canvas(CANVAS_NUM_LARGE_W, CANVAS_NUM_LARGE_H);
canvas.setFont(font_mono_val_l.normal);
canvas.setCursor(CANVAS_NUM_LARGE_UL_X, CANVAS_NUM_LARGE_UL_Y);
if (state.nav.hdg.dashes == true || state.nav.hdg.value < 0)
{
printDash(3, &canvas, &font_mono_val_l);
}
else
{
canvas.printf("%03i", print_hdg);
if (state.nav.hdg.dot == false)
{
canvas.setFont(font_mono_val_l.deg);
canvas.printf(SYM_DEG);
}
}
if (state.nav.hdg.dot == true)
{
canvas.setFont(font_mono_val_l.dot);
canvas.printf(SYM_DOT);
}
lcd.drawBitmap(DATA_HDG_POS_X, DATA_HDG_POS_Y, canvas.getBuffer(), CANVAS_NUM_LARGE_W, CANVAS_NUM_LARGE_H, HX8357_WHITE, HX8357_BLACK);
update.hdg = false;
}
void Display::drawHeadingLabel()
{
if (state.nav.hdg.label.length() > 0)
{
this->drawLabel(LABEL_HDG_POS_X, LABEL_HDG_POS_Y, state.nav.hdg.label);
}
else
{
this->drawLabel(LABEL_HDG_POS_X, LABEL_HDG_POS_Y, CRS_LABEL[state.nav.crs_sel]);
}
update.hdg_lbl = false;
}
void Display::updateTransponderCode()
{
update.xpdr = true;
}
void Display::drawTransponderCode()
{
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
canvas.setFont(font_mono_val_s.normal);
canvas.setCursor(CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y);
if (state.radio.xpdr != 0)
{
canvas.printf("%04i", state.radio.xpdr);
}
else
{
printDash(4, &canvas, &font_mono_val_s);
}
lcd.drawBitmap(DATA_XPDR_POS_X, DATA_XPDR_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_WHITE, HX8357_BLACK);
update.xpdr = false;
}
void Display::updateBarometer()
{
update.baro = true;
}
void Display::updateBarometerLabel(uint8_t selection)
{
lcd.setFont(font_var_lbl.normal);
lcd.setTextColor(HX8357_BLACK);
lcd.setCursor(165, 355);
lcd.printf("%s ", BARO_LABEL[(selection + (this->baro_labels - 1)) % this->baro_labels]);
lcd.setTextColor(HX8357_GREEN);
lcd.setCursor(165, 355);
lcd.printf("%s ", BARO_LABEL[selection]);
update.baro = true;
}
void Display::drawBarometer()
{
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
canvas.setFont(font_mono_val_s.normal);
canvas.setCursor(CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y);
if (state.nav.baro < 1.0)
{
printDash(4, &canvas, &font_mono_val_s);
lcd.drawBitmap(DATA_BARO_POS_X, DATA_BARO_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_CYAN, HX8357_BLACK);
}
else if (state.nav.baro_mode_sel == 1)
{
this->trimDecimal(state.nav.baro, 2, 2, true, false, CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y, &canvas, &font_mono_val_s);
lcd.drawBitmap(DATA_BARO_POS_X, DATA_BARO_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_CYAN, HX8357_BLACK);
}
else
{
canvas.printf("%4i", (int16_t)state.nav.baro); // hPa
lcd.drawBitmap(DATA_BARO_POS_X, DATA_BARO_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_CYAN, HX8357_BLACK);
}
update.baro = false;
}
void Display::updateActiveRadio()
{
update.radio_active = true;
update.radio_standby = true;
update.radio_select_buttons = true;
}
void Display::updateRadioFrequencyActive()
{
update.radio_active = true;
}
void Display::updateRadioFrequencyStandby()
{
update.radio_standby = true;
}
void Display::drawRadioActive()
{
uint8_t frac_digits = 3;
uint8_t pad_digits = 3;
if (state.radio.sel <= 1)
frac_digits = 2;
else if (state.radio.sel == 4)
{
pad_digits = 4;
frac_digits = 1;
}
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
this->trimDecimal(state.radio.freq.active, pad_digits, frac_digits, true, false, CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y, &canvas, &font_mono_val_s);
lcd.drawBitmap(DATA_RADIO_ACT_POS_X, DATA_RADIO_ACT_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_WHITE, HX8357_BLACK);
update.radio_active = false;
}
void Display::drawRadioStandby()
{
uint8_t frac_digits = 3;
uint8_t pad_digits = 3;
if (state.radio.sel <= 1)
frac_digits = 2;
else if (state.radio.sel == 4)
{
frac_digits = 1;
pad_digits = 4;
}
GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
this->trimDecimal(state.radio.freq.standby, pad_digits, frac_digits, true, false, CANVAS_NUM_UL_X, CANVAS_NUM_UL_Y, &canvas, &font_mono_val_s);
lcd.drawBitmap(DATA_RADIO_STANDBY_POS_X, DATA_RADIO_STANDBY_POS_Y, canvas.getBuffer(), CANVAS_NUM_W, CANVAS_NUM_H, HX8357_CYAN, HX8357_BLACK);
update.radio_standby = false;
}
void Display::printLastCommand(uint8_t command, uint8_t idx, int32_t val)
{
this->printLastCommand(command, idx, String(val));
}
void Display::printLastCommand(uint8_t command, uint8_t idx, const String val)
{
lcd.setTextColor(HX8357_CYAN, HX8357_BLACK);
lcd.setFont(NULL);
lcd.setCursor(5, 465);
dbg_str = F("Cmd: ");
dbg_str.concat((int)command);
dbg_str.concat(' ');
dbg_str.concat((int)idx);
dbg_str.concat(' ');
dbg_str.concat(val);
while (dbg_str.length() < DEBUG_STR_LENGTH)
{
dbg_str.concat(' ');
}
lcd.printf("%s", dbg_str.substring(0, min(dbg_str.length(), DEBUG_STR_LENGTH) - 1).c_str());
}
void Display::printMem()
{
lcd.setTextColor(HX8357_CYAN, HX8357_BLACK);
lcd.setFont(NULL);
lcd.setCursor(5, 455);
lcd.printf("Mem: %d ", freeMemory());
}
void Display::printDebug(String msg)
{
lcd.setTextColor(HX8357_CYAN, HX8357_BLACK);
lcd.setFont(NULL);
lcd.setCursor(165, 465);
lcd.printf(msg.c_str());
}
void Display::trimDecimal(float_t num, uint8_t padding, uint8_t decimals, bool dashes, bool force_sign, int x, int y, GFXcanvas1 *canvas, const Fonts *font)
{
const float_t COMP_EPSILON = 1.0 / pow(10, decimals + 1);
// GFXcanvas1 canvas(CANVAS_NUM_W, CANVAS_NUM_H);
String num_str = "";
bool negative = (sgn(num) == -1);
if (fabsf(num) < COMP_EPSILON && dashes)
{
for (int i = 0; i < padding; i++)
num_str.concat('-');
num_str.concat('.');
for (int i = 0; i < decimals; i++)
num_str.concat('-');
canvas->setFont(font->normal);
}
else
{
num_str.concat(String(fabsf(num), decimals));
canvas->setFont(font->normal);
}
String num_str_int = getStringValue(num_str, '.', 0);
String num_str_int_pad;
if (force_sign && !negative)
{
num_str_int_pad.concat('+');
}
else if (negative)
{
num_str_int_pad.concat('-');
}
uint8_t pads = padding - num_str_int.length();
for (int i = 0; i < pads; i++)
{
num_str_int_pad.concat('0');
}
num_str_int_pad.concat(num_str_int);
if (decimals > 0)
num_str_int_pad.concat('.');
String num_str_frac = getStringValue(num_str, '.', 1);
canvas->setCursor(x, y);
int16_t x1, y1;
uint16_t w, h;
canvas->getTextBounds(num_str_int_pad.c_str(), x, y, &x1, &y1, &w, &h); // calc width of new string
canvas->printf("%s", num_str_int_pad.c_str());
canvas->setCursor(x + w + DECIMAL_PAD, y);
canvas->printf("%s", num_str_frac.c_str());
return;
}
void Display::printDash(uint8_t num, GFXcanvas1 *canvas, const Fonts *font)
{
canvas->setFont(font->dash);
for (uint8_t i = 0; i < num; i++)
{
canvas->print('-');
}
}
// https://stackoverflow.com/questions/9072320/split-string-into-string-array
String Display::getStringValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++)
{
if (data.charAt(i) == separator || i == maxIndex)
{
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}