-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
UI.h
1668 lines (1419 loc) · 50.2 KB
/
UI.h
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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _UI_H_
#define _UI_H_
#include "./Config.h"
#ifdef USE_RTC
#include "modules/RTC/DS1307RTC.h" // a custom DS1307 library that returns time as a time_t
DS1307_RTC RTC;
static time_t RTCGet()
{
return RTC.get();
}
#else
//#include <Time.h>
#include <TimeLib.h>
#endif
void M5Begin()
{
#ifndef LGFX_ONLY
if( SERIAL_SPEED != 115200 ) {
Serial.begin( SERIAL_SPEED );
M5.begin(true, SD_ENABLE, false);
} else {
M5.begin();
}
#else
Serial.begin( SERIAL_SPEED );
Serial.printf("Custom ESP32 started at %d bauds!", SERIAL_SPEED);
setDisplayPins();
tft.setPanel(&panel);
tft.init();
#endif
}
#include "modules/SpriteSheet/SpriteSheet.h"
#ifdef DCF77_DO_WEATHER
#include <Preferences.h>
Preferences prefs;
static int maxEntriesPerPage = 10;
static int entriesIndex = -1;
static bool pickedCity = false;
static unsigned long pickerTimeout = 5000;
static unsigned long beforePicking = millis();
String preferredCountry = "";
String preferredCity = "";
#endif
#ifdef USE_SPEAKER
SPEAKER Speaker;
#endif
#define freeheap heap_caps_get_free_size( MALLOC_CAP_INTERNAL )
static xSemaphoreHandle mux = NULL; // this is needed to prevent rendering collisions
// between scrollpanel and heap graph
#define takeMuxSemaphore() if( mux ) { xSemaphoreTake( mux, portMAX_DELAY ); log_v( "Took Semaphore" ); }
#define giveMuxSemaphore() if( mux ) { xSemaphoreGive( mux ); log_v( "Gave Semaphore" ); }
// this is just lgfx::TextStyle with a constructor
struct TextStyle
{
std::uint32_t fore_rgb888 = 0xFFFFFFU;
std::uint32_t back_rgb888 = 0;
float size_x = 1;
float size_y = 1;
textdatum_t datum = textdatum_t::top_left;
bool utf8 = true;
bool cp437 = false;
// constructor
TextStyle( std::uint32_t _fore_rgb888, std::uint32_t _back_rgb888, float _size_x, float _size_y, textdatum_t _datum, bool _utf8, bool _cp437 ) :
fore_rgb888( _fore_rgb888 ), back_rgb888( _back_rgb888 ), size_x( _size_x ), size_y( _size_y ), datum( _datum ), utf8( _utf8 ), cp437( _cp437 ) { }
void setFgColor( std::uint32_t color ) { fore_rgb888 = color; }
void setBgColor( std::uint32_t color ) { back_rgb888 = color; }
void setSizeX( float size ) { size_x = size; }
void setSizeY( float size ) { size_y = size; }
void setTextDatum( textdatum_t newdatum ) { datum = newdatum; }
};
struct FontStyle
{
const lgfx::IFont* font;
TextStyle *style;
// constructor
FontStyle( const lgfx::IFont *_font, TextStyle *_style ) : font( _font ), style( _style ) { }
// style setter
void setTextStyle( TextStyle *_style ) {
style = _style;
}
};
struct BoxStyle
{
const std::uint32_t fillColor;
FontStyle* style;
BoxStyle( const std::uint32_t f, FontStyle *s ) : fillColor(f), style(s) { }
};
// helper for setFontStyle
void setTextStyle( DCFDisplay *_tft, TextStyle *style )
{
lgfx::TextStyle myStyle; // why no constructor ??
myStyle.fore_rgb888 = style->fore_rgb888;
myStyle.back_rgb888 = style->back_rgb888;
myStyle.size_x = style->size_x;
myStyle.size_y = style->size_y;
myStyle.datum = style->datum;
myStyle.utf8 = style->utf8;
myStyle.cp437 = style->cp437;
_tft->setTextStyle( myStyle );
}
void setFontStyle( DCFDisplay *_tft, FontStyle *myFontStyle )
{
_tft->setFont( myFontStyle->font );
setTextStyle( _tft, myFontStyle->style );
}
// helper for setFontStyle
void setTextStyle( LGFX_Sprite *sprite, TextStyle *style )
{
lgfx::TextStyle myStyle; // why no constructor ??
myStyle.fore_rgb888 = style->fore_rgb888;
myStyle.back_rgb888 = style->back_rgb888;
myStyle.size_x = style->size_x;
myStyle.size_y = style->size_y;
myStyle.datum = style->datum;
myStyle.utf8 = style->utf8;
myStyle.cp437 = style->cp437;
sprite->setTextStyle( myStyle );
}
void setFontStyle( LGFX_Sprite *sprite, FontStyle *myFontStyle )
{
sprite->setFont( myFontStyle->font );
setTextStyle( sprite, myFontStyle->style );
}
#if defined UI_320x240
#include "themes/UI_320x240.h"
#elif defined UI_160x128
#include "themes/UI_160x128.h"
#else
#error "Please define either UI_320x240 or UI_160x128"
#endif
#include "modules/DCF77/DCF77.h"
static LGFX_Sprite sprite = LGFX_Sprite( &tft );
#ifdef DCF77_DO_WEATHER
static LGFX_Sprite ScrollSprite = LGFX_Sprite( &tft );
#endif
static LGFX_Sprite MainSprite = LGFX_Sprite( &tft );
static LGFX_Sprite MaskSprite = LGFX_Sprite( &tft );
static LGFX_Sprite LogoSprite = LGFX_Sprite( &sprite );
static uint16_t TFT_HALFWIDTH;// tft.width()/2
static uint16_t TFT_HALFHEIGHT;// tft.height()/2
static uint16_t RingLabelsFontHeight = 0;
static uint16_t RingLabelsFontWidth = 0;
static uint16_t ErrorsCountFontHeight = 0;
static uint16_t ErrorsCountFontWidth = 0;
static uint16_t tmpFontHeight = 0;
static uint16_t tmpFontWidth = 0;
static uint16_t LedWeekStatusFontWidth = 0;
static uint16_t LedWeekStatusFontHeight = 0;
static uint16_t LedErrorStatusFontWidth = 0;
static uint16_t LedErrorStatusFontHeight = 0;
static uint16_t LedParityStatusFontWidth = 0;
static uint16_t LedParityStatusFontHeight = 0;
static uint16_t LedDCFStatusFontWidth = 0;
static uint16_t LedDCFStatusFontHeight = 0;
static uint16_t LedDisplayFontHeight = 0;
//static uint16_t BufferFontHeight = 0;
static uint16_t RTCDateFontHeight = 0;
//static uint16_t timeColor;
static uint16_t weekDayNamesWidth = 0;
static uint16_t CETWidth = 0;
static uint16_t CETXPos = 0;
static uint16_t CESTWidth = 0;
static uint16_t CESTXpos = 0;
static uint16_t LEAPWidth = 0;
static uint16_t LEAPXPos = 0;
int16_t x, y;
uint16_t w, h;
float MinuteSteps = ( TWO_PI / 60 ) / 5;
float r1 = float_r1; // inner ring
float r2 = float_r2; // outer ring
float r3 = float_r3; // inner 10's mark
float r4 = float_r4; // inner 10's label
enum UIModes
{
DCF_CLOCK, // default
#ifdef DCF77_DO_WEATHER
DCF_SETUP,
#endif
#ifdef USE_BUTTONS
COOK_TIMER, // bonus ^^
#endif
};
UIModes UIMode = DCF_CLOCK;
//UIModes UIMode = COOK_TIMER;
#ifdef DCF77_DO_WEATHER
static String scrollText = "blah bleh blih bloh bluh blyh blah bleh blih bloh bluh blyh ";
static uint16_t scrollWidth;
static uint16_t scrollHeight;
static int scrollPos = 0;
//static int scrollFontSize = int_scrollFontSize;
//static bool isScrolling = false;
//static uint16_t scrollFontColor;
//static uint16_t scrollFontColorDisabled = TFT_DARKGRAY;
//static uint16_t scrollFontColorEnabled = TFT_GRAY;
#endif
//void sprite_drawJpg( LGFX_Sprite *spr, int16_t x, int16_t y, const uint8_t * jpg_data, size_t jpg_len, uint16_t maxWidth, uint16_t maxHeight );
void tft_drawSpriteSheet( SpriteSheetIcon icon, uint16_t x=0, uint16_t y=0 )
{
uint16_t offsetx = (icon%16)*32;
uint16_t offsety = (icon/16)*32;
tft.drawJpg( sprite_jpg, sprite_jpg_len, x, y, 32, 32, offsetx, offsety );
}
void sprite_drawSpriteSheet( LGFX_Sprite &sprite, SpriteSheetIcon icon, uint16_t x=0, uint16_t y=0 )
{
uint16_t offsetx = (icon%16)*32;
uint16_t offsety = (icon/16)*32;
//log_e("sprite.drawSpriteSheet( %d, %d, %d, %d, %d, %d );", x, y, 32, 32, offsetx, offsety );
sprite.fillRect( x, y, 32, 32, TFT_BLACK );
sprite.drawJpg( sprite_jpg, sprite_jpg_len, x, y, 32, 32, offsetx, offsety );
//log_e("done");
}
static void getTextBounds( LGFX_Sprite *sprite, const char *string, uint16_t *w, uint16_t *h )
{
*w = sprite->textWidth( string );
*h = sprite->fontHeight();
}
#ifdef USE_BUTTONS
#include "modules/CookTimer/CookTimer.h"
#endif
#include "Tasks.h"
#if defined USE_BUTTONS
#if defined( BUTTON_A_PIN ) && defined( BUTTON_B_PIN ) && defined( BUTTON_C_PIN )
void checkButtons()
{
//static byte longPushCounter = 0;
M5.update();
if ( longPushCounter >= 30 /*|| M5.BtnC.pressedFor( 1000 )*/ ) {
longPushCounter = 0;
// long press = switch UI mode
switch( UIMode ) {
#ifdef DCF77_DO_WEATHER
case DCF_SETUP:
// TODO: find something to do with long press when in setup mode :-)
break;
#endif
case DCF_CLOCK:
UIMode = COOK_TIMER;
cookTimerSetup();
break;
case COOK_TIMER:
UIMode = DCF_CLOCK;
cookTimerStop();
break;
}
// wait for button release
while( M5.BtnC.isPressed() ) M5.update();
}
switch( UIMode ) {
#ifdef DCF77_DO_WEATHER
case DCF_SETUP:
if ( M5.BtnA.wasPressed() ) { entriesIndex--; pickerTimeout = 600000; beforePicking = millis(); log_w("entriesIndex : %d", entriesIndex ); }
if ( M5.BtnB.wasPressed() ) { entriesIndex++; pickerTimeout = 600000; beforePicking = millis(); log_w("entriesIndex : %d", entriesIndex ); }
if ( M5.BtnC.wasPressed() ) pickedCity = true;
break;
#endif
case DCF_CLOCK:
if( M5.BtnC.isPressed() ) longPushCounter++;
else longPushCounter = 0;
#ifdef DCF77_DO_WEATHER
if ( M5.BtnA.wasPressed() ) dumpWeather();
#endif
if ( M5.BtnB.wasPressed() ) dcf77SoundSwitch = 1 - dcf77SoundSwitch;
break;
case COOK_TIMER:
if( M5.BtnC.isPressed() ) { longPushCounter++; CookTimerButtonPos = BUTTON_CLICK; }
else if( M5.BtnB.isPressed() ) { longPushCounter = 0; CookTimerButtonPos = BUTTON_RIGHT; }
else if( M5.BtnA.isPressed() ) { longPushCounter = 0; CookTimerButtonPos = BUTTON_LEFT; }
else { longPushCounter = 0; CookTimerButtonPos = BUTTON_NEUTRAL; }
break;
}
//delay(50);
}
#else
// TODO: implement touch or other input methods
#endif
#else
void checkSerial()
{
if( Serial.available() ) {
String respStr = Serial.readStringUntil('\n');
int resp = respStr.toInt();
if( resp < 0 || resp > citiesLength ) {
Serial.println("Invalid entry, please provide the City ID, not the name");
pickerTimeout = 600000;
beforePicking = millis();
} else {
Serial.printf("Selecting city #%d ( %s / %s", resp, cities[resp].country.name, cities[resp].name );
entriesIndex = resp;
pickedCity = true;
}
}
}
#endif
#ifdef DCF77_DO_WEATHER
static void updateIcons( SpriteSheetIcon icon1, SpriteSheetIcon icon2, SpriteSheetIcon icon3 )
{
needrendering = 0;
uint16_t posx = ( TFT_HALFWIDTH - 32 / 2 );
uint16_t posy = ( TFT_HALFHEIGHT - 32 / 2 );
if( icon1 != nullicon && icon1 != lasticon1 ) {
lasticon1 = icon1;
needrendering++;
log_w("Icon1 will be rendererd with #%d", icon1 );
drawIconTask( icon1, posx-32, posy );
vTaskDelay(200);
}
if( icon2 != nullicon && icon2 != lasticon2 ) {
lasticon2 = icon2;
needrendering++;
log_w("Icon2 will be rendererd with #%d", icon2 );
drawIconTask( icon2, posx, posy );
vTaskDelay(200);
}
if( icon3 != nullicon && icon3 != lasticon3 ) {
lasticon3 = icon3;
needrendering++;
log_w("Icon3 will be rendererd with #%d", icon3 );
drawIconTask( icon3, posx+32, posy );
vTaskDelay(200);
}
if( needrendering > 0 ) {
while( needrendering > 1 ) {
takeMuxSemaphore();
sprite.pushSprite( 0, 0 );
giveMuxSemaphore();
vTaskDelay( 10 );
}
}
}
void setupScroll()
{
takeMuxSemaphore();
ScrollSprite.createSprite( tft.width(), scrollHeight );
//ScrollSprite.fillSprite( TFT_BLACKISH );
//ScrollSprite.setTextColor( scrollFontColor, TFT_BLACKISH );
scrollFontStyle->setTextStyle( scrollStyleDisabled );
setFontStyle( &ScrollSprite, scrollFontStyle );
giveMuxSemaphore();
takeMuxSemaphore();
MaskSprite.createSprite( tft.width(), scrollHeight );
MaskSprite.fillSprite( TFT_BLACK );
MaskSprite.setSwapBytes( true );
giveMuxSemaphore();
}
void unsetupScroll()
{
MaskSprite.deleteSprite();
ScrollSprite.deleteSprite();
}
void initScroll( String text/*=" Meteo is loading" */ )
{
scrollText = text;
scrollPos = 0;
//scrollFontSize = int_scrollFontSizeSmall;
//scrollFontColor = scrollFontColorDisabled;
scrollFontStyle->setTextStyle( scrollStyleDisabled );
/*
takeMuxSemaphore();
uint16_t* mainSpritePtr = (uint16_t*)MainSprite.createSprite( tft.width(), tft.height() );
if( mainSpritePtr == NULL ) {
log_e("Unable to create mainSpritePtr");
} else {
log_n("Successfully created mainSpritePtr");
}
MainSprite.fillSprite( TFT_BLACK );
MainSprite.setSwapBytes( true );
giveMuxSemaphore();*/
setFontStyle( &ScrollSprite, scrollFontStyle );
//tft_setFont( scrollFontSize, ScrollSprite );
getTextBounds( &sprite, scrollText.c_str(), &scrollWidth, &scrollHeight );
setupScroll();
unsetupScroll();
}
__attribute__((unused))
void updateScroll( String text )
{
scrollText = text;
scrollPos = 0;
//scrollFontSize = int_scrollFontSize;
//scrollFontColor = scrollFontColorEnabled;
scrollFontStyle->setTextStyle( scrollStyleEnabled );
//MaskSprite.deleteSprite();
//ScrollSprite.deleteSprite();
//setupScroll();
}
void handleScroll()
{
if ( scrollWidth <= 0 ) {
Serial.println("Skipping zero width scroll");
return;
}
setupScroll();
takeMuxSemaphore();
/*
tft_setFont( scrollFontSize, ScrollSprite );
ScrollSprite.drawString( scrollText, scrollPos, 0 );
ScrollSprite.drawString( scrollText, scrollWidth + scrollPos, 0 );*/
//scrollFontStyle->setTextStyle( );
//setFontStyle( &ScrollSprite, scrollFontStyle );
//ScrollSprite.fillSprite( TFT_GREEN );
ScrollSprite.drawString( scrollText, scrollPos, 0 );
giveMuxSemaphore();
takeMuxSemaphore();
//MaskSprite.pushImage( 0, -tft.height() / 2 + scrollHeight / 2, tft.width(), tft.height(), (const uint16_t*)sprite.frameBuffer(1)/*, TFT_BLACK*/ );
//MaskSprite.pushImage( ( TFT_HALFWIDTH - 32 / 2 ), ( TFT_HALFHEIGHT - 32 / 2 ), 32, 32, (const uint16_t*)LogoSprite.frameBuffer(1) );
//MaskSprite.pushImage( ( TFT_HALFWIDTH - 32 / 2 ), ( TFT_HALFHEIGHT - 32 / 2 ), 32, 32, (const uint16_t*)LogoSprite.frameBuffer(1) );
MaskSprite.pushRotated( &ScrollSprite, 0/*, TFT_BLACK*/ );
//MaskSprite.pushRotatedHP( &ScrollSprite, 0, TFT_BLACK );
//ScrollSprite.pushImage( 0, 0, MaskSprite.width(), MaskSprite.height(), (const uint16_t*)MaskSprite.frameBuffer(1) );
giveMuxSemaphore();
takeMuxSemaphore();
//MainSprite.pushImage( 0, tft.height() / 2 - scrollHeight / 2, tft.width(), scrollHeight, (const uint16_t*)ScrollSprite.frameBuffer(1)/*, TFT_BLACK*/);
giveMuxSemaphore();
scrollPos -= scrollSpeed;
if ( scrollPos <= -scrollWidth ) {
scrollPos = 0;
}
unsetupScroll();
}
#endif
void displayBufferPosition( int dcfBit )
{
takeMuxSemaphore();
setFontStyle( &sprite, LedDisplayFontStyle );
w = sprite.textWidth( "0" );
sprite.setTextColor( TFT_RED, TFT_BLACK );
sprite.drawString( dcfBit ? "1" : "0", tft.width() - w, LedDisplayFontHeight + 2 );
char bufferPosStr[3];
sprintf( bufferPosStr, "%02d", bufferPosition );
w = sprite.textWidth( "000" );
sprite.setTextColor( TFT_GREEN, TFT_BLACK );
sprite.drawString( bufferPosStr, tft.width() - (w + 10), LedDisplayFontHeight + 2 );
giveMuxSemaphore();
}
void LedDisplay( int addr, String leftOrRight, int value )
{
int shift;
( leftOrRight == "L" ? shift = 4 : shift = 0 );
//Now print the number digit by digit
//preceding zero's are removed with tenary operator by 'printing' a space character.
uint16_t xpos = 0;
takeMuxSemaphore();
switch ( addr ) {
case DisplayPeriodPulse:
char pulseStr[10];
switch ( shift ) {
case 4: // Right
LedDisplayFontStyle->setTextStyle( LedDisplayStylePingtime );
setFontStyle( &sprite, LedDisplayFontStyle );
w = sprite.textWidth( "00000000" );
sprintf( pulseStr, "%4d ", value );
xpos = tft.width() - w;
break;
case 0: // Left
LedDisplayFontStyle->setTextStyle( LedDisplayStyleLeftover );
setFontStyle( &sprite, LedDisplayFontStyle );
w = sprite.textWidth( "000" );
sprintf( pulseStr, "%3d", value );
xpos = tft.width() - w;
break;
}
sprite.drawString( pulseStr, xpos, 0 );
sprite.fillCircle( TFT_HALFWIDTH - 1, TFT_HALFHEIGHT - 1, 1, second() % 2 == 0 ? TFT_RED : TFT_WHITE );
//tft.fillCircle( 80, 55, 1, second() % 2 == 0 ? TFT_WHITE : TFT_RED );
break;
case DisplayBufferBitError:
{
char errorStr[12];
if (value > 99) value = 99;
sprintf( errorStr, "E: %02d", value );
ErrorsCountFontStyle->setTextStyle( (value==0) ? ErrorsCountStyleOK : ErrorsCountStyleKO );
setFontStyle( &sprite, ErrorsCountFontStyle );
w = sprite.textWidth( errorStr );
sprite.fillRect( tft.width() - (w + 3), ErrorsCountFontHeight * 2 + 2, w + 2, ErrorsCountFontHeight + 1, TFT_DARKGRAY );
sprite.drawString( errorStr, tft.width() - w, ErrorsCountFontHeight * 2 + 3 );
}
break;
default:
log_e( "Ignored addr: %d, value: %d", addr, value );
}
giveMuxSemaphore();
}
void LedDCFStatus( int status )
{
//uint16_t color = TFT_GRAY;
switch ( status ) {
case 0:
LedDCFStatusFontStyle->setTextStyle( LedDCFStatusStyleKO );
//color = TFT_RED;
break;
case 1:
LedDCFStatusFontStyle->setTextStyle( LedDCFStatusStyleOK );
//color = TFT_GREEN;
break;
case -1:
default:
//
break;
}
takeMuxSemaphore();
setFontStyle( &sprite, LedDCFStatusFontStyle );
sprite.drawString( "DCF77", 0, 0 );
giveMuxSemaphore();
}
void LedParityStatus( byte paritynum, int status )
{
int xpos = 0;
int ypos = ( tft.height() - 2 * LedParityStatusFontHeight ) - 2; // TODO: normalize this
String out = " ";
//uint16_t color;
switch ( paritynum ) {
case 1: out = "Min"; xpos = MHDXPos[0]; break;
case 2: out = "Hr"; xpos = MHDXPos[1]; break;
case 3: out = "Date"; xpos = MHDXPos[2]; break;
default: log_d( "invalid paritynum: %d", paritynum ); return;
}
switch (status) {
case -1:
//color = TFT_LIGHTGRAY;
LedParityStatusFontStyle->setTextStyle( LedParityStatusStyleNA );
break;
case 0:
//color = TFT_GREEN;
LedParityStatusFontStyle->setTextStyle( LedParityStatusStyleOK );
break;
case 1:
//color = TFT_RED;
LedParityStatusFontStyle->setTextStyle( LedParityStatusStyleKO );
break;
default:
log_d( "invalid status for paritynum %d", paritynum );
return;
}
takeMuxSemaphore();
setFontStyle( &sprite, LedParityStatusFontStyle );
sprite.drawString( out, xpos, ypos );
giveMuxSemaphore();
}
void LedErrorStatus( byte lednum, int status )
{
int xpos = 0;
int ypos = 12;
String out = " ";
takeMuxSemaphore();
ypos = LedErrorStatusFontHeight; //
switch ( status ) {
case LOW:
LedErrorStatusFontStyle->setTextStyle( LedErrorStatusStyleGray );
break;
case HIGH:
LedErrorStatusFontStyle->setTextStyle( LedErrorStatusStyleRed );
break;
default:
log_d( "Unhandled status: %d", status );
return;
}
switch ( lednum ) {
case 40: // LED_MINUTEMARKER output - LED - End of DCF data stream detected before buffer is filled, data is corrupt
ypos += 0;
out = "MMK";
LedErrorStatusFontStyle->setTextStyle( ( status == HIGH ) ? LedErrorStatusStyleGreen : LedErrorStatusStyleGray );
break;
case 32: // LED_RTCERROR
ypos += LedErrorStatusFontHeight;//6;
out = "RTC";
LedErrorStatusFontStyle->setTextStyle( ( status == HIGH ) ? LedErrorStatusStyleRed : LedErrorStatusStyleGray );
myRTCTimeFontStyle->setTextStyle ( ( status == HIGH ) ? myRTCDateTimeTextStyleKO : myRTCDateTimeTextStyleNA );
break;
case 33: // LED_RTCSYNC
ypos += LedErrorStatusFontHeight;//6;
out = "RTC";
LedErrorStatusFontStyle->setTextStyle( ( status == HIGH ) ? LedErrorStatusStyleGreen : LedErrorStatusStyleGray );
myRTCTimeFontStyle->setTextStyle ( ( status == HIGH ) ? myRTCDateTimeTextStyleOK : myRTCDateTimeTextStyleNA );
break;
case 39: // LED_BUFFERFULL output - LED - Buffer full indicator, next the data will be analized
ypos += LedErrorStatusFontHeight * 2; //12;
out = "BFU";
break;
case 41: // LED_BUFFEROVERFLOW output - LED - More data received in one minute than expected due to bad signal
ypos += LedErrorStatusFontHeight * 3; //18;
out = "BOV";
break;
case 38: // LED_ERRORPW output - LED - DCF Period Width error
ypos += LedErrorStatusFontHeight * 4; //24;
out = "PW";
break;
case 37: // LED_ERRORPT output - LED - DCF Period Time error
ypos += LedErrorStatusFontHeight * 5; //30;
out = "PT";
break;
default:
log_d( "Unhandled lednum : %d", lednum );
return;
}
setFontStyle( &sprite, LedErrorStatusFontStyle );
sprite.drawString( out, xpos, ypos );
giveMuxSemaphore();
}
void LeapSecondWarning()
{
takeMuxSemaphore();
//TODO: manage coordinates and text styles from 320x240 and 160x128 profiles
setFontStyle( &sprite, StatusFontStyle ); // centered / small font
sprite.setTextColor(TFT_RED, TFT_BLACK);
sprite.drawString("Leap Sec Inserted", tft.width()/2, 95 );
// record date of last Leap Second on TFT
sprite.setTextColor(TFT_GREEN, TFT_BLACK);
sprite.drawString("Leap Sec", tft.width()/2, 170);
char timeStr[16];
sprintf( timeStr, TIME_FORMAT, hour(), minute(), bufferPosition +1 );
sprite.drawString( timeStr, tft.width()/2, 180 );
char dateStr[16];
sprintf( dateStr, DATE_FORMAT, year(), month(), day() );
sprite.drawString( timeStr, tft.width()/2, 190 );
giveMuxSemaphore();
// record Leap Second date and time on serial port
Serial.printf( "Leap Second Inserted %02d:%02d:%02d 20%02d/%02d/%02d ]\n",
dcfHour,
dcfMinute,
bufferPosition +1,
dcfYear,
dcfMonth,
dcfDay
);
}
static const char weekStr[] = "SMTWTFS";
void drawWeekDays( int daynum )
{
int hpos = sprite.width();
int vpos = sprite.height();
int margin = 1;
int boxWidth = LedWeekStatusFontWidth + (margin);
int boxHeight = (LedWeekStatusFontHeight + (margin*2))-1;
int boxCenterX = boxWidth/2 - margin;
int boxCenterY = boxHeight/2 + margin*2;
hpos -= (boxWidth*7); // right aligned
vpos -= (boxHeight);
setFontStyle( &sprite, LedWeekStatusFontStyle );
for ( byte pos = 0; pos < 7; pos++ ) {
if ( daynum > -1 && daynum == pos ) {
sprite.fillCircle( hpos+(boxWidth/2), vpos-2, 1, TFT_ORANGE );
sprite.fillRect( hpos, vpos, boxWidth, boxHeight, TFT_DARKRED );
sprite.setTextColor( TFT_UGRAY );
} else {
sprite.fillCircle( hpos+(boxWidth/2), vpos-2, 1, TFT_DARKGRAY );
sprite.drawCircle( hpos+(boxWidth/2), vpos-2, 1, TFT_GRAY );
if( pos == 0 || pos == 6 ) {
sprite.fillRect( hpos, vpos, boxWidth, boxHeight, TFT_ORANGE );
} else {
sprite.fillRect( hpos, vpos, boxWidth, boxHeight, TFT_LIGHTGRAY );
}
sprite.setTextColor( TFT_GRAY );
}
sprite.drawChar( weekStr[pos], hpos+boxCenterX+LedWeekStatusMarginX, vpos+boxCenterY+LedWeekStatusMarginY );
hpos += boxWidth;
}
}
#ifdef DCF77_DO_WEATHER
#endif
void LedWeekStatus( int weekDay, int status )
{
int xpos = tft.width() - ( weekDayNamesWidth + 1 );
//int ypos = ( tft.height() - (LedWeekStatusFontHeight) ) - 3;
int weekDayBlockWidth = LedWeekStatusFontWidth + 2;
int wpos = -1;
switch ( weekDay ) {
case 22: // LED_SUNDAY // output - LED - Sunday
wpos = 0;
xpos += 0;
break;
case 23: // LED_MONDAY // output - LED - Monday
wpos = 1;
xpos += weekDayBlockWidth;
break;
case 24: // LED_TUESDAY // output - LED - Tuesday
wpos = 2;
xpos += weekDayBlockWidth * 2;
break;
case 25: // LED_WEDNESDAY // output - LED - Wednesday
wpos = 3;
xpos += weekDayBlockWidth * 3;
break;
case 26: // LED_THURSDAY // output - LED - Thursday
wpos = 4;
xpos += weekDayBlockWidth * 4;
break;
case 27: // LED_FRIDAY // output - LED - Friday
wpos = 5;
xpos += weekDayBlockWidth * 5;
break;
case 28: // LED_SATURDAY // output - LED - Saturday
wpos = 6;
xpos += weekDayBlockWidth * 6;
break;
case 29: // LED_CEST // output - LED - Summertime CEST
takeMuxSemaphore();
setFontStyle( &sprite, status ? BoxSelected->style : BoxUnSelected->style );
sprite.fillRect( CESTXpos, CETCESTYPos - LedWeekStatusFontHeight - 1, CESTWidth + 2, LedWeekStatusFontHeight+1, status ? BoxSelected->fillColor : BoxUnSelected->fillColor );
sprite.drawString( "CEST", CESTXpos + 1, (CETCESTYPos - LedWeekStatusFontHeight) );
giveMuxSemaphore();
return;
break;
case 30: // LED_CET // output - LED - Wintertime CET
takeMuxSemaphore();
setFontStyle( &sprite, status ? BoxSelected->style : BoxUnSelected->style );
sprite.fillRect( CETXPos, CETCESTYPos - LedWeekStatusFontHeight - 1, CETWidth + 2, LedWeekStatusFontHeight+1, status ? BoxSelected->fillColor : BoxUnSelected->fillColor );
sprite.drawString( "CET", CETXPos + 1, (CETCESTYPos - LedWeekStatusFontHeight) );
giveMuxSemaphore();
return;
break;
case 31: // LED_LEAPYEAR // output - LED - Leap year
takeMuxSemaphore();
setFontStyle( &sprite, status ? BoxSelected->style : BoxUnSelected->style );
sprite.fillRect( LEAPXPos, LeapYearYpos - LedWeekStatusFontHeight - 1, LEAPWidth + 2, LedWeekStatusFontHeight+1, status ? BoxSelected->fillColor : BoxUnSelected->fillColor );
sprite.drawString( "LEAP", LEAPXPos + 1, (LeapYearYpos - LedWeekStatusFontHeight) );
giveMuxSemaphore();
return;
break;
case 51: // LED_WEEKNUMBER
char weekNumStr[5];
sprintf( weekNumStr, "W:%02d", weekNumber );
takeMuxSemaphore();
setFontStyle( &sprite, weekNumber > 0 ? BoxSelected->style : BoxUnSelected->style );
tmpFontWidth = sprite.textWidth( weekNumStr );
sprite.fillRect( tft.width() - (tmpFontWidth + 2), WeekNumberYpos - 1, tmpFontWidth + 2, LedWeekStatusFontHeight+1, weekNumber > 0 ? BoxSelected->fillColor : BoxUnSelected->fillColor );
sprite.drawString( String( weekNumStr ), tft.width() - (tmpFontWidth + 1), WeekNumberYpos );
giveMuxSemaphore();
return;
break;
default:
log_d("Invalid weekDay: %d", weekDay);
return;
}
takeMuxSemaphore();
if( wpos > -1 ) {
drawWeekDays( wpos );
}
giveMuxSemaphore();
}
void setRingLed( byte ringNum, byte ledNum, bool enable, bool clear )
{
//float i = ( float( ledNum - 60 / 2 ) / 60) * TWO_PI;
float x1, y1;
uint16_t fillcolor, shinecolor;
byte r = 0;
switch ( ringNum ) {
case 0: // inner
x1 = ringLedCoords[0][ledNum].x;
y1 = ringLedCoords[0][ledNum].y;
r = int_ringLedRadius;
break;
case 1: // outer
x1 = ringLedCoords[1][ledNum].x;
y1 = ringLedCoords[1][ledNum].y;
r = int_ringLedRadius;
break;
default:
log_d( "Invalid ringNum: %d", ringNum );
return;
}
takeMuxSemaphore();
if ( enable ) {
switch ( ledNum ) {
case 20: // start
case 28: // p1
case 35: // p2
case 58: // p3
fillcolor = TFT_GREENISH;
shinecolor = TFT_WHITE;
break;
default:
fillcolor = TFT_RED;
shinecolor = TFT_UGRAY;
}
sprite.fillCircle( x1, y1, r, fillcolor );
if (r > 1) {
sprite.fillTriangle( x1, y1 - 1, x1 + 1, y1 - 1, x1 + 1, y1, shinecolor );
}
} else {
if( clear ) {
sprite.fillCircle( x1, y1, r, TFT_DARKGRAY );
sprite.drawCircle( x1, y1, r, TFT_LIGHTGRAY );
} else {
sprite.fillCircle( x1, y1, r, TFT_LIGHTGRAY );
sprite.fillTriangle( x1, y1 - 1, x1 + 1, y1 - 1, x1 + 1, y1, TFT_WHITE );
}
}
giveMuxSemaphore();
}
void setRingCoords()
{
for ( uint8_t ledNum = 0; ledNum < 60; ledNum++ ) {
float i = ( float( ledNum - 60 / 2 ) / 60 ) * TWO_PI;
float x1, y1, x2, y2, x3, y3, x4, y4;
x1 = ( -sin(i) * r1 ) + TFT_HALFWIDTH;
y1 = ( cos(i) * r1 ) + TFT_HALFHEIGHT;
x2 = ( -sin(i) * r2 ) + TFT_HALFWIDTH;
y2 = ( cos(i) * r2 ) + TFT_HALFHEIGHT;
x3 = ( -sin(i) * r3 ) + TFT_HALFWIDTH;
y3 = ( cos(i) * r3 ) + TFT_HALFHEIGHT;
x4 = ( -sin(i) * r4 ) + TFT_HALFWIDTH;
y4 = ( cos(i) * r4 ) + TFT_HALFHEIGHT;
// cache coords
ringLedCoords[0][ledNum] = {x1, y1};
ringLedCoords[1][ledNum] = {x2, y2};
ringLedCoords[2][ledNum] = {x3, y3};
ringLedCoords[3][ledNum] = {x4, y4};
}
}
void drawRing()
{
takeMuxSemaphore();
setFontStyle( &sprite, RingLabelsFontStyle );
for ( uint8_t ledNum = 0; ledNum < 60; ledNum++ ) {
float i = ( float( ledNum - 60 / 2 ) / 60 ) * TWO_PI;
float x1, y1, x2, y2, x3, y3, x4, y4;
x1 = ringLedCoords[0][ledNum].x;
y1 = ringLedCoords[0][ledNum].y;
x2 = ringLedCoords[1][ledNum].x;
y2 = ringLedCoords[1][ledNum].y;
x3 = ringLedCoords[2][ledNum].x;
y3 = ringLedCoords[2][ledNum].y;
x4 = ringLedCoords[3][ledNum].x;
y4 = ringLedCoords[3][ledNum].y;
uint16_t color1;
if ( ledNum > 0 && ledNum < 15 ) { // meteo data
color1 = tft.color565( 0x44, 0x22, 0x44);
} else if ( ledNum > 14 && ledNum < 21 ) { // antenna / leap hour / CEST / CET / leap sec . start
color1 = tft.color565( 0x22, 0x44, 0x44 );
} else if ( ledNum > 20 && ledNum < 29 ) { // Minute
color1 = tft.color565( 0x66, 0x22, 0x00 );
} else if ( ledNum > 28 && ledNum < 36 ) { // Hour
color1 = tft.color565( 0x44, 0x22, 0x44);
} else if ( ledNum > 35 && ledNum < 42 ) { // Day
color1 = tft.color565( 0x22, 0x44, 0x44 );
} else if ( ledNum > 41 && ledNum < 45 ) { // Day Of Week
color1 = tft.color565( 0x66, 0x22, 0x00 );
} else if ( ledNum > 44 && ledNum < 50 ) { // Month
color1 = tft.color565( 0x44, 0x22, 0x44);
} else if ( ledNum > 49 && ledNum < 58 ) { // Year
color1 = tft.color565( 0x22, 0x44, 0x44 );
} else { // Minute Marker
color1 = tft.color565( 0x22, 0x66, 0x22 );
}
if ( ledNum % 10 == 0 ) {
sprite.drawLine( x2, y2, x3, y3, TFT_LIGHTGRAY );
sprite.drawString( String(ledNum).c_str(), x4, y4);
}
for ( float l = ledNum - 0.5; l <= ledNum + 0.5; l += MinuteSteps ) {
i = ( float( l - 60 / 2) / 60) * TWO_PI;
x1 = ( -sin(i) * r1 ) + TFT_HALFWIDTH;
y1 = ( cos(i) * r1 ) + TFT_HALFHEIGHT;
x2 = ( -sin(i) * r2 ) + TFT_HALFWIDTH;
y2 = ( cos(i) * r2 ) + TFT_HALFHEIGHT;
sprite.drawLine( x1, y1, x2, y2, color1 );
}
}
giveMuxSemaphore();