-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplayEnhanced.c
1846 lines (1627 loc) · 56 KB
/
displayEnhanced.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
/*
* displayEnhanced.c
*
* for high-level drawing functions.
* Customizations: KD4Z, NO7K
*
*/
#include "display.h"
#include "md380.h"
#include "version.h"
#include "tooldfu.h"
#include "config.h"
#include "gfx.h"
#include "printf.h"
#include "string.h"
#include "addl_config.h"
#include "ambe.h"
#include "usersdb.h"
#include "dmr.h"
#include "console.h"
#include "netmon.h"
#include "radiostate.h"
#include "unclear.h"
#include "etsi.h"
#include "codeplug.h"
#include "app_menu.h"
#include "syslog.h" // LOGB()
#include "irq_handlers.h" // boot_flags, BOOT_FLAG_DREW_STATUSLINE
#include "lcd_driver.h"
#include "codeplug.h"
#include "beep.h"
#include "keyb.h"
#if defined(FW_D13_020) || defined(FW_S13_020)
#include "amenu_set_tg.h"
#else
#warning old firmware
#endif
//#include "amenu_channels.h"
#include <stdlib.h>
#define RX_POPUP_Y_START 17 // prev=22 // orig=24
#define RX_POPUP_X_START 4 // 10
#define FIRSTNAME_BUFSIZE 30
#define COUNTRY_BUFSIZE 20
#define STATE_BUFSIZE 20
char eye_paltab[] = {
0xd7, 0xd8, 0xd6, 0x00, 0x88, 0x8a, 0x85, 0x00, 0xe1, 0xe2, 0xe0, 0x00, 0xff, 0xff, 0xff, 0x00,
0xae, 0xae, 0xaf, 0x00, 0x24, 0x4e, 0x8a, 0x00, 0x5d, 0x88, 0xbb, 0x00, 0xd1, 0xd2, 0xd4, 0x00,
0xf4, 0xf4, 0xf4, 0x00, 0x3c, 0x66, 0x9f, 0x00, 0xdb, 0xe6, 0xf3, 0x00, 0x48, 0x73, 0xaa, 0x00,
0xb6, 0xb8, 0xb4, 0x00, 0x5e, 0x6a, 0x77, 0x00
};
char eye_pix[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x11, 0x10, 0x00, 0x00, 0x23,
0x41, 0x11, 0x31, 0x00, 0x01, 0x14, 0x55, 0x55, 0x61, 0x00, 0x21, 0x75, 0x88, 0x59, 0x94, 0x31, 0x3a, 0x85, 0x88, 0x56,
0x57, 0x73, 0x21, 0x86, 0x55, 0x5b, 0x67, 0x41, 0x13, 0x48, 0x66, 0x69, 0x71, 0xc1, 0x0c, 0x13, 0x47, 0x33, 0x11, 0x10,
0x00, 0x03, 0xdc, 0xd1, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const gfx_pal eye_pal = {14, 0, eye_paltab};
const gfx_bitmap bmp_eye = {12, 12, 6, 4, eye_pix, &eye_pal, 0};
#ifdef FW_D13_020
#define D_ICON_EYE_X 65
#define D_ICON_EYE_Y 1
#endif
#ifdef FW_S13_020
// on MD390 draw promiscous mode eye closed to S-Meter due to GPS-symbol an standard position
#define D_ICON_EYE_X 20
#define D_ICON_EYE_Y 1
#endif
#define LCD_OPT_FONT_8x16 (LCD_OPT_FONT_8x8|LCD_OPT_DOUBLE_HEIGHT)
#define VU_BAR_TOP_Y 16
#define VU_LEGEND_X 0
#define VU_LEGEND_WIDTH 3
#define VU_BAR_X VU_LEGEND_X+VU_LEGEND_WIDTH + 1
#define VU_BAR_WIDTH 7
#define VU_TEXT_X VU_BAR_X+VU_BAR_WIDTH + 1
#define TO_BAR_WIDTH 3
#define TO_BAR_X LCD_SCREEN_WIDTH - 1 - TO_BAR_WIDTH
#if defined(FW_D13_020) || defined(FW_S13_020)
#define __PTT_LASTHEARD
#define __PTT_LASTHEARD_DOWN
#define __RX_SCREEN_OPTION
#define __RX_SCREEN_OPTION_WHITE
#endif
static int lh_painted = 0;
static const char *const countries[] = {
"AD,Andorra",
"AN,Antilles",
"AR,Argentina",
"AT,Austria",
"AU,Australia",
"BA,Bosnia and Herzegovina",
"BB,Barbados",
"BE,Belgium",
"BG,Bulgaria",
"BR,Brazil",
"BZ,Belize",
"CA,Canada",
"CH,Switzerland",
"CL,Chile",
"CN,China",
"CO,Columbia",
"CR,Costa Rica",
"CY,Cyprus",
"CZ,Czech Republic",
"DE,Germany",
"DK,Denmark",
"DM,Dominica",
"DO,Dominican Republic",
"EC,Ecuador",
"EE,Estonia",
"ES,Spain",
"FI,Finland",
"FR,France",
"GR,Greece",
"GT,Guatemala",
"HK,Hong Kong",
"HR,Croatia",
"HT,Haiti",
"HU,Hungary",
"ID,Indonesia",
"IE,Ireland",
"IL,Israel",
"IN,India",
"IT,Italy",
"JP,Japan",
"KR,Korea",
"KW,Kuwait",
"LI,Liechtenstein",
"LU,Luxemburg",
"LV,Latvia",
"ME,Montenegro",
"MK,Macedonia",
"MT,Malta",
"MX,Mexico",
"MY,Malaysia",
"NL,Netherlands",
"NO,Norway",
"NZ,New Zealand",
"PA,Pananma",
"PH,Philippines",
"PL,Poland",
"PT,Portugal",
"PY,Paraguay",
"QA,Qatar",
"RE,Reunion",
"RO,Romainia",
"RS,Serbia",
"RU,Russia",
"SE,Sweden",
"SG,Singapore",
"SI,Slovenia",
"SK,Slovakia",
"TH,Thailand",
"TR,Turkey",
"TT,Trinidad and Tobago",
"TW,Taiwan",
"UA,Ukraine",
"UK,United Kingdom",
"US,USA",
"UY,Uruguay",
"VE,Venezuela",
"ZA,South Africa",
};
static const char *const states[] = {
"AB,Alberta",
"ABR,Abruzzo",
"ACT,Austrailian Capital T",
"AK,Alaska",
"AL,Alabama",
"ANT,Antwerpen",
"AR,Arkansas",
"AZ,Arizona",
"BAS,Basilicata",
"BB,Brandenburg",
"BC,British Columbia",
"BE,Berlin",
"BW,Baden-Wurttemberg",
"BRU,Brussels",
"BY,Bavaria",
"CA,California",
"CAL,Calabria",
"CAM,Campania",
"CO,Colorada",
"CT,Connecticut",
"DC,District of Columbia",
"DE,Delaware",
"DR,Drenthe",
"EMI,Emila-Romagna",
"FLD,Flevoland",
"FL,Florida",
"FRL,Friesland",
"FRI,Friuli-Venezia Giulia",
"GA,Georgia",
"GLD,Gelderland",
"GR,Groningen",
"HB,Bremen",
"HE,Hessen",
"HH,Hamburg",
"HI,Hawaii",
"IA,Iowa",
"ID,Idaho",
"IF,Ile-de-France",
"IL,Illinois",
"IN,Indiana",
"KS,Kansas",
"KY,Kentucky",
"LA,Louisiana",
"LAZ,Lazio",
"LB,Limburg",
"LIG,Liguria",
"LIE,Liege",
"LIM,Limburg",
"LOM,Lombardia",
"MA,Massachusetts",
"MAR,Marche",
"MB,Manitoba",
"MD,Maryland",
"ME,Maine",
"MI,Michigan",
"MN,Minnesota",
"MO,Missouri",
"MOL,Molise",
"MS,Mississippi",
"MT,Montana",
"MV,Mecklenburg-Vorpommern",
"N-BR,N.Brabant",
"N-H,N.Holland",
"NB,New Brunswick",
"NC,N.Carolina",
"ND,N.Dakota",
"NE,Nebraska",
"NH,New Hampshire",
"NI,Lower Saxony",
"NJ,New Jersey",
"NL,Newfoundland",
"NM,New Mexico",
"NS,Nova Scotia",
"NSW,New S.Wales",
"NT,Northern Territory",
"NV,Nevada",
"NW,N.Rhine-Westphalia",
"NY,New York",
"OVL,Oost-Vlaanderen",
"OA,OA",
"OH,Ohio",
"OK,Oklahoma",
"ON,Ontario",
"OR,Oregon",
"OV,Overijssel",
"PA,Pennsylvania",
"PE,Prince Edward Isle",
"PIE,Piemonte",
"PLDS,Lower Silesia",
"PLKP,Kuyavia-Pomerania",
"PLLB,Lubusz",
"PLLD,Lodz",
"PLLU,Lublin",
"PLMA,Lesser Poland",
"PLMZ,Mazovia",
"PLOP,Opole",
"PLPD,Podlaskie",
"PLPK,Subcarpathia",
"PLPM,Pomerania",
"PLSK,Holy Cross",
"PLSL,Silesia",
"PLWN,Greater Poland",
"PLZP,W.Pomerania",
"PR,Puerto Rico",
"PUG,Puglia",
"QC,Quebec",
"QLD,Queensland",
"RI,Rhode Island",
"RP,Rhineland-Palatinate",
"SA,S.Australia",
"SAR,Sardegna",
"SC,S.Carolina",
"SD,S.Dakota",
"SH,Schleswig-Holstein",
"SIC,Sicilia",
"SK,Saskatchewan",
"SL,Saarland",
"SN,Saxony",
"ST,Saxony-Anhalt",
"SV,Savona",
"TAS,Tasmania",
"TH,Thuringia",
"TN,Tennessee",
"TOS,Toscana",
"TRE,Trentino-Alto Adige",
"TX,Texas",
"UMB,Umbria",
"UT,Utah",
"UTR,Utrecht",
"VA,Virginia",
"VAL,Valle d-Aosta",
"VAN,Antwerp",
"VB,Vlaams-Brabant",
"VBR,Flemish Brabant",
"VEN,Veneto",
"VIC,Victoria",
"VLI,Limburg",
"VOV,E.Flanders",
"VT,Vermont",
"WVL,W.Flanders",
"WA,Washington",
"WAU,Western Australia",
"WBR,Walloon Brabant",
"WHT,Hainaut",
"WI,Wisconsin",
"WLG,Leige",
"WLX,Luxembourg",
"WNA,Namur",
"WV,W.Virginia",
"WY,Wyoming",
"YT,Yukon",
"ZE,Zeeland",
"ZH,S.Holland",
};
#define ARRAY_SIZE(x) (sizeof x / sizeof x[0])
int abbrevs_sorted(const char *const a[], int size) {
int hasSortIssue = 1;
for (int i = 1; i < size; i++)
if (strcmp(a[i-1], a[i]) >= 0) {
hasSortIssue = 0;
printf("Sort problem, these need to be swapped: %s and %s \n",a[i-1],a[i]);
return hasSortIssue;
}
return hasSortIssue;
}
const char *lookupAbbrev(char *abbrev, const char *const abbrevs[], int length) {
int left = 0;
int right = length - 1;
static int sorted;
static int order_checked;
if (!sorted) {
if (!order_checked) {
sorted = abbrevs_sorted(countries, ARRAY_SIZE(countries));
sorted &= abbrevs_sorted(states, ARRAY_SIZE(states));
order_checked = 1;
}
if (!sorted)
return "unsorted";
}
while (left <= right) {
int middle = left + (right-left)/2;
const char *p, *q;
for (p=abbrev, q=abbrevs[middle]; *q != 0; p++, q++) {
if (*p < *q) {
if (*p == 0 && *q == ',')
return q + 1;
right = middle - 1;
break;
}
if (*p > *q) {
left = middle + 1;
break;
}
}
}
return abbrev;
}
void draw_eye_opt()
{
#if defined(FW_D13_020) || defined(FW_S13_020)
// draw promiscous mode eye symbol
if( global_addl_config.promtg == 1 ) {
gfx_drawbmp((char *) &bmp_eye, D_ICON_EYE_X, D_ICON_EYE_Y);
}
#endif
}
// Takes a positive(!) integer amplitude and computes 200*log10(amp),
// centi Bel, approximtely. If the given parameter is 0 or less, this
// function returns -1. tnx to sellibitze
int intCentibel(long ampli)
{
if( ampli <= 0 )
return -1; // invalid
int log_2 = 0;
while (ampli >= 32 * 8) {
ampli >>= 1 + 3;
log_2 += 1 + 3;
}
while (ampli >= 32) {
ampli >>= 1;
log_2 += 1;
}
// 1 <= ampli < 32
static const short fine[] = {
-1, 0, 60, 95, 120, 140, 156, 169,
181, 191, 200, 208, 216, 223, 229, 235,
243, 249, 253, 258, 262, 266, 270, 274,
278, 281, 285, 288, 291, 294, 297, 300
};
return (log_2 * 301 + 2) / 5 + fine[ampli];
}
//#d efine RX_POPUP_Y_START 24
//#d efine RX_POPUP_X_START 10
void draw_txt(char* testStr, int x, int y, char font){
char c=0;
int maxLen=16;
uint16_t fg_color = 0, bg_color = 0;
#if defined(FW_D13_020) || defined(FW_S13_020)
Menu_GetColours(SEL_FLAG_NONE, &fg_color, &bg_color);
#endif
while( ((c=*testStr)!=0) && maxLen>0)
{ x = LCD_DrawCharAt( c, x, y, fg_color, bg_color, font);
//++i; // character index and limiting counter
++testStr;
// (in rare cases, some of the leading text may be OVERWRITTEN below)
maxLen--;
}
}
char *get_firstname(user_t *up, char *buf, int buflen) {
// Thanks to Dale Farnsworth [email protected] for providing this little ditty.
if (*up->firstname != 0)
return up->firstname;
char *p = buf;
char *q = up->name;
for (int i = 0; i < buflen-1 && *q != ' ' && *q != 0; i++)
*p++ = *q++;
*p = 0;
return buf;
}
#define ARRAY_SIZE(x) (sizeof x / sizeof x[0])
char *lookup_country(user_t *up, char *buf) {
const char *p = lookupAbbrev(up->country, countries, ARRAY_SIZE(countries));
//printf("lookup country in %s",up->country);
//printf(" out=%s\n",p);
strcpy(buf, p);
return buf;
}
char *lookup_state(user_t *up, char *buf) {
const char *p = lookupAbbrev(up->state, states, ARRAY_SIZE(states));
strcpy(buf, p);
return buf;
}
#if defined(__PTT_LASTHEARD)
static uint32_t stopwatch_cnt = 0;
static int tot_beep_done = 0;
static int previous_sec = -1;
void oem_repaint_screen () {
channel_num = 0;
CheckTalkgroupAfterChannelSwitch();
}
void draw_tx_screen_layout(int showtimer) {
#if defined(FW_D13_020) || defined(FW_S13_020)
int sel_flags = SEL_FLAG_NONE;
int src;
int dst;
//char firstname_buf[FIRSTNAME_BUFSIZE];
//char *firstname;
char state_buf[STATE_BUFSIZE];
int ptt_seconds=0;
int ch_to = 0;
int secs_display = 0;
int to_barvalue=0;
int have_lh_info = 1;
lcd_context_t dc;
user_t usr;
src = rst_src;
dst = rst_dst ;
channel_info_t *ci = ¤t_channel_info;
ch_to = ci->unk8==0 ? 999 : ci->unk8 * 15;
have_lh_info = usr_find_by_dmrid(&usr, src);
LCD_InitContext( &dc );
dc.x2 = dc.x2 - TO_BAR_WIDTH - 1;
Menu_GetColours( sel_flags, &dc.fg_color, &dc.bg_color );
dc.x = 0;
dc.y = 17;
if (lh_painted != 1 ) {
LCD_FillRect( 0, 15, dc.x2, LCD_SCREEN_HEIGHT-1, dc.bg_color );
lh_painted = 1;
}
if ( dst > 0 ) {
dc.x = VU_TEXT_X;
dc.font = LCD_OPT_FONT_8x8;
dc.fg_color = LCD_COLOR_WHITE;
dc.bg_color = LCD_COLOR_BLUE;
LCD_Printf( &dc, "LH: TG %d \r",dst);
}
Menu_GetColours( sel_flags, &dc.fg_color, &dc.bg_color );
if (showtimer == 1){
ptt_seconds = ReadStopwatch_ms(&stopwatch_cnt)/1000;
#if defined(__PTT_LASTHEARD_DOWN)
secs_display = ch_to - ptt_seconds;
if ( tot_beep_done == 0 && ( secs_display < 11) ) {
bp_send_beep(BEEP_TEST_1);
tot_beep_done++;
reset_backlight();
} else if ( tot_beep_done == 1 && ( secs_display < 6) ) {
bp_send_beep(BEEP_TEST_1);
tot_beep_done++;
reset_backlight();
}
#else
secs_display = ptt_seconds;
#endif
to_barvalue = ptt_seconds * 127 / ch_to;
if (to_barvalue > 127) {
to_barvalue = 127;
}
if (to_barvalue < VU_BAR_TOP_Y){
to_barvalue = VU_BAR_TOP_Y;
}
if ( previous_sec != secs_display) {
gfx_set_bg_color(0x000000);
gfx_set_fg_color(0x000000);
gfx_blockfill(TO_BAR_X, VU_BAR_TOP_Y, TO_BAR_X + TO_BAR_WIDTH, to_barvalue);
gfx_set_fg_color(0x0000ff); // red
gfx_blockfill(TO_BAR_X, to_barvalue+1, TO_BAR_X + TO_BAR_WIDTH, 127);
}
}
if ( have_lh_info >0 ) {
dc.font = LCD_OPT_FONT_12x24;
if (showtimer == 1) {
LCD_Printf( &dc, "%s %d\r", usr.callsign,secs_display);
} else {
dc.x = 5;
LCD_Printf( &dc, "%s\r", usr.callsign);
dc.x = 8;
}
dc.y = dc.y - 1;
dc.font = LCD_OPT_FONT_8x16;
LCD_Printf( &dc, "%s\r", usr.name);
LCD_Printf( &dc, "%s\r", usr.place);
LCD_Printf( &dc, "%s\r", lookup_state(&usr, state_buf));
LCD_Printf( &dc, "%s\r", lookup_country(&usr, state_buf));
LCD_DrawString( &dc, "\r");
} else {
//printf("no lh else previous_sec=%d secs_display=%d\n",previous_sec,secs_display);
if (showtimer == 1){
if ( previous_sec != secs_display) {
dc.font = LCD_OPT_FONT_12x24;
dc.x = VU_TEXT_X;
LCD_DrawString( &dc, " PTT\r");
LCD_Printf( &dc, " %d\r",secs_display);
#if defined(__PTT_LASTHEARD_DOWN)
LCD_DrawString( &dc, " Secs until\r Timeout\r");
LCD_DrawString( &dc, "\r");
#else
LCD_DrawString( &dc, " Seconds\r");
#endif
}
} else {
dc.font = LCD_OPT_FONT_8x16;
dc.y += 12;
LCD_DrawString( &dc, " No\r Last Heard\r Info yet!!");
}
if (showtimer == 1){
if ( previous_sec != secs_display) {
previous_sec = secs_display;
}
}
}
#endif
}
void draw_micbargraph()
{
//
// New bargraph routine extended with Last Heard information de KD4Z
//
if( gui_opmode2 == OPM2_MENU || Menu_IsVisible() ) {
// case for pressing the PTT during 'Manual Dial' in 'Contacts'
return ;
}
static int rx_active; // flag to syncronice this hook ( operatingmode == 0x11 is also on rx seeded)
static int fullscale_offset = 0;
static uint32_t lastframe = 0;
static int red = 0;
static int green = 0;
int relative_peak_cb;
int centibel_val;
if( fullscale_offset == 0 ) { // init int_centibel()
fullscale_offset = intCentibel(3000); // maybe wav max max_level
}
int is_tx = 0 ;
int is_rx = 0 ;
is_tx = gui_opmode1 == SCR_MODE_RX_VOICE && max_level > 10 ;
is_rx = gui_opmode1 == SCR_MODE_RX_TERMINATOR ;
#if defined(FW_D13_020) || defined(FW_S13_020)
{
uint8_t s = radio_status_1.m1 ;
is_tx = s & 1 ;
is_rx = s & 2 ;
}
#endif
if( is_tx && max_level < 4500 ) {
if (stopwatch_cnt==0)
StartStopwatch(&stopwatch_cnt);
if( lastframe < ambe_encode_frame_cnt ) { // check for new frame
lastframe = ambe_encode_frame_cnt;
rx_active = 1;
relative_peak_cb = intCentibel(max_level) - fullscale_offset;
centibel_val = relative_peak_cb;
if( lastframe % 5 == 1 ) { // reduce drawing
if( centibel_val < -220 ) { // limit 110 pixel bargraph 15 125 -> 110 pixel for vertical bargraph
centibel_val = -220;
} else if( centibel_val > 0 ) {
centibel_val = 0;
}
centibel_val += 220; // shift to positive
centibel_val /= 2; // scale
previous_sec=0;
draw_tx_screen_layout(1);
lh_painted = 1;
gfx_set_bg_color(0x000000);
gfx_set_fg_color(0x000000);
gfx_blockfill(VU_BAR_X, VU_BAR_TOP_Y, VU_BAR_X + VU_BAR_WIDTH, 127);
// paint legend
gfx_set_fg_color(0x0000ff); // red
gfx_blockfill(VU_LEGEND_X, VU_BAR_TOP_Y, VU_LEGEND_X + VU_LEGEND_WIDTH, 40); // 135,67,150,70
gfx_set_fg_color(0x00ff00); // green
gfx_blockfill(VU_LEGEND_X, 41, VU_LEGEND_X + VU_LEGEND_WIDTH, 90); // 85,67,134,70
gfx_set_fg_color(0x555555); // grey
gfx_blockfill(VU_LEGEND_X, 91, VU_LEGEND_X + VU_LEGEND_WIDTH,127); // 10,67,84,70
// set color
if( relative_peak_cb > -3 || red > 0 ) {
if( red > 0 ) red--;
if( relative_peak_cb > -3 ) red = 30;
gfx_set_fg_color(0x0000ff);
} else if( relative_peak_cb > -130 || green > 0 ) {
if( green > 0 ) green--;
if( relative_peak_cb > -130 ) green = 30;
gfx_set_fg_color(0x00ff00);
} else {
gfx_set_fg_color(0x555555);
}
// paint the VU bar
if (centibel_val > 125)
centibel_val = 125;
gfx_blockfill(VU_BAR_X, (127 - centibel_val), VU_BAR_X + VU_BAR_WIDTH, 124);
}
}
}
if( is_rx && rx_active == 1 ) {
rx_active = 0;
red = 0;
green = 0;
lh_painted = 0;
stopwatch_cnt = 0;
tot_beep_done = 0;
previous_sec=1;
#if defined(FW_D13_020) || defined(FW_S13_020)
LCD_FillRect( 0,0, LCD_SCREEN_WIDTH-1, LCD_SCREEN_HEIGHT-1, LCD_COLOR_MD380_BKGND_BLUE );
oem_repaint_screen();
#endif
}
}
#else
void draw_tx_screen_layout(int showtimer) {}
void oem_repaint_screen () {}
void draw_micbargraph()
{
//
// original mic bargraph routine
//
if( gui_opmode2 == OPM2_MENU ) {
// case for pressing the PTT during 'Manual Dial' in 'Contacts'
return ;
}
static int rx_active; // flag to syncronice this hook ( operatingmode == 0x11 is also on rx seeded)
static int fullscale_offset = 0;
static uint32_t lastframe = 0;
static int red = 0;
static int green = 0;
int relative_peak_cb;
int centibel_val;
if( fullscale_offset == 0 ) { // init int_centibel()
fullscale_offset = intCentibel(3000); // maybe wav max max_level
}
int is_tx = 0 ;
int is_rx = 0 ;
is_tx = gui_opmode1 == SCR_MODE_RX_VOICE && max_level > 10 ;
is_rx = gui_opmode1 == SCR_MODE_RX_TERMINATOR ;
#if defined(FW_D13_020) || defined(FW_S13_020)
{
uint8_t s = radio_status_1.m1 ;
is_tx = s & 1 ;
is_rx = s & 2 ;
channel_info_t *ci = ¤t_channel_info ;
}
#endif
if( is_tx && max_level < 4500 ) {
if( lastframe < ambe_encode_frame_cnt ) { // check for new frame
lastframe = ambe_encode_frame_cnt;
rx_active = 1;
relative_peak_cb = intCentibel(max_level) - fullscale_offset;
centibel_val = relative_peak_cb;
if( lastframe % 5 == 1 ) { // reduce drawing
if( centibel_val < -280 ) { // limit 160 pixel bargraph 10 150 -> 140 pixel for bargraph
centibel_val = -280;
} else if( centibel_val > 0 ) {
centibel_val = 0;
}
centibel_val += 280; // shift to positive
centibel_val /= 2; // scale
gfx_set_fg_color(0x999999);
gfx_set_bg_color(0xff000000);
gfx_blockfill(9, 54, 151, 66);
// paint legend
gfx_set_fg_color(0x0000ff);
gfx_blockfill((-30 + 280) / 2 + 10, 67, 150, 70);
gfx_set_fg_color(0x00ff00);
gfx_blockfill((-130 + 280) / 2 + 10, 67, (-30 + 280) / 2 - 1 + 10, 70);
gfx_set_fg_color(0x555555);
gfx_blockfill(10, 67, (-130 + 280) / 2 - 1 + 10, 70);
// set color
if( relative_peak_cb > -3 || red > 0 ) {
if( red > 0 ) red--;
if( relative_peak_cb > -3 ) red = 30;
gfx_set_fg_color(0x0000ff);
} else if( relative_peak_cb > -130 || green > 0 ) {
if( green > 0 ) green--;
if( relative_peak_cb > -130 ) green = 30;
gfx_set_fg_color(0x00ff00);
} else {
gfx_set_fg_color(0x555555);
}
gfx_set_bg_color(0xff000000);
gfx_blockfill(10, 55, centibel_val, 65);
gfx_set_fg_color(0xff8032);
gfx_set_bg_color(0xff000000);
}
}
}
if( is_rx && rx_active == 1 ) { // clear screen area
gfx_set_fg_color(0xff8032);
gfx_set_bg_color(0xff000000);
gfx_blockfill(9, 54, 151, 70);
rx_active = 0;
red = 0;
green = 0;
}
}
#endif
#if defined(__RX_SCREEN_OPTION)
void draw_rx_screen(unsigned int bg_color)
{
// KD4Z primary RX screen
#define FULLNAME_MAX_LARGEFONT_CHARS 16
#define FULLNAME_MAX_MIDDLEFONT_CHARS 18
#define CITY_MAX_LARGEFONT_CHARS 18
#define STATECOUNTRY_MAX_LARGEFONT_CHARS 15
static int dst;
int src;
int grp;
int primask = OS_ENTER_CRITICAL(); // for form sake
dst = rst_dst ;
src = rst_src ;
grp = rst_grp ;
OS_EXIT_CRITICAL(primask);
lcd_context_t dc;
user_t usr;
int displayLines;
int siglin;
int siglinfudge=0;
LCD_InitContext( &dc );
char firstname_buf[FIRSTNAME_BUFSIZE];
char country_buf[COUNTRY_BUFSIZE];
char state_buf[STATE_BUFSIZE];
if( usr_find_by_dmrid(&usr,src) == 0 ) {
if( src==4000 ) {
usr.callsign = "Message" ;
usr.firstname = "from" ;
usr.name = "Server" ;
usr.place = "" ;
usr.state = "" ;
usr.country = "";
}
else {
usr.callsign = "Callsign" ;
usr.firstname = "not found" ;
usr.name = talkerAlias.text;
usr.place = "Update from" ;
usr.state = "our github," ;
usr.country = "bm-database.";
}
}
#if defined(FW_D13_020) || defined(FW_S13_020)
channel_info_t *ci = ¤t_channel_info ;
int ts2 = ( ci->cc_slot_flags >> 3 ) & 0x1 ;
int cc = ( ci->cc_slot_flags >> 4 ) & 0xf ;
#else
int ts2 = 0;
int cc = 0;
#endif
// font options (width x height)
//dc.font = LCD_OPT_FONT_6x12; // base font
//dc.font = LCD_OPT_FONT_8x8; // base font looks bold
// these are combinations of base fonts with LCD_OPT_DOUBLE_WIDTH|LCD_OPT_DOUBLE_HEIGHT
//dc.font = LCD_OPT_FONT_8x16; // double height 8x8
//dc.font = LCD_OPT_FONT_16x16; // double height and width of 8x8
//dc.font = LCD_OPT_FONT_12x12; // double width 6x12
//dc.font = LCD_OPT_FONT_12x24; // double height and width of 6x24
dc.bg_color = LCD_COLOR_MD380_BKGND_BLUE;
LCD_FillRect( 0, 15, LCD_SCREEN_WIDTH-1, LCD_SCREEN_HEIGHT-1, dc.bg_color );
dc.x = 0;
dc.y = 15;
//printf("usr.country= %s \n",usr.country);
char *state = lookup_state(&usr, state_buf);
char *country = lookup_country(&usr, country_buf);
displayLines = (strlen(state) + strlen(country)) > STATECOUNTRY_MAX_LARGEFONT_CHARS ? 5 : 4 ;
dc.font = LCD_OPT_FONT_6x12;
dc.fg_color = LCD_COLOR_WHITE;
dc.bg_color = LCD_COLOR_BLUE;
if( grp ) {
LCD_Printf( &dc, "\t%d-TG %d %s CC%d\r", src, dst, ( ts2==1 ? "T2" : "T1"),cc );
} else {
LCD_Printf( &dc, "\t%d-%d %s CC%d\r", src, dst, ( ts2==1 ? "T2" : "T1"),cc );
}
dc.bg_color = LCD_COLOR_MD380_BKGND_BLUE;
#if defined(__RX_SCREEN_OPTION_WHITE)
dc.fg_color = LCD_COLOR_WHITE;
#else
dc.fg_color = LCD_COLOR_BLACK;
#endif
dc.x = 3;
dc.y +=4;
dc.font = LCD_OPT_FONT_8x8|LCD_OPT_DOUBLE_HEIGHT;
int nameLen=0;
int smallFontFudge=0;
if (strlen(usr.firstname) > 0) { // have real nickname, display it as before
LCD_Printf( &dc, "\t%s - %s\r", usr.callsign, usr.firstname );
dc.y+=2;
} else {
char *firstname = get_firstname(&usr, firstname_buf, FIRSTNAME_BUFSIZE);
nameLen = strlen(usr.name);
if (strcmp(usr.firstname, firstname) != 0 && strlen(usr.firstname)>0) {
LCD_Printf( &dc, "\t%s - %s\r", usr.callsign, firstname );
dc.y+=2;
} else if (nameLen > FULLNAME_MAX_LARGEFONT_CHARS) {
if (nameLen > FULLNAME_MAX_MIDDLEFONT_CHARS ) {
// name will be in small font, allow large font for call
dc.y-=1;
LCD_Printf( &dc, "\t%s\r", usr.callsign);
dc.y-=1;
} else {
// or fullname is going to be in medium font
dc.y-=1;
LCD_Printf( &dc, "\t%s\r", usr.callsign);
dc.y+=1;
smallFontFudge=2;
}
} else {
LCD_Printf( &dc, "\t%s\r", usr.callsign);
dc.y+=2;
}
}
// Display Q/A ids 2682100 2682101 2220298 2620071 2621168 3101380 (name=15) 3101439 (name=17)
if ( global_addl_config.userscsv > 1 && talkerAlias.length > 0 ) { // 2017-02-19 show Talker Alias depending on setup 0=CPS 1=DB 2=TA 3=TA & DB
// TA or TA/DB mode
nameLen = strlen(talkerAlias.text);
if ( talkerAlias.length > FULLNAME_MAX_LARGEFONT_CHARS ) {
if (nameLen > FULLNAME_MAX_MIDDLEFONT_CHARS ) {
dc.font = LCD_OPT_FONT_6x12; // drastic measures
}
else {
dc.font = LCD_OPT_FONT_6x12|LCD_OPT_DOUBLE_HEIGHT;
}
dc.y-=4;
LCD_Printf( &dc, "\t%s\r", talkerAlias.text );
dc.y--;
} else {
dc.font = LCD_OPT_FONT_8x8|LCD_OPT_DOUBLE_HEIGHT;
if (talkerAlias.length < 1) {
LCD_Printf( &dc, "\tDMRID: %d\r", src );
} else {
dc.y++;
LCD_Printf( &dc, "\t%s\r", talkerAlias.text );
}
}
}
else {
// user.bin or codeplug or talkerAlias length=0
if (nameLen > FULLNAME_MAX_LARGEFONT_CHARS) {
dc.y-=4;
if (nameLen > FULLNAME_MAX_MIDDLEFONT_CHARS ) {
dc.y+=2;
siglinfudge=-1;
dc.font = LCD_OPT_FONT_6x12; // drastic measures
LCD_Printf( &dc, "\t%s\r", usr.name );
dc.y+=3;
}
else {
dc.y++;
dc.font = LCD_OPT_FONT_6x12|LCD_OPT_DOUBLE_HEIGHT;
LCD_Printf( &dc, "\t%s\r", usr.name );
dc.y--;
}
}
else {
dc.y-=2;
dc.font = LCD_OPT_FONT_8x8|LCD_OPT_DOUBLE_HEIGHT;
LCD_Printf( &dc, "\t%s\r", usr.name );