-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen.ino
1866 lines (1668 loc) · 46.7 KB
/
Screen.ino
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
char *ItoaPadded(int val, char *str, uint8_t bytes, uint8_t decimalpos) {
// Val to convert
// Return String
// Length
// Decimal position
uint8_t neg = 0;
if(val < 0) {
neg = 1;
val = -val;
}
str[bytes] = 0;
for(;;) {
if(bytes == decimalpos) {
str[--bytes] = DECIMAL;
decimalpos = 0;
}
str[--bytes] = '0' + (val % 10);
val = val / 10;
if(bytes == 0 || (decimalpos == 0 && val == 0))
break;
}
if(neg && bytes > 0)
str[--bytes] = '-';
while(bytes != 0)
str[--bytes] = ' ';
return str;
}
char *ItoaUnPadded(int val, char *str, uint8_t bytes, uint8_t decimalpos) {
// Val to convert
// Return String
// Length
// Decimal position
uint8_t neg = 0;
if(val < 0) {
neg = 1;
val = -val;
}
str[bytes] = 0;
for(;;) {
if(bytes == decimalpos) {
str[--bytes] = DECIMAL;
decimalpos = 0;
}
str[--bytes] = '0' + (val % 10);
val = val / 10;
if(bytes == 0 || (decimalpos == 0 && val == 0))
break;
}
if(neg && bytes > 0)
str[--bytes] = '-';
while(bytes != 0)
str[--bytes] = ' ';
return str;
}
char *FormatGPSCoord(int32_t val, char *str, uint8_t p, char pos, char neg) {
if(val < 0) {
pos = neg;
val = -val;
}
uint8_t bytes = p+6;
val = val / 100;
str[bytes] = 0;
str[--bytes] = pos;
for(;;) {
if(bytes == p) {
str[--bytes] = DECIMAL;
continue;
}
str[--bytes] = '0' + (val % 10);
val = val / 10;
if(bytes == 0 || (bytes < 3 && val == 0))
break; }
while(bytes != 0)
str[--bytes] = ' ';
return str;
}
// Take time in Seconds and format it as 'MM:SS'
// Alternately Take time in Minutes and format it as 'HH:MM'
// If hhmmss is 1, display as HH:MM:SS
char *formatTime(uint32_t val, char *str, uint8_t hhmmss) {
int8_t bytes = 5;
if(hhmmss)
bytes = 8;
str[bytes] = 0;
do {
str[--bytes] = '0' + (val % 10);
val = val / 10;
str[--bytes] = '0' + (val % 6);
val = val / 6;
str[--bytes] = ':';
} while(hhmmss-- != 0);
do {
str[--bytes] = '0' + (val % 10);
val = val / 10;
} while(val != 0 && bytes != 0);
while(bytes != 0)
str[--bytes] = ' ';
return str;
}
uint8_t FindNull(void)
{
uint8_t xx;
for(xx=0;screenBuffer[xx]!=0;xx++)
;
return xx;
}
uint16_t getPosition(uint8_t pos) {
uint16_t val = screenPosition[pos];
uint16_t ret = val&POS_MASK;
return ret;
}
uint8_t fieldIsVisible(uint8_t pos) {
// uint16_t val = (uint16_t)pgm_read_word(&screenPosition[pos]);
uint16_t val = screenPosition[pos];
if ((val & DISPLAY_MASK)==DISPLAY_ALWAYS)
return 1;
else
return 0;
/*
switch(val & DISPLAY_MASK) {
case DISPLAY_ALWAYS:
return 1;
case DISPLAY_NEVER:
return 0;
case DISPLAY_COND:
return !!(MwSensorActive&mode.osd_switch);
case DISPLAY_MIN_OFF:
return !(MwSensorActive&mode.osd_switch);
}
*/
}
void displayTemperature(void) // DEPRECATED RUSHDUINO SUPPORT
{
int xxx;
if (Settings[S_UNITSYSTEM])
xxx = temperature*1.8+32; //Fahrenheit conversion for imperial system.
else
xxx = temperature;
// if(!fieldIsVisible(temperaturePosition))
// return;
itoa(xxx,screenBuffer,10);
uint8_t xx = FindNull(); // find the NULL
screenBuffer[xx++]=temperatureUnitAdd[Settings[S_UNITSYSTEM]];
screenBuffer[xx]=0; // Restore the NULL
MAX7456_WriteString(screenBuffer,getPosition(temperaturePosition));
}
void displayMode(void)
{
if(timer.MSP_active==0){ // no MSP >> mode display not valid
return;
}
uint8_t xx = 0;
if((MwSensorActive&mode.camstab)&&Settings[S_GIMBAL]){
screenBuffer[2]=0;
screenBuffer[0]=SYM_GIMBAL;
screenBuffer[1]=SYM_GIMBAL1;
if(fieldIsVisible(gimbalPosition))
MAX7456_WriteString(screenBuffer,getPosition(gimbalPosition));
}
if(Settings[S_MODESENSOR]){
xx = 0;
if(MwSensorActive&mode.stable||MwSensorActive&mode.horizon){
screenBuffer[xx] = SYM_ACC;
xx++;
}
if (MwSensorActive&mode.baro){
screenBuffer[xx] = SYM_BAR;
xx++;
}
if (MwSensorActive&mode.mag){
screenBuffer[xx] = SYM_MAG;
xx++;
}
screenBuffer[xx] = 0;
if(fieldIsVisible(sensorPosition)){
MAX7456_WriteString(screenBuffer,getPosition(sensorPosition));
}
}
if(MwSensorActive&mode.passthru){
screenBuffer[2]=0;
screenBuffer[0]=SYM_PASS;
screenBuffer[1]=SYM_PASS1;
}
else if(MwSensorActive&mode.gpshome){
#ifdef APINDICATOR
screenBuffer[0] = SYM_GHOME;
screenBuffer[1] = SYM_GHOME1;
screenBuffer[2]=0;
#else
uint32_t dist;
if(Settings[S_UNITSYSTEM]){
dist = GPS_distanceToHome * 3.2808; // mt to feet
}
else{
dist = GPS_distanceToHome; // Mt
}
itoa(dist, screenBuffer+3, 10);
xx = FindNull()+1;
if(Settings[S_UNITSYSTEM]==METRIC){
screenBuffer[xx] =SYM_M;
}
else{
screenBuffer[xx] =SYM_FT;
}
screenBuffer[xx] =0;
screenBuffer[0] = SYM_GHOME;
screenBuffer[1] = SYM_GHOME1;
screenBuffer[2] = SYM_COLON;
screenBuffer[8]=0;
#endif
}
else if(MwSensorActive&mode.gpshold){
screenBuffer[2]=0;
screenBuffer[0] = SYM_GHOLD;
screenBuffer[1] = SYM_GHOLD1;
}
#if defined MULTIWII_V24
else if(MwSensorActive&mode.gpsmission){
itoa(GPS_waypoint_step,screenBuffer+2,10);
screenBuffer[4]=0;
screenBuffer[0] = SYM_GMISSION;
screenBuffer[1] = SYM_GMISSION1;
}
else if(MwSensorActive&mode.gpsland){
screenBuffer[2]=0;
screenBuffer[0] = SYM_GLAND;
screenBuffer[1] = SYM_GLAND1;
}
#endif //MULTIWII_V24
else if(MwSensorActive&mode.stable){
screenBuffer[2]=0;
screenBuffer[0]=SYM_STABLE;
screenBuffer[1]=SYM_STABLE1;
}
else if(MwSensorActive&mode.horizon){
screenBuffer[2]=0;
screenBuffer[0]=SYM_HORIZON;
screenBuffer[1]=SYM_HORIZON1;
}
else{
screenBuffer[2]=0;
#ifdef FIXEDWING
screenBuffer[0]=SYM_ACROGY;
#else
screenBuffer[0]=SYM_ACRO;
#endif
screenBuffer[1]=SYM_ACRO1;
//#if defined BETAFLIGHT
if((MwSensorActive)&(mode.acroplus)){
screenBuffer[1]=SYM_PLUS;
}
//#endif //BETAFLIGHT
}
if(Settings[S_MODEICON]){
if(fieldIsVisible(ModePosition)){
MAX7456_WriteString(screenBuffer,getPosition(ModePosition));
#ifdef AIRMODE
if((MwSensorActive)&(mode.air)){
screenBuffer[0]=SYM_AIR;
screenBuffer[1]=SYM_AIR1;
screenBuffer[2]=0;
MAX7456_WriteString(screenBuffer,getPosition(ModePosition)+AIRMODE);
}
#endif //AIRMODE
}
}
#ifdef APINDICATOR
if(timer.Blink2hz)
return;
if(!fieldIsVisible(APstatusPosition))
return;
uint8_t apactive=0;
if (MwSensorActive&mode.gpshome)
apactive=6;
else if (MwSensorActive&mode.gpshold)
apactive=7;
else if (MwSensorActive&mode.gpsmission)
apactive=8;
else
return;
strcpy_P(screenBuffer, (char*)pgm_read_word(&(message_item[apactive])));
MAX7456_WriteString(screenBuffer, getPosition(APstatusPosition));
#endif
}
void displayCallsign(int cposition)
{
for(uint8_t X=0; X<10; X++) {
screenBuffer[X] = char(Settings[S_CS0 + X]);
}
screenBuffer[10] = 0;
MAX7456_WriteString(screenBuffer, cposition);
}
void displayHorizon(int rollAngle, int pitchAngle)
{
#ifdef DISPLAY_PR
screenBuffer[0]=0x50;
int16_t xx=abs(pitchAngle/10);
uint8_t offset=1;
if(pitchAngle<0) {
screenBuffer[1]='-';
offset++;
}
itoa(xx, screenBuffer+offset,10);
if(fieldIsVisible(pitchAnglePosition))
MAX7456_WriteString(screenBuffer,getPosition(pitchAnglePosition));
screenBuffer[0]=0x52;
offset=1;
xx=abs(rollAngle/10);
if(rollAngle<0) {
screenBuffer[1]='-';
offset++;
}
itoa(xx, screenBuffer+offset,10);
if(fieldIsVisible(rollAnglePosition))
MAX7456_WriteString(screenBuffer,getPosition(rollAnglePosition));
#endif
#ifdef HORIZON
if (Settings[S_SCROLLING]||Settings[S_SIDEBARTOPS]){
if(!armed) GPS_speed=0;
// Scrolling decoration
if (GPS_speed > (old_GPS_speed+15)){
sidebarsMillis = millis();
sidebarsdir = 2;
old_GPS_speed = GPS_speed;
SYM_AH_DECORATION_LEFT--;
if (SYM_AH_DECORATION_LEFT<0x10)
SYM_AH_DECORATION_LEFT=0x15;
}
else if ((GPS_speed+15) < old_GPS_speed){
sidebarsMillis = millis();
sidebarsdir = 1;
old_GPS_speed = GPS_speed;
SYM_AH_DECORATION_LEFT++;
if (SYM_AH_DECORATION_LEFT>0x15)
SYM_AH_DECORATION_LEFT=0x10;
}
if (MwAltitude > old_MwAltitude+20){
sidebaraMillis = millis();
sidebaradir = 2;
old_MwAltitude = MwAltitude;
SYM_AH_DECORATION_RIGHT--;
if (SYM_AH_DECORATION_RIGHT<0x10)
SYM_AH_DECORATION_RIGHT=0x15;
}
else if (MwAltitude+20 < old_MwAltitude){
sidebaraMillis = millis();
sidebaradir = 1;
old_MwAltitude = MwAltitude;
SYM_AH_DECORATION_RIGHT++;
if (SYM_AH_DECORATION_RIGHT>0x15)
SYM_AH_DECORATION_RIGHT=0x10;
}
}
if (!Settings[S_SCROLLING]){
SYM_AH_DECORATION_LEFT=0x13;
SYM_AH_DECORATION_RIGHT=0x13;
}
uint16_t position = getPosition(horizonPosition);
if(pitchAngle>AHIPITCHMAX) pitchAngle=AHIPITCHMAX;
if(pitchAngle<-AHIPITCHMAX) pitchAngle=-AHIPITCHMAX;
if(rollAngle>AHIROLLMAX) rollAngle=AHIROLLMAX;
if(rollAngle<-AHIROLLMAX) rollAngle=-AHIROLLMAX;
#ifndef AHICORRECT
#define AHICORRECT 10
#endif
pitchAngle=pitchAngle+AHICORRECT;
#if defined REVERSEAHI
pitchAngle=-pitchAngle;
rollAngle=-rollAngle;
#endif //REVERSEAHI
if(Settings[S_DISPLAY_HORIZON_BR]&fieldIsVisible(horizonPosition)){
#ifdef FULLAHI
for(uint8_t X=0; X<=12; X++) {
if (X==6) X=7;
int Y = (rollAngle * (4-X)) / 64;
Y -= pitchAngle / 8;
Y += 41;
if(Y >= 0 && Y <= 81) {
uint16_t pos = position -9 + LINE*(Y/9) + 3 - 4*LINE + X;
screen[pos] = SYM_AH_BAR9_0+(Y%9);
if (Settings[S_HORIZON_ELEVATION]){
if(X >= 4 && X <= 8) {
screen[pos-3*LINE] = SYM_AH_BAR9_0+(Y%9);
screen[pos+3*LINE] = SYM_AH_BAR9_0+(Y%9);
}
}
}
}
#else //FULLAHI
for(uint8_t X=0; X<=8; X++) {
if (X==4) X=5;
int Y = (rollAngle * (4-X)) / 64;
Y -= pitchAngle / 8;
Y += 41;
if(Y >= 0 && Y <= 81) {
uint16_t pos = position -7 + LINE*(Y/9) + 3 - 4*LINE + X;
screen[pos] = SYM_AH_BAR9_0+(Y%9);
if (Settings[S_HORIZON_ELEVATION]){
if(X >= 2 && X <= 6) {
screen[pos-3*LINE] = SYM_AH_BAR9_0+(Y%9);
screen[pos+3*LINE] = SYM_AH_BAR9_0+(Y%9);
}
}
}
}
#endif //FULLAHI
if(!fieldIsVisible(MapModePosition)){
if(Settings[S_DISPLAY_HORIZON_BR]){
screen[position-1] = SYM_AH_CENTER_LINE;
screen[position+1] = SYM_AH_CENTER_LINE_RIGHT;
screen[position] = SYM_AH_CENTER;
}
}
}
if (Settings[S_WITHDECORATION]&fieldIsVisible(SideBarPosition)){
// Draw AH sides
int8_t hudwidth= getPosition(SideBarWidthPosition)&0x0F;
int8_t hudheight= getPosition(SideBarHeightPosition)&0x0F;
for(int8_t X=-hudheight; X<=hudheight; X++) {
screen[position-hudwidth+(X*LINE)] = SYM_AH_DECORATION_LEFT;
screen[position+hudwidth+(X*LINE)] = SYM_AH_DECORATION_RIGHT;
}
#if defined AHILEVEL
screen[position-hudwidth+1] = SYM_AH_LEFT;
screen[position+hudwidth-1] = SYM_AH_RIGHT;
#endif //AHILEVEL
#if defined(USEGLIDESCOPE) && defined(FIXEDWING)
if(Settings[S_DISPLAYGPS]){
displayfwglidescope();
}
#endif //USEGLIDESCOPE
#ifdef SBDIRECTION
if (Settings[S_SIDEBARTOPS]&fieldIsVisible(SideBarScrollPosition)) {
if (millis()<(sidebarsMillis + 1000)) {
if (sidebarsdir == 2){
screen[position-(hudheight*LINE)-hudwidth] = SYM_AH_DECORATION_UP;
}
else{
screen[position+(hudheight*LINE)-hudwidth] = SYM_AH_DECORATION_DOWN;
}
}
if (millis()<(sidebaraMillis + 1000)) {
if (sidebaradir == 2){
screen[position-(hudheight*LINE)+hudwidth] = SYM_AH_DECORATION_UP;
}
else{
screen[position+(hudheight*LINE)+hudwidth] = SYM_AH_DECORATION_DOWN;
}
}
}
#endif //SBDIRECTION
}
#endif //HORIZON
}
void displayVoltage(void)
{
if (Settings[S_MAINVOLTAGE_VBAT]){
voltage=MwVBat;
}
#ifdef AUTOCELL
uint8_t tcells = ((voltage-3) / MvVBatMaxCellVoltage) + 1;
if (tcells>cells){
if (tcells<11){
cells=tcells;
}
}
voltageWarning = cells * MvVBatWarningCellVoltage;
#ifdef AUTOCELL_VOLTAGE
voltageWarning = cells * Settings[S_VOLTAGEMIN];
#endif // AUTOCELL_VOLTAGE
#else //NOT AUTOCELL
voltageWarning = Settings[S_VOLTAGEMIN];
cells = Settings[S_BATCELLS];
#endif //AUTOCELL
#ifdef BATTERYICONVOLTS
if (Settings[S_SHOWBATLEVELEVOLUTION])
{
uint8_t battev = 0;
int batevlow = cells * MvVBatMinCellVoltage;
int batevhigh = cells * MvVBatMaxCellVoltage;
battev = constrain(voltage, batevlow, batevhigh-2);
battev = map(battev, batevlow, batevhigh-1, 0, 7);
screenBuffer[0]=(SYM_BATT_EMPTY)-battev;
}
else
#endif // BATTERYICONVOLTS
{
screenBuffer[0]=SYM_MAIN_BATT;
}
if ((voltage<voltageWarning)&&(timer.Blink2hz))
return;
#ifdef DISP_LOW_VOLTS_WARNING
if (voltage<=voltageWarning&&!armedtimer)
MAX7456_WriteString_P(lowvolts_text, getPosition(motorArmedPosition));
#endif
#ifdef FORCE_DISP_LOW_VOLTS
if(fieldIsVisible(voltagePosition)||(voltage<=voltageWarning))
#else
if(fieldIsVisible(voltagePosition))
#endif
{
ItoaPadded(voltage, screenBuffer+1, 4, 3);
screenBuffer[5] = SYM_VOLT;
screenBuffer[6] = 0;
MAX7456_WriteString(screenBuffer,getPosition(voltagePosition)-1);
}
}
void displayVidVoltage(void)
{
if((vidvoltage<vidvoltageWarning)&&(timer.Blink2hz))
return;
#ifdef FORCE_DISP_LOW_VID_VOLTS
if(fieldIsVisible(vidvoltagePosition)||(vidvoltage<=vidvoltageWarning))
#else
if(fieldIsVisible(vidvoltagePosition))
#endif
{
screenBuffer[0]=SYM_VID_BAT;
ItoaPadded(vidvoltage, screenBuffer+1, 4, 3);
screenBuffer[5] = SYM_VOLT;
screenBuffer[6] = 0;
MAX7456_WriteString(screenBuffer,getPosition(vidvoltagePosition)-1);
}
}
void displayCurrentThrottle(void)
{
if(!fieldIsVisible(CurrentThrottlePosition))
return;
#ifndef NOTHROTTLESPACE
#define THROTTLESPACE 1
#else
#define THROTTLESPACE 0
#endif
screenBuffer[1]=' ';
#ifdef AUTOTHROTTLE
if (MwRcData[THROTTLESTICK] > HighT) HighT = MwRcData[THROTTLESTICK];
if (MwRcData[THROTTLESTICK] < LowT) LowT = MwRcData[THROTTLESTICK]; // Calibrate high and low throttle settings --defaults set in GlobalVariables.h 1100-1900
if (HighT>2050) HighT=2050;
if (LowT<950) LowT=950;
#else
HighT=HIGHTHROTTLE;
LowT=LOWTHROTTLE;
#endif
uint32_t Vthrottle = constrain(MwRcData[THROTTLESTICK],1000,2000);
#ifndef FIXEDWING
if(!armed) {
screenBuffer[0+THROTTLESPACE]=' ';
screenBuffer[1+THROTTLESPACE]=' ';
screenBuffer[2+THROTTLESPACE]='-';
screenBuffer[3+THROTTLESPACE]='-';
screenBuffer[4+THROTTLESPACE]=' ';
}
else
#endif // FIXEDWING
{
int CurThrottle = map(MwRcData[THROTTLESTICK],LowT,HighT,0,100);
ItoaPadded(CurThrottle,screenBuffer+1+THROTTLESPACE,3,0);
screenBuffer[4+THROTTLESPACE]='%';
}
screenBuffer[0]=SYM_THR;
screenBuffer[5+THROTTLESPACE]=0;
MAX7456_WriteString(screenBuffer,getPosition(CurrentThrottlePosition));
}
void displayTime(void)
{
if(!Settings[S_TIMER])
return;
if (screenPosition[onTimePosition]<512)
return;
uint32_t displaytime;
if (armed) {
if(((flyTime/60)>=Settings[S_FLYTIME_ALARM])&&(timer.Blink2hz))
return;
if(flyTime < 3600) {
screenBuffer[0] = SYM_FLY_M;
displaytime = flyTime;
}
else {
screenBuffer[0] = SYM_FLY_H;
displaytime = flyTime/60;
}
}
else {
if(onTime < 3600) {
screenBuffer[0] = SYM_ON_M;
displaytime = onTime;
}
else {
screenBuffer[0] = SYM_ON_H;
displaytime = onTime/60;
}
}
formatTime(displaytime, screenBuffer+1, 0);
MAX7456_WriteString(screenBuffer,getPosition(onTimePosition));
}
void displayAmperage(void)
{
if(amperage > ampMAX)
ampMAX = amperage;
if(!fieldIsVisible(amperagePosition))
return;
ItoaPadded(amperage, screenBuffer, 5, 4); // 999.9 ampere max!
screenBuffer[5] = SYM_AMP;
screenBuffer[6] = 0;
MAX7456_WriteString(screenBuffer,getPosition(amperagePosition));
}
void displayWatt(void)
{
if(!fieldIsVisible(wattPosition))
return;
uint16_t WhrPosition = getPosition(wattPosition);
uint16_t watts = amperage*voltage/100;
ItoaPadded(watts, screenBuffer+1 , 5, 5);
screenBuffer[0] = SYM_BLANK;
screenBuffer[5] = SYM_WATT;
screenBuffer[6] = 0;
MAX7456_WriteString(screenBuffer,WhrPosition);
}
void displaypMeterSum(void)
{
if(!fieldIsVisible(pMeterSumPosition))
return;
#ifdef BATTERYICONAMPS
uint16_t battev =0;
if (Settings[S_SHOWBATLEVELEVOLUTION]){
battev=amperagesum/(360*Settings[S_AMPER_HOUR_ALARM]);
battev=constrain(battev,0,100);
battev = map(100-battev, 0, 101, 0, 7);
screenBuffer[0]=SYM_BATT_EMPTY-battev;
screenBuffer[1]=SYM_MAH;
int xx=amperagesum/360;
itoa(xx,screenBuffer+2,10);
}
else
#endif //BATTERYICONAMPS
{
screenBuffer[0]=SYM_MAH;
int xx=amperagesum/360;
itoa(xx,screenBuffer+1,10);
}
MAX7456_WriteString(screenBuffer,getPosition(pMeterSumPosition));
}
void displayI2CError(void)
{
#ifdef I2CERROR
if (I2CError<=I2CERROR)
return;
screenBuffer[0] = 0x49;
screenBuffer[1] = 0X3A;
itoa(I2CError,screenBuffer+2,10);
MAX7456_WriteString(screenBuffer,getPosition(temperaturePosition));
#endif
}
void displayRSSI(void)
{
if(!fieldIsVisible(rssiPosition))
return;
screenBuffer[0] = SYM_RSSI;
itoa(rssi,screenBuffer+1,10);
uint8_t xx = FindNull();
screenBuffer[xx++] = '%';
screenBuffer[xx] = 0;
MAX7456_WriteString(screenBuffer,getPosition(rssiPosition)-1);
}
void displayHeading(void)
{
if(!fieldIsVisible(MwHeadingPosition))
return;
if (Settings[S_SHOWHEADING]) {
int16_t heading = MwHeading;
if (Settings[S_HEADING360]) {
if(heading < 0)
heading += 360;
ItoaPadded(heading,screenBuffer,3,0);
screenBuffer[3]=SYM_DEGREES;
screenBuffer[4]=0;
}
else {
ItoaPadded(heading,screenBuffer,4,0);
screenBuffer[4]=SYM_DEGREES;
screenBuffer[5]=0;
}
MAX7456_WriteString(screenBuffer,getPosition(MwHeadingPosition));
}
}
void displayHeadingGraph(void)
{
if (!fieldIsVisible(MwHeadingGraphPosition))
return;
if (!Settings[S_COMPASS])
return;
int xx;
xx = MwHeading * 4;
xx = xx + 720 + 45;
xx = xx / 90;
uint16_t pos = getPosition(MwHeadingGraphPosition);
memcpy_P(screen+pos, headGraph+xx+1, 9);
}
void displayIntro(void)
{
const int startCol = 4;
int line = LINE02;
MAX7456_WriteString_P(message0, line+startCol);
line += LINE*2;
#ifndef GPSOSD
MAX7456_WriteString_P(message5, line+startCol);
MAX7456_WriteString(ItoaPadded(MwVersion, screenBuffer, 4, 2), line+startCol+11);
line += LINE;
#endif
#ifdef INTRO_CALLSIGN
MAX7456_WriteString_P(message9, line+startCol);
displayCallsign(line+startCol+4);
line += LINE;
#endif
#ifdef GPSTIME
#ifdef INTRO_TIMEZONE
//timezone
MAX7456_WriteString_P(message10, line+startCol);
if(abs(Settings[S_GPSTZ]) >= 100)ItoaPadded(Settings[S_GPSTZ], screenBuffer, 5, 4);
else ItoaPadded(Settings[S_GPSTZ], screenBuffer, 4, 3);
if(Settings[S_GPSTZAHEAD] || Settings[S_GPSTZ] == 0)screenBuffer[0] = '+';
else screenBuffer[0] = '-';
MAX7456_WriteString(screenBuffer, line+startCol+8);
line += LINE;
//more settings
MAX7456_WriteString_P(message11, line+startCol);
#endif
#endif
#ifdef INTRO_MENU
MAX7456_WriteString_P(message6, line+startCol);
line += LINE;
MAX7456_WriteString_P(message7, line+startCol+10);
line += LINE;
MAX7456_WriteString_P(message8, line+startCol+10);
line += LINE;
#endif
#ifdef HAS_ALARMS
if (alarmState != ALARM_OK) {
line += LINE;
MAX7456_WriteString((const char*)alarmMsg, line+startCol);
}
#endif
}
void displayGPSPosition(void)
{
uint16_t position;
if(!GPS_fix)
return;
displayGPSAltitude();
if(!fieldIsVisible(MwGPSLatPositionTop))
return;
/* if (!MwSensorActive&mode.gpshome)
return;*/
if(Settings[S_COORDINATES]|(MwSensorActive&mode.gpshome)){
position = getPosition(MwGPSLatPositionTop);
screenBuffer[0] = SYM_LAT;
FormatGPSCoord(GPS_latitude,screenBuffer+1,4,'N','S');
MAX7456_WriteString(screenBuffer, position);
position = getPosition(MwGPSLonPositionTop);
screenBuffer[0] = SYM_LON;
FormatGPSCoord(GPS_longitude,screenBuffer+1,4,'E','W');
MAX7456_WriteString(screenBuffer, position);
}
}
void displayGPSAltitude(void){
if(Settings[S_GPSALTITUDE]){
if(!fieldIsVisible(MwGPSAltPosition))
return;
screenBuffer[0] = MwGPSAltPositionAdd[Settings[S_UNITSYSTEM]];
uint16_t xx;
if(Settings[S_UNITSYSTEM])
xx = GPS_altitude * 3.2808; // Mt to Feet
else
xx = GPS_altitude; // Mt
if(((xx/10)>=Settings[S_ALTITUDE_ALARM])&&(timer.Blink2hz))
return;
itoa(xx,screenBuffer+1,10);
MAX7456_WriteString(screenBuffer,getPosition(MwGPSAltPosition));
}
}
void displayNumberOfSat(void)
{
if((GPS_numSat<MINSATFIX)&&(timer.Blink2hz)){
return;
}
if(!fieldIsVisible(GPS_numSatPosition))
return;
screenBuffer[0] = SYM_SAT_L;
screenBuffer[1] = SYM_SAT_R;
itoa(GPS_numSat,screenBuffer+2,10);
MAX7456_WriteString(screenBuffer,getPosition(GPS_numSatPosition));
}
void displayGPS_speed(void)
{
if(!GPS_fix) return;
if(!armed) GPS_speed=0;
uint16_t xx;
if(!Settings[S_UNITSYSTEM])
xx = GPS_speed * 0.036; // From MWii cm/sec to Km/h
else
xx = GPS_speed * 0.02236932; // (0.036*0.62137) From MWii cm/sec to mph
if(xx > speedMAX)
speedMAX = xx;
if(!fieldIsVisible(speedPosition))
return;
if((xx>Settings[S_SPEED_ALARM])&&(timer.Blink2hz))
return;
screenBuffer[0]=speedUnitAdd[Settings[S_UNITSYSTEM]];
itoa(xx,screenBuffer+1,10);
MAX7456_WriteString(screenBuffer,getPosition(speedPosition));
#ifdef SHOW_MAX_SPEED
itoa(speedMAX,screenBuffer+1,10);
MAX7456_WriteString(screenBuffer,getPosition(speedPosition)+LINE);
#endif //SHOW_MAX_SPEED
}
void displayGPS_time(void) //local time of coord calc - haydent
{
if(!GPS_fix) return;
if(!Settings[S_GPSTIME]) return;
if(!fieldIsVisible(GPS_timePosition)) return;
//convert to local
int TZ_SIGN = (Settings[S_GPSTZAHEAD] ? 1 :-1);
uint32_t local = GPS_time + (((Settings[S_GPSTZ] * 60 * TZ_SIGN / 10)) * 60000);//make correction for time zone
local = local % 604800000;//prob not necessary but keeps day of week accurate <= 7
//convert to local
//format and display
// uint16_t milli = local % 1000;//get milli for later
uint32_t seconds = (local / 1000) % 86400;//remove millisonds and whole days
formatTime(seconds, screenBuffer, 1);
if(screenBuffer[0] == ' ')screenBuffer[0] = '0';//put leading zero if empty space
/*
screenBuffer[8] = '.';//add milli indicator
screenBuffer[9] = '0' + (milli / 100);//only show first digit of milli due to limit of gps rate
screenBuffer[10] = 0;//equivalent of new line or end of buffer
*/
screenBuffer[8] = 0;//equivalent of new line or end of buffer
MAX7456_WriteString(screenBuffer,getPosition(GPS_timePosition));
}
void displayAltitude(void)
{
int16_t altitude;
if(Settings[S_UNITSYSTEM])
altitude = MwAltitude*0.032808; // cm to feet
else
altitude = MwAltitude/100; // cm to mt
if(armed && allSec>5 && altitude > altitudeMAX)
altitudeMAX = altitude;
if(!fieldIsVisible(MwAltitudePosition))
return;
if(!Settings[S_BAROALT])
return;
if(((altitude/10)>=Settings[S_ALTITUDE_ALARM])&&(timer.Blink2hz))
return;
screenBuffer[0]=MwAltitudeAdd[Settings[S_UNITSYSTEM]];
itoa(altitude,screenBuffer+1,10);
MAX7456_WriteString(screenBuffer,getPosition(MwAltitudePosition));
#ifdef SHOW_MAX_ALTITUDE
itoa(altitudeMAX,screenBuffer+1,10);
MAX7456_WriteString(screenBuffer,getPosition(MwAltitudePosition)+LINE);
#endif //SHOW_MAX_ALTITUDE
}
void displayClimbRate(void)
{
if(!fieldIsVisible(MwClimbRatePosition))
return;
if(!Settings[S_VARIO])
return;
uint16_t position = getPosition(MwClimbRatePosition);
for(int8_t X=-1; X<=1; X++) {
screen[position+(X*LINE)] = SYM_VARIO;
}
int8_t xx=MwVario;
if (MwVario>120) xx=120;
if (MwVario<-120) xx=-120;
xx=map(xx,120,-120,0,17);
int8_t varline=(xx/6)-1;
int8_t varsymbol=xx%6;
screen[position+(varline*LINE)] = 0x8F-varsymbol;
}
void displayDistanceToHome(void)
{
if(!GPS_fix)
return;
uint16_t dist;
if(Settings[S_UNITSYSTEM])
dist = GPS_distanceToHome * 3.2808; // mt to feet
else
dist = GPS_distanceToHome; // Mt
if(dist > distanceMAX)
distanceMAX = dist;
if(!fieldIsVisible(GPS_distanceToHomePosition))