forked from EU1KY/Analyzer_EU1KY_CEC_AKF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwnd.c
1406 lines (1257 loc) · 41.6 KB
/
mainwnd.c
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
/*
* (c) Yury Kuchura
* kuchura@gmail.com
*
* Modified by KD8CEC
* This code can be used on terms of WTFPL Version 2 (http://www.wtfpl.net/).
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "font.h"
#include "touch.h"
#include "mainwnd.h"
#include "textbox.h"
#include "config.h"
#include "fftwnd.h"
#include "generator.h"
#include "measurement.h"
#include "oslcal.h"
#include "panvswr2.h"
#include "panfreq.h"
#include "main.h"
#include "usbd_storage.h"
#include "ff_gen_drv.h"
#include "sd_diskio.h"
#include "crash.h"
#include "dsp.h"
#include "gen.h"
#include "aauart.h"
#include "build_timestamp.h"
#include "tdr.h"
#include "screenshot.h"
#include "spectr.h"
#include "stm32_ub_adc3_single.h"
#include "DS3231.h"
//KD8CEC
#include "guicontrol.h"
#include "aaprotocol.h"
//#include "trackspectr.h"
extern void Track_Proc(void);
extern void TRACK_Beep(int duration);
extern void Sleep(uint32_t);
extern void WeakSignal_Proc(void);
static void Exit1(void);
void DisplayVoltage();
uint32_t date, time;
uint32_t RTCpresent;
void Voltage(void);
void InitVoltage(void);
// MainWnd
static TEXTBOX_CTX_t main_ctx;
static TEXTBOX_t hbTimestamp;
// MenuTools, MenuSettings
static TEXTBOX_CTX_t menu1_ctx;
static void MenuSettings(void);
// MenuCalibration
static TEXTBOX_CTX_t menu2_ctx;
static void MenuCalibration(void);
static TEXTBOX_CTX_t menu3_ctx;
// Oscillator test
static TEXTBOX_CTX_t osci_ctx;
volatile int NoDate;
// Voltage
static int VoltCase, Volt_max_Display, Volt_min_Display, Volt_max_Factor;
int BattVoltage, Batt;
float VoltFloat, percent;
int cntr, CountMax;
static void Colours(void);
#define M_BGCOLOR LCD_RGB(0, 0, 64) //Menu item background color
#define M_FGCOLOR LCD_RGB(255, 255, 0) //Menu item foreground color
#define COL1 10 //Column 1 x coordinate
#define COL2 230 //Column 2 x coordinate
static USBD_HandleTypeDef USBD_Device;
extern char SDPath[4];
extern FATFS SDFatFs;
extern uint8_t second;
static bool rqExit1;
static void USBD_Proc()
{
while (TOUCH_IsPressed())
;
LCD_FillAll(LCD_BLACK);
FONT_Write(FONT_FRANBIG, LCD_YELLOW, LCD_BLACK, 10, 0, "USB storage access via USB HS port");
FONT_Write(FONT_FRANBIG, LCD_YELLOW, LCD_BLACK, 80, 200, "Exit (Reset device)");
FATFS_UnLinkDriver(SDPath);
BSP_SD_DeInit();
Sleep(100);
USBD_Init(&USBD_Device, &MSC_Desc, 0);
USBD_RegisterClass(&USBD_Device, USBD_MSC_CLASS);
USBD_MSC_RegisterStorage(&USBD_Device, &USBD_DISK_fops);
USBD_Start(&USBD_Device);
//USBD works in interrupts only, no need to leave CPU running in main.
for (;;)
{
Sleep(50); //To enter low power if necessary
LCDPoint coord;
if (TOUCH_Poll(&coord))
{
while (TOUCH_IsPressed())
;
if (coord.x > 80 && coord.x < 320 && coord.y > 200 && coord.y < 240)
{
USBD_Stop(&USBD_Device);
USBD_DeInit(&USBD_Device);
BSP_LCD_DisplayOff();
BSP_SD_DeInit();
Sleep(100);
NVIC_SystemReset(); //Never returns
}
}
}
}
static uint16_t Line;
static uint16_t Pmax;
static uint8_t EndFlag;
static uint16_t rqExit, rqExitR, newLoad;
uint16_t FileNo;
volatile int Page;
#define TBX0 190
#define Fieldw1 70
#define TBX1 300
#define Fieldw2 60
#define FieldH 36
#define TBY 90
void(Delete(void))
{
SCREENSHOT_DeleteFile(Line % 12);
newLoad = 1;
}
void(ShowP(void))
{
SCREENSHOT_ShowPicture(Line % 12);
newLoad = 1;
}
void(Next(void))
{
uint16_t idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), BackGrColor);
if (idx >= 11)
{
FileNo += 12;
Page += 1;
Line = 0;
newLoad = 1;
return;
}
if (idx >= Pmax - 1)
{
EndFlag = 0;
Page = 1;
Line = 0;
FileNo = 0;
newLoad = 1;
return;
}
Line++;
idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), CurvColor);
}
void(NextPage(void))
{
uint16_t idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), BackGrColor);
newLoad = 1;
if (EndFlag == 1)
{
EndFlag = 0;
Page = 1;
FileNo = 0;
}
else
{
FileNo += 12;
Page += 1;
}
Line = 0;
}
void(Prev(void))
{
uint16_t idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), BackGrColor); // delete the "cursor"
if ((idx == 0) && (Page == 1))
{
do
{
Pmax = SCREENSHOT_SelectFileNames(12 * (Page - 1));
Page++;
FileNo += 12;
} while (11 < Pmax); // up from first element --> go to end
Page--;
EndFlag = 1;
newLoad = 1;
}
else if (idx > 0)
{
Line--;
idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), CurvColor);
}
else
{
Page--;
FileNo -= 12;
newLoad = 1;
}
}
void Exit(void)
{
rqExitR = 1;
InitVoltage();
}
static const TEXTBOX_t tb_reload[] = {
(TEXTBOX_t){.x0 = TBX0 + 200, .y0 = 10, .text = "Up", .font = FONT_FRANBIG, .width = Fieldw1, .height = FieldH, .center = 1, .border = 1, .fgcolor = LCD_WHITE, .bgcolor = LCD_BLACK, .cb = (void (*)(void))Prev, .cbparam = 1, .next = (void *)&tb_reload[1]},
(TEXTBOX_t){.x0 = TBX0 + 200, .y0 = 10 + FieldH + 1, .text = "Down", .font = FONT_FRANBIG, .width = Fieldw1, .height = FieldH, .center = 1, .border = 1, .fgcolor = LCD_WHITE, .bgcolor = LCD_BLACK, .cb = (void (*)(void))Next, .cbparam = 1, .next = (void *)&tb_reload[2]},
(TEXTBOX_t){.x0 = TBX0 + 200, .y0 = 234, .text = "Delete", .font = FONT_FRANBIG, .width = Fieldw1, .height = FieldH, .center = 1, .border = 1, .fgcolor = LCD_WHITE, .bgcolor = LCD_RED, .cb = (void (*)(void))Delete, .cbparam = 1, .next = (void *)&tb_reload[3]},
(TEXTBOX_t){.x0 = TBX0 + 200, .y0 = TBY + 18, .text = "Show", .font = FONT_FRANBIG, .width = Fieldw1, .height = FieldH, .center = 1, .border = 1, .fgcolor = LCD_WHITE, .bgcolor = LCD_GREEN, .cb = (void (*)(void))ShowP, .cbparam = 1, .next = (void *)&tb_reload[4]},
(TEXTBOX_t){.x0 = 2, .y0 = 234, .text = " Exit ", .font = FONT_FRANBIG, .width = 100, .height = FieldH, .center = 1, .border = 1, .fgcolor = LCD_WHITE, .bgcolor = LCD_BLACK, .cb = (void (*)(void))Exit, .cbparam = 1, .next = (void *)&tb_reload[5]},
(TEXTBOX_t){
.x0 = 80,
.y0 = 234,
.text = " Next Page",
.font = FONT_FRANBIG,
.width = 150,
.height = FieldH,
.center = 1,
.border = 1,
.fgcolor = LCD_WHITE,
.bgcolor = LCD_BLACK,
.cb = (void (*)(void))NextPage,
.cbparam = 1,
},
};
void Reload_Proc(void)
{ // WK ***************************************************************************************
TEXTBOX_CTX_t fctx;
LCDPoint pt;
char str[16];
uint32_t idx;
SetColours();
rqExitR = 0;
FileNo = 0;
Page = 1;
Line = 0;
LCD_FillAll(BackGrColor);
TEXTBOX_InitContext(&fctx);
TEXTBOX_Append(&fctx, (TEXTBOX_t *)tb_reload); //Append the very first element of the list in the flash.
//It is enough since all the .next fields are filled at compile time.
TEXTBOX_DrawContext(&fctx);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 0, 0, "Manage Snapshots"); // WK
newLoad = 0;
EndFlag = 0;
if (SCREENSHOT_SelectFileNames(0) < 11)
EndFlag = 1;
LCD_Rectangle(LCD_MakePoint(0, 31), LCD_MakePoint(280, 16 + 32), CurvColor);
sprintf(str, "Page: %d", Page);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 250, 235, str);
do
{
Pmax = SCREENSHOT_SelectFileNames(12 * (Page - 1));
Page++;
FileNo += 12;
} while (11 < Pmax); // --> go to end
Page--;
EndFlag = 1;
newLoad = 1;
Line += Pmax - 1;
idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), CurvColor);
for (;;)
{
if (TEXTBOX_HitTest(&fctx))
{
Sleep(50);
}
if (rqExitR)
{
LCD_FillAll(BackGrColor);
break;
}
Sleep(10);
if (newLoad == 1)
{
newLoad = 0;
LCD_FillRect(LCD_MakePoint(0, 31), LCD_MakePoint(290, 234), BackGrColor);
TEXTBOX_InitContext(&fctx);
TEXTBOX_Append(&fctx, (TEXTBOX_t *)tb_reload); //Append the very first element of the list in the flash.
TEXTBOX_DrawContext(&fctx);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 0, 0, "Manage Snapshots"); // WK
Pmax = SCREENSHOT_SelectFileNames(12 * (Page - 1));
if (11 > Pmax)
EndFlag = 1;
LCD_Rectangle(LCD_MakePoint(0, Line * 16 + 31), LCD_MakePoint(280, (Line % 12) * 16 + 16 + 32), CurvColor);
sprintf(str, "Page: %d", Page);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 250, 235, str);
}
//Check Touch FileName
if (TOUCH_Poll(&pt))
{
if (pt.x < 300 && pt.y > 32 && pt.y < ((Pmax)*16 + 32))
{
TRACK_Beep(1);
//Select
while (TOUCH_IsPressed())
;
idx = Line % 12;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), BackGrColor);
int newIdx = (pt.y - 32) / 16;
idx = newIdx;
//Line = Page * 12 + idx;
Line = idx;
LCD_Rectangle(LCD_MakePoint(0, idx * 16 + 31), LCD_MakePoint(280, idx * 16 + 16 + 32), CurvColor);
}
}
}
}
static uint8_t second1;
uint8_t TestDate(void)
{
int dd, mm, yyyy;
char txt[10], txt1[5];
if ((date <= 19800101) || (date > 20803112))
return 7;
sprintf(txt, "%08u", (unsigned int)date); // date
dd = atoi(&txt[6]);
if ((dd == 0) || (dd > 31))
return 1; // day false
strncpy(txt1, &txt[4], 2); // test month 0..12
txt1[2] = 0;
mm = atoi(txt1);
if ((mm == 0) || (mm > 12))
return 2; // month false
strncpy(txt1, &txt[4], 4); // test month 0..12
txt1[4] = 0;
yyyy = atoi(txt1);
if (mm == 2)
{
if ((yyyy % 4 == 0) && (yyyy % 100 != 0))
{ // leap-year ?
if (dd > 29)
return 3;
}
else if (dd > 28)
return 4;
}
switch (mm)
{
case 4:
case 6:
case 9:
case 11:
if (dd > 30)
return 5;
default:
if (dd > 31)
return 6;
}
return 0;
}
void SetInternTime(uint32_t timx)
{
secondsCounter = second1 + (timx % 100) * 60 + (timx / 100) * 3600;
}
void NextDay(void)
{
if (NoDate == 1)
return;
date += 1;
if (TestDate() == 0)
return;
date = date - (date % 100) + 101; // month +1; day =1
if (TestDate() == 0)
return;
date = date - (date % 10000) + 10101; // year +1; moth = day = 1
}
uint32_t GetInternTime(uint8_t *secondsx)
{
uint32_t minutes;
if (secondsCounter > 86400)
{ // 24 * 3600
NextDay();
CFG_SetParam(CFG_PARAM_Date, date);
CFG_Flush();
secondsCounter -= 86400;
}
minutes = secondsCounter / 60;
*secondsx = (uint8_t)(secondsCounter % 60);
return (minutes % 60 + (minutes / 60) * 100);
}
//KD8CEC : RESIZE FONT AND CHANGE POSITION
static void DateTime(void)
{
uint32_t mon;
short AMPM1;
char text1[20];
if (NoDate == 1)
return;
if (RTCpresent)
{
getTime(&time, &second1, &M1, 0);
getDate(&date);
}
else
{
time = GetInternTime(&second1);
date = CFG_GetParam(CFG_PARAM_Date);
}
mon = date % 10000;
sprintf(text1, "%04d %02d %02d ", (int)date / 10000, (int)mon / 100, (int)mon % 100);
FONT_Write(FONT_FRAN, CurvColor, LCD_RGB(64, 64, 64), 220, 257, text1);
sprintf(text1, "%02d:%02d:%02d ", (int)time / 100, (int)time % 100, (int)second1);
FONT_Write(FONT_FRAN, CurvColor, LCD_RGB(64, 64, 64), 305, 257, text1);
}
void Measure_LCR_Proc(void);
void AudioDSP_Proc(void);
void RecPlayAudio_Proc(void);
#ifdef _DEBUG_UART
extern void PrintOSLSize(void);
#endif
// ================================================================================================
// Main window procedure (never returns)
void MainWnd(void)
{
//uint8_t i;
int counter11;
//By KD8CEC
#ifdef _DEBUG_UART
DBGUART_Init();
DBG_Str("Debug Start for Antenna Analyzer!!! \r\n");
#endif
SetColours();
BSP_LCD_SelectLayer(0);
SetColours();
//modified by KD8CEC
//LCD_FillAll(LCD_BLACK);
SetColours();
GetBS(CFG_GetParam(CFG_PARAM_PAN_F1) / 1000);
//KD8CEC
BSP_LCD_SelectLayer(1);
LCD_ShowActiveLayerOnly();
LCD_DrawBitmap(LCD_MakePoint(0, 0), mainimg_bmp, mainimg_bmp_size);
while (TOUCH_IsPressed())
;
//Initialize textbox context
TEXTBOX_InitContext(&main_ctx);
//modified by KD8CEC
if (DatumDDMMYYYY)
{
//modified by KD8CEC
hbTimestamp = (TEXTBOX_t){.x0 = 27, .y0 = 257, .text = "" AAVERSION "," BUILD_TIMESTAMP_D, .font = FONT_FRAN, .fgcolor = LCD_GRAY, .bgcolor = LCD_RGB(64, 64, 64)};
}
else
{
hbTimestamp = (TEXTBOX_t){.x0 = 27, .y0 = 257, .text = "" AAVERSION "," BUILD_TIMESTAMP_US, .font = FONT_FRAN, .fgcolor = LCD_GRAY, .bgcolor = LCD_RGB(64, 64, 64)};
}
TEXTBOX_Append(&main_ctx, &hbTimestamp);
//Draw context
TEXTBOX_DrawContext(&main_ctx);
PROTOCOL_Reset();
InitVoltage();
FONT_Write(FONT_FRAN, LCD_WHITE, 0, 420, 9, AAVERSION_CECV);
counter11 = 98;
for (;;)
{
Voltage();
if (++counter11 > 100)
{
DateTime();
counter11 = 0;
}
Sleep(10); //for autosleep to work
//KD8CEC
LCDPoint pt;
if (TOUCH_Poll(&pt))
{
int touchIndex = GetTouchIndex(pt, buttonsArea, BUTTON_COUNT);
if (touchIndex > -1)
{
TRACK_Beep(1);
while (TOUCH_IsPressed())
;
switch (touchIndex)
{
//LINE 1
case BTN_SINGLE:
Single_Frequency_Proc();
break;
case BTN_SWEEP:
PANVSWR2_Proc();
break;
case BTN_MULTISWR:
MultiSWR_Proc();
break;
case BTN_TUNESWR:
Tune_SWR_Proc();
break;
case BTN_TDR:
TDR_Proc();
break;
//LINE 2
case BTN_FIND:
SPECTR_FindFreq();
break;
case BTN_QUARTZ:
Quartz_proc();
break;
case BTN_RFGEN:
GENERATOR_Window_Proc();
break;
case BTN_SNAPSHOT:
Reload_Proc();
break;
case BTN_USB:
USBD_Proc();
break;
case BTN_LC:
Measure_LCR_Proc();
break;
//LINE 3
case BTN_CONFIG:
MenuSettings();
break;
case BTN_DSP:
FFTWND_Proc();
break;
case BTN_TRACKER: // S21
Track_Proc();
break;
case BTN_WSPR:
WeakSignal_Proc();
break;
}
while (TOUCH_IsPressed())
;
Sleep(50);
//Redraw main window
//BSP_LCD_SelectLayer(1);
LCD_DrawBitmap(LCD_MakePoint(0, 0), mainimg_bmp, mainimg_bmp_size);
TEXTBOX_DrawContext(&main_ctx);
//LCD_ShowActiveLayerOnly();
PROTOCOL_Reset();
//Write Version Number
FONT_Write(FONT_FRAN, LCD_WHITE, 0, 420, 9, AAVERSION_CECV);
Voltage(); //reduce delay time for display voltage information
DisplayVoltage();
} //end of if (check touch)
}
PROTOCOL_Handler(); // UART communication USB AA600 emulation or LinSmith
}
}
#define XXa 2
void SetColours(void)
{
if (ColourSelection == 1)
{ // Daylight
BackGrColor = LCD_WHITE;
CurvColor = LCD_COLOR_DARKGREEN; // dark blue
TextColor = LCD_BLACK;
Color1 = LCD_COLOR_DARKGREEN; //LCD_COLOR_DARKBLUE;
Color2 = LCD_COLOR_DARKGRAY;
Color3 = LCD_YELLOW; // -ham bands area at daylight
Color4 = LCD_MakeRGB(128, 255, 128); //Light green
}
else
{ // Inhouse
BackGrColor = LCD_BLACK;
CurvColor = LCD_COLOR_LIGHTGREEN;
TextColor = LCD_WHITE;
Color1 = LCD_COLOR_LIGHTBLUE;
Color2 = LCD_COLOR_GRAY;
Color3 = LCD_MakeRGB(0, 0, 64); // very dark blue -ham bands area
Color4 = LCD_MakeRGB(0, 64, 0); // very dark green
}
CFG_SetParam(CFG_PARAM_Daylight, ColourSelection);
CFG_Flush();
}
static void Daylight(void)
{
ColourSelection = 1;
SetColours(); // includes "CFG_Flush"
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 240, 10, " Daylight Colours ");
}
static void Inhouse(void)
{
ColourSelection = 0;
SetColours();
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 240, 10, " Inhouse Colours ");
}
static void Fatlines(void)
{
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 20, 10, " Fat Lines ");
FatLines = true;
CFG_SetParam(CFG_PARAM_Fatlines, 1);
CFG_Flush();
}
static void Thinlines(void)
{
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 20, 10, " Thin Lines ");
FatLines = false;
CFG_SetParam(CFG_PARAM_Fatlines, 0);
CFG_Flush();
}
static void BeepOn(void)
{
if (CFG_GetParam(CFG_PARAM_BeepOn) == 0)
{
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 50, " Beep On ");
BeepOn1 = 1;
CFG_SetParam(CFG_PARAM_BeepOn, 1);
}
else
{
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 50, " Beep Off ");
BeepOn1 = 0;
CFG_SetParam(CFG_PARAM_BeepOn, 0);
}
CFG_Flush();
}
static void Rotate(void)
{
if (LCD_Get_Orientation() == 0)
{
LCD_Set_Orientation(1);
}
else
{
LCD_Set_Orientation(0);
}
CFG_Flush();
rqExit1 = 1; // leave the menue
}
static void Exit1(void)
{
rqExit1 = true;
InitVoltage();
}
static const TEXTBOX_t tb_col[] = {
(TEXTBOX_t){.x0 = XXa, .y0 = 50, .text = "Daylight", .font = FONT_FRANBIG, .width = 200, .height = 34, .center = 1, .border = 1, .fgcolor = M_FGCOLOR, .bgcolor = M_BGCOLOR, .cb = (void (*)(void))Daylight, .cbparam = 1, .next = (void *)&tb_col[1]},
(TEXTBOX_t){.x0 = XXa, .y0 = 100, .text = "Inhouse", .font = FONT_FRANBIG, .width = 200, .height = 34, .center = 1, .border = 1, .fgcolor = M_FGCOLOR, .bgcolor = M_BGCOLOR, .cb = (void (*)(void))Inhouse, .cbparam = 1, .next = (void *)&tb_col[2]},
(TEXTBOX_t){.x0 = XXa, .y0 = 150, .text = "Fat Lines", .font = FONT_FRANBIG, .width = 200, .height = 34, .center = 1, .border = 1, .fgcolor = M_FGCOLOR, .bgcolor = M_BGCOLOR, .cb = (void (*)(void))Fatlines, .cbparam = 1, .next = (void *)&tb_col[3]},
(TEXTBOX_t){.x0 = XXa, .y0 = 200, .text = "Thin Lines", .font = FONT_FRANBIG, .width = 200, .height = 34, .center = 1, .border = 1, .fgcolor = M_FGCOLOR, .bgcolor = M_BGCOLOR, .cb = (void (*)(void))Thinlines, .cbparam = 1, .next = (void *)&tb_col[4]},
(TEXTBOX_t){.x0 = XXa + 240, .y0 = 100, .text = "Beep On/Off", .font = FONT_FRANBIG, .width = 200, .height = 34, .center = 1, .border = 1, .fgcolor = M_FGCOLOR, .bgcolor = M_BGCOLOR, .cb = (void (*)(void))BeepOn, .cbparam = 1, .next = (void *)&tb_col[5]},
(TEXTBOX_t){
.x0 = 240,
.y0 = 200,
.text = " Exit ",
.font = FONT_FRANBIG,
.width = 200,
.height = 34,
.center = 1,
.border = 1,
.fgcolor = M_FGCOLOR,
.bgcolor = LCD_RED,
.cb = (void (*)(void))Exit1,
.cbparam = 1,
},
};
static void Colours(void)
{
while (TOUCH_IsPressed())
;
SetColours();
rqExit1 = false;
LCD_FillAll(LCD_COLOR_DARKGRAY);
TEXTBOX_CTX_t fctx;
if (ColourSelection == 0)
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 10, " Inhouse Colours ");
else
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 10, " Daylight Colours ");
if (FatLines == true)
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 20, 10, " Fat Lines ");
else
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 20, 10, " Thin Lines ");
if (BeepOn1 == 1)
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 50, " Beep On ");
else
FONT_Write(FONT_FRANBIG, LCD_BLACK, LCD_YELLOW, 240, 50, " Beep Off ");
TEXTBOX_InitContext(&fctx);
TEXTBOX_Append(&fctx, (TEXTBOX_t *)tb_col); //Append the very first element of the list in the flash.
//It is enough since all the .next fields are filled at compile time.
TEXTBOX_DrawContext(&fctx);
for (;;)
{
Sleep(0); //for autosleep to work
if (TEXTBOX_HitTest(&fctx))
{
Sleep(50);
if (rqExit1)
{
rqExit1 = false;
while (TOUCH_IsPressed())
;
return;
}
Sleep(50);
}
Sleep(0);
}
}
#define COL3 380
void InitVoltage(void)
{
Volt_max_Display = CFG_GetParam(CFG_PARAM_Volt_max_Display);
Volt_min_Display = CFG_GetParam(CFG_PARAM_Volt_min_Display);
Volt_max_Factor = CFG_GetParam(CFG_PARAM_Volt_max_Factor);
if (Volt_max_Factor == 0)
Volt_max_Factor = 614.f; // default factor
BattVoltage = 0;
CountMax = 100;
cntr = 0;
SetColours();
}
//KD8CEC : for Visible Voltage indicator from hidden by other screen
void DisplayVoltage()
{
char text1[60];
LCDColor vbg;
//Modified by KD8CEC for users request
//sprintf(text1,"%5.2fV %3f", VoltFloat, percent);
//strcat(text1,"%");
//sprintf(text1,"%5.2fV %3.0f%% ", VoltFloat, percent);
//2019.03.26 removed % mark
sprintf(text1, "%5.2fV %3.0f ", VoltFloat, percent);
//vbg=BackGrColor;
vbg = LCD_RGB(64, 64, 64); //
if (percent <= 25)
{
vbg = LCD_RED;
}
else if (percent <= 50)
{
vbg = LCD_RGB(127, 127, 0); //LCD_YELLOW
}
FONT_Write(FONT_FRAN, TextColor, vbg, 399, 257, text1);
}
//KD8CEC : RESIZE FONT AND CHANGE POSITION
void Voltage(void)
{
char text1[10];
int VoltRaw;
if (Volt_max_Display == 0)
return;
cntr++;
VoltRaw = UB_ADC3_SINGLE_Read_MW(ADC_PF9);
if (VoltRaw <= 0)
{
sprintf(text1, "Error: %d ", VoltRaw);
FONT_Write(FONT_FRAN, TextColor, LCD_RED, 340, 230, text1);
return;
}
BattVoltage += VoltRaw;
if (cntr >= CountMax)
{
Batt = BattVoltage / CountMax; // value for calibration
VoltFloat = (float)Batt / Volt_max_Factor; //614.f 563.0f
cntr = 0;
CountMax = 3200,
BattVoltage = 0;
if (VoltFloat > (float)Volt_max_Display / 1000.0f)
{
percent = 100;
}
else
//percent=(int)(VoltFloat*100.f-300.f);
percent = (int)100.f * ((1000.f * VoltFloat - (float)Volt_min_Display) / (Volt_max_Display - Volt_min_Display));
DisplayVoltage();
}
}
void minus10(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display -= 10;
else
Volt_min_Display -= 10;
}
void minus100(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display -= 100;
else
Volt_min_Display -= 100;
}
void minus1000(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display -= 1000;
else
Volt_min_Display -= 1000;
}
void plus10(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display += 10;
else
Volt_min_Display += 10;
}
void plus100(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display += 100;
else
Volt_min_Display += 100;
}
void plus1000(void)
{
while (TOUCH_IsPressed())
;
if (VoltCase == 1)
Volt_max_Display += 1000;
else
Volt_min_Display += 1000;
}
void VoltCase1(void)
{
while (TOUCH_IsPressed())
;
VoltCase = 1;
LCD_Rectangle(LCD_MakePoint(COL1, 160), LCD_MakePoint(COL1 + 200, 160 + 34), LCD_RED);
LCD_Rectangle(LCD_MakePoint(COL2, 160), LCD_MakePoint(COL2 + 200, 160 + 34), LCD_YELLOW);
}
void VoltCase2(void)
{
while (TOUCH_IsPressed())
;
VoltCase = 2;
LCD_Rectangle(LCD_MakePoint(COL1, 160), LCD_MakePoint(COL1 + 200, 160 + 34), LCD_YELLOW);
LCD_Rectangle(LCD_MakePoint(COL2, 160), LCD_MakePoint(COL2 + 200, 160 + 34), LCD_RED);
}
static int rqExit3;
static void Exit3(void)
{
rqExit3 = 1;
InitVoltage();
}
void ShowVoltage(void)
{
char str1[30];
sprintf(str1, "MaxV: %.3f ", (float)Volt_max_Display / 1000.f);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 120, 10, str1);
sprintf(str1, "MinV: %.3f ", (float)Volt_min_Display / 1000.f);
FONT_Write(FONT_FRANBIG, TextColor, BackGrColor, 120, 45, str1); //60
sprintf(str1, "MaxFact: %d ", Volt_max_Factor);
FONT_Write(FONT_FRAN, TextColor, BackGrColor, 120, 80, str1);
if (Volt_max_Display == 0)
LCD_Rectangle(LCD_MakePoint(COL2, 210), LCD_MakePoint(COL2 + 240, 210 + 34), LCD_RED);
else
LCD_Rectangle(LCD_MakePoint(COL2, 210), LCD_MakePoint(COL2 + 240, 210 + 34), LCD_YELLOW);
}
void VoltOff(void)
{
while (TOUCH_IsPressed())
;
CFG_SetParam(CFG_PARAM_Volt_max_Display, 0);
Volt_max_Display = 0;
ShowVoltage();
Sleep(2000);
rqExit3 = 1;
}
void SetMax(void)
{
while (TOUCH_IsPressed())
;
Volt_max_Factor = (int)((float)Batt * 1000.f / Volt_max_Display);
CFG_SetParam(CFG_PARAM_Volt_max_Factor, Volt_max_Factor);
ShowVoltage();
LCD_Rectangle(LCD_MakePoint(110, 110), LCD_MakePoint(330, 144), LCD_RED);
Sleep(2000);
rqExit3 = 1;