-
Notifications
You must be signed in to change notification settings - Fork 1
/
menus.cpp
executable file
·6987 lines (6222 loc) · 186 KB
/
menus.cpp
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
/*
* Author - Erez Raviv <erezraviv@gmail.com>
*
* Based on th9x -> http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "er9x.h"
#include <stdlib.h>
#include "templates.h"
#include "menus.h"
#ifdef FRSKY
#include "frsky.h"
#endif
#include "language.h"
#define THROTTLE_TRACE 1
union t_xmem Xmem ;
//extern void putVoiceQueue( uint8_t value ) ;
//extern int8_t Rotary_diff ;
extern int16_t AltOffset ;
#ifdef PHASES
static uint8_t s_currIdx;
#endif
NOINLINE void resetTimer1(void) ;
struct t_timerg TimerG ;
uint8_t RotaryState ; // Defaults to ROTARY_MENU_LR
extern int16_t getAltbaroWithOffset() ;
const prog_char APM Str_Switch_warn[] = STR_SWITCH_WARN ;
const prog_char APM Str_ALTeq[] = STR_ALTEQ ;
const prog_char APM Str_TXeq[] = STR_TXEQ ;
const prog_char APM Str_RXeq[] = STR_RXEQ ;
const prog_char APM Str_TRE012AG[] = STR_TRE012AG ;
const prog_char APM Str_YelOrgRed[] = STR_YELORGRED ;
const prog_char APM Str_A_eq[] = STR_A_EQ ;
const prog_char APM Str_Timer[] = STR_TIMER ;
const prog_char APM Str_Sounds[] = STR_SOUNDS ;
int8_t phyStick[4] ;
#define FR_WATT -11
#define V_GVAR1 -10
#define V_GVAR2 -9
#define V_GVAR3 -8
#define V_GVAR4 -7
#define V_GVAR5 -6
#define V_GVAR6 -5
#define V_GVAR7 -4
#define BATTERY -3
#define TIMER1 -2
#define TIMER2 -1
#define TEL_ITEM_A1 0
#define TEL_ITEM_A2 1
#define TEL_ITEM_RSSI 2
#define TEL_ITEM_TSSI 3
#define TEL_ITEM_TIM1 4
#define TEL_ITEM_TIM2 5
#define TEL_ITEM_BALT 6
#define TEL_ITEM_GALT 7
#define TEL_ITEM_GSPD 8
#define TEL_ITEM_T1 9
#define TEL_ITEM_T2 10
#define TEL_ITEM_RPM 11
#define TEL_ITEM_FUEL 12
#define TEL_ITEM_MAH1 13
#define TEL_ITEM_MAH2 14
#define TEL_ITEM_CVLT 15
#define TEL_ITEM_BATT 16
#define TEL_ITEM_AMPS 17
#define TEL_ITEM_MAHC 18
#define TEL_ITEM_CTOT 19
#define TEL_ITEM_FASV 20
#define TEL_ITEM_ACCX 21
#define TEL_ITEM_ACCY 22
#define TEL_ITEM_ACCZ 23
#define TEL_ITEM_VSPD 24
#define TEL_ITEM_GVAR1 25
#define TEL_ITEM_GVAR2 26
#define TEL_ITEM_GVAR3 27
#define TEL_ITEM_GVAR4 28
#define TEL_ITEM_GVAR5 29
#define TEL_ITEM_GVAR6 30
#define TEL_ITEM_GVAR7 31
#define TEL_ITEM_FWATT 32
#ifdef FRSKY
// TSSI set to zero on no telemetry data
const prog_char APM Str_telemItems[] = STR_TELEM_ITEMS ;
const prog_int8_t APM TelemIndex[] = {FR_A1_COPY, FR_A2_COPY,
FR_RXRSI_COPY, FR_TXRSI_COPY,
TIMER1, TIMER2,
FR_ALT_BARO, FR_GPS_ALT,
FR_GPS_SPEED, FR_TEMP1, FR_TEMP2, FR_RPM,
FR_FUEL, FR_A1_MAH, FR_A2_MAH, FR_CELL_MIN,
BATTERY, FR_CURRENT, FR_AMP_MAH, FR_CELLS_TOT, FR_VOLTS,
FR_ACCX, FR_ACCY, FR_ACCZ, FR_VSPD, V_GVAR1, V_GVAR2,
V_GVAR3, V_GVAR4, V_GVAR5, V_GVAR6, V_GVAR7, FR_WATT } ;
const prog_uint8_t APM TelemValid[] = { 1, 1, 1, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2 } ;
#else
const prog_char APM Str_telemItems[] = STR_TELEM_SHORT ;
const prog_int8_t APM TelemIndex[] = { TIMER1, TIMER2, BATTERY, V_GVAR1, V_GVAR2, V_GVAR3, V_GVAR4, V_GVAR5, V_GVAR6, V_GVAR7 } ;
const prog_uint8_t APM TelemValid[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
#endif
int8_t edit_dr_switch( uint8_t x, uint8_t y, int8_t drswitch, uint8_t attr, uint8_t edit ) ;
NOINLINE int16_t m_to_ft( int16_t metres )
{
int16_t result ;
// m to ft *105/32
result = metres * 3 ;
metres >>= 2 ;
result += metres ;
metres >>= 2 ;
return result + (metres >> 1 );
}
NOINLINE int16_t c_to_f( int16_t degrees )
{
degrees += 18 ;
degrees *= 115 ;
degrees >>= 6 ;
return degrees ;
}
uint8_t telemItemValid( uint8_t index )
{
#ifdef FRSKY
uint8_t x ;
x = pgm_read_byte( &TelemValid[index] ) ;
if ( x == 0 )
{
return 1 ;
}
if ( x == 1 )
{
if ( frskyStreaming )
{
return 1 ;
}
}
if ( frskyUsrStreaming )
{
return 1 ;
}
return 0 ;
#else
return 1 ;
#endif
}
void voice_telem_item( int8_t index )
{
int16_t value ;
uint8_t spoken = 0 ;
uint8_t unit = 0 ;
uint8_t num_decimals = 0 ;
#ifdef FRSKY
uint8_t att = 0 ;
#endif
value = get_telemetry_value( index ) ;
if (telemItemValid( index ) == 0 )
{
putVoiceQueue( V_NOTELEM ) ;
spoken = 1 ;
}
index = pgm_read_byte( &TelemIndex[index] ) ;
switch (index)
{
case BATTERY:
#ifdef FRSKY
case FR_VOLTS :
case FR_CELLS_TOT :
#endif
unit = V_VOLTS ;
num_decimals = 1 ;
break ;
#ifdef FRSKY
case FR_CELL_MIN:
unit = V_VOLTS ;
num_decimals = 2 ;
break ;
#endif
case TIMER1 :
case TIMER2 :
{
div_t qr ;
qr = div( value, 60 ) ;
voice_numeric( qr.quot, 0, V_MINUTES ) ;
value = qr.rem ;
unit = V_SECONDS ;
}
break ;
case V_GVAR1 :
case V_GVAR2 :
case V_GVAR3 :
case V_GVAR4 :
case V_GVAR5 :
case V_GVAR6 :
case V_GVAR7 :
value = g_model.gvars[index-V_GVAR1].gvar ;
break ;
#ifdef FRSKY
case FR_A1_COPY:
case FR_A2_COPY:
{
FrSkyChannelData *fd ;
fd = &g_model.frsky.channels[index-FR_A1_COPY] ;
uint8_t ltype = fd->opt.alarm.type ;
uint8_t lratio = fd->opt.alarm.ratio ;
value = scale_telem_value( value, index-FR_A1_COPY, (ltype == 2/*V*/), &att ) ;
unit = V_VOLTS ;
num_decimals = 1 ;
if (ltype == 3)
{
unit = V_AMPS ;
}
else if (ltype == 1)
{
unit = 0 ;
num_decimals = 0 ;
}
else
{
if ( lratio < 100 )
{
num_decimals = 2 ;
}
}
}
break ;
case FR_ALT_BARO:
unit = V_METRES ;
if (g_model.FrSkyUsrProto == 1) // WS How High
{
if ( g_model.FrSkyImperial )
unit = V_FEET ;
}
else
{
if ( g_model.FrSkyImperial )
{
// m to ft *105/32
value = m_to_ft( value ) ;
unit = V_FEET ;
}
}
if ( value < 1000 )
{
num_decimals = 1 ;
}
else
{
value /= 10 ;
}
break ;
case FR_CURRENT :
num_decimals = 1 ;
unit = V_AMPS ;
break ;
case FR_TEMP1:
case FR_TEMP2:
unit = V_DEGREES ;
if ( g_model.FrSkyImperial )
{
value = c_to_f(value) ;
}
break ;
case FR_WATT :
unit = V_WATTS ;
break ;
// case FR_A1_MAH:
// break ;
case FR_VSPD :
num_decimals = 1 ;
value /= 10 ;
break ;
#endif
}
if ( spoken == 0 )
{
voice_numeric( value, num_decimals, unit ) ;
}
}
// This routine converts an 8 bit value for custom switch use
int16_t convertTelemConstant( int8_t channel, int8_t value)
{
int16_t result;
channel = pgm_read_byte( &TelemIndex[channel] ) ;
result = value + 125 ;
switch (channel)
{
// unneeded cases:
// case FR_A1_COPY :
// case FR_A2_COPY :
// case FR_RXRSI_COPY :
// case FR_TXRSI_COPY :
// cases not implemented, to consider:
// case FR_GPS_SPEED :
// case FR_FUEL :
// case FR_CURRENT :
case TIMER1 :
case TIMER2 :
result *= 10 ;
break;
#ifdef FRSKY
case FR_ALT_BARO:
case FR_GPS_ALT:
if ( result > 63 )
{
result *= 2 ;
result -= 64 ;
}
if ( result > 192 )
{
result *= 2 ;
result -= 192 ;
}
if ( result > 448 )
{
result *= 2 ;
result -= 488 ;
}
result *= 10 ; // Allow for decimal place
if ( g_model.FrSkyImperial )
{
// m to ft *105/32
result = m_to_ft( result ) ;
}
break;
case FR_RPM:
result *= 100;
break;
case FR_TEMP1:
case FR_TEMP2:
result -= 30;
break;
case FR_A1_MAH:
case FR_A2_MAH:
case FR_AMP_MAH :
result *= 50;
break;
case FR_CELL_MIN:
result *= 2;
break ;
case FR_CELLS_TOT :
case FR_VOLTS :
result *= 2;
break ;
case FR_WATT:
result *= 8 ;
break;
case FR_VSPD :
result = value * 10 ;
break ;
#endif
}
return result;
}
int16_t get_telemetry_value( int8_t channel )
{
channel = pgm_read_byte( &TelemIndex[channel] ) ;
#ifdef FRSKY
if ( channel == FR_WATT )
{
return (getTelemetryValue(FR_VOLTS)>>1) * ( getTelemetryValue(FR_CURRENT)>>1) / 25 ;
}
#endif
if ( channel < -3 ) // A GVAR
{
return g_model.gvars[channel-V_GVAR1].gvar ;
}
switch (channel)
{
case TIMER1 :
case TIMER2 :
return TimerG.s_timerVal[channel+2] ;
case BATTERY :
return g_vbat100mV ;
#ifdef FRSKY
case FR_ALT_BARO :
return getAltbaroWithOffset() ;
case FR_CELL_MIN :
return getTelemetryValue(channel) * 2 ;
default :
return getTelemetryValue(channel) ;
#else
default :
return 0 ;
#endif
}
}
// Styles
#define TELEM_LABEL 0x01
#define TELEM_UNIT 0x02
#define TELEM_UNIT_LEFT 0x04
#define TELEM_VALUE_RIGHT 0x08
uint8_t putsTelemetryChannel(uint8_t x, uint8_t y, int8_t channel, int16_t val, uint8_t att, uint8_t style)
{
uint8_t unit = ' ' ;
uint8_t xbase = x ;
uint8_t fieldW = FW ;
uint8_t displayed = 0 ;
if ( style & TELEM_LABEL )
{
lcd_putsAttIdx( x, y, Str_telemItems, channel+1, 0 ) ;
x += 4*FW ;
if ( att & DBLSIZE )
{
x += 4 ;
y -= FH ;
fieldW += FW ;
}
}
if (style & TELEM_VALUE_RIGHT)
{
att &= ~LEFT ;
}
channel = pgm_read_byte( &TelemIndex[channel] ) ;
switch (channel)
{
case TIMER1 :
case TIMER2 :
if ( (att & DBLSIZE) == 0 )
{
x -= 4 ;
}
if ( style & TELEM_LABEL )
{
x += FW+4 ;
}
att &= DBLSIZE | INVERS | BLINK ;
putsTime(x-FW, y, val, att, att) ;
displayed = 1 ;
unit = channel + 2 + '1';
xbase -= FW ;
break ;
#ifdef FRSKY
case FR_A1_COPY:
case FR_A2_COPY:
// uint8_t blink ;
// blink = (alarmRaised[i] ? INVERS+BLINK : 0)|LEFT;
channel -= FR_A1_COPY ;
unit = putsTelemValue( (style & TELEM_VALUE_RIGHT) ? xbase+61 : x-fieldW, y, val, channel, att|NO_UNIT/*|blink*/, 1 ) ;
displayed = 1 ;
break ;
case FR_TEMP1:
case FR_TEMP2:
unit = 'C' ;
if ( g_model.FrSkyImperial )
{
val = c_to_f(val) ;
unit = 'F' ;
x -= fieldW ;
}
break;
case FR_ALT_BARO:
case FR_GPS_ALT:
unit = 'm' ;
if ( g_model.FrSkyImperial )
{
if (g_model.FrSkyUsrProto == 0) // Not WS How High
{
// m to ft *105/32
val = m_to_ft( val ) ;
}
unit = 'f' ;
}
if ( val < 1000 )
{
att |= PREC1 ;
}
else
{
val /= 10 ;
}
break;
case FR_CURRENT :
att |= PREC1 ;
unit = 'A' ;
break ;
case FR_CELL_MIN:
att |= PREC2 ;
unit = 'v' ;
break ;
case FR_CELLS_TOT :
case FR_VOLTS :
att |= PREC1 ;
unit = 'v' ;
break ;
case BATTERY:
att |= PREC1 ;
unit = 'v' ;
break ;
case FR_WATT :
unit = 'w' ;
break ;
case FR_VSPD :
att |= PREC1 ;
val /= 10 ;
break ;
default:
break;
#endif
}
if ( !displayed )
{
lcd_outdezAtt( (style & TELEM_VALUE_RIGHT) ? xbase+61 : x, y, val, att ) ;
}
if ( style & ( TELEM_UNIT | TELEM_UNIT_LEFT ) )
{
if ( style & TELEM_UNIT_LEFT )
{
x = xbase + FW + 4 ;
att &= ~DBLSIZE ;
}
else
{
x = lcd_lastPos ;
}
lcd_putcAtt( x, y, unit, att);
}
return unit ;
}
//#ifdef FRSKY
//// This is for the customisable telemetry display
//void display_custom_telemetry_value( uint8_t x, uint8_t y, int8_t index )
//{
// lcd_putsAttIdx( x, y, Str_telemItems, index+1, 0 ) ;
// index = pgm_read_byte( &TelemIndex[index] ) ;
// if ( index < 0 )
// { // A timer
// putsTime( x+4*FW, y, s_timerVal[index+2], 0, 0);
// }
// else
// { // A telemetry value
// }
//}
//#endif
//int16_t get_telem_value( uint8_t index )
//{
// index = pgm_read_byte( &TelemIndex[index] ) ;
// if ( index < 0 )
// { // A timer
// return s_timerVal[index+2] ;
// }
//#ifdef FRSKY
// return FrskyHubData[index] ;
//#else
// return 0 ; // What else - TODO
//#endif
//}
/*
#define GET_DR_STATE(x) (!getSwitch(g_model.expoData[x].drSw1,0) ? \
DR_HIGH : \
!getSwitch(g_model.expoData[x].drSw2,0)? \
DR_MID : DR_LOW);
*/
#if GVARS
void dispGvar( uint8_t x, uint8_t y, uint8_t gvar, uint8_t attr )
{
lcd_putsAtt( x, y, PSTR(STR_GV), attr ) ;
lcd_putcAtt( x+2*FW, y, gvar+'0', attr ) ;
}
int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, uint8_t attr )
{
uint8_t invers = attr&(INVERS|BLINK);
if (invers && Tevent == EVT_KEY_LONG(KEY_MENU))
{
value = ((value >= 126 || value <= -126) ? g_model.gvars[(uint8_t)value-126].gvar : 126);
eeDirty(EE_MODEL);
}
if (value >= 126 || value <= -126)
{
dispGvar( x-3*FW, y, (uint8_t)value - 125, attr ) ;
// lcd_putsAtt( x-3*FW, y, PSTR("GV"), attr ) ;
// lcd_putcAtt( x-FW, y, (uint8_t)value - 125+'0', attr ) ;
if (invers) value = checkIncDec16((uint8_t)value, 126, 130, EE_MODEL);
}
else
{
lcd_outdezAtt(x, y, value, attr ) ;
if (invers) CHECK_INCDEC_H_MODELVAR(value, min, max);
}
return value;
}
//void displayGVar(uint8_t x, uint8_t y, int8_t value)
//{
// if (value >= 126 || value <= -126)
// {
// lcd_puts_P( x-3*FW, y, PSTR("GV") ) ;
// lcd_putc( x-FW, y, (uint8_t)value - 125+'0') ;
// }
// else
// {
// lcd_outdez(x, y, value ) ;
// }
//}
#endif
uint8_t get_dr_state(uint8_t x)
{
ExpoData *ped ;
ped = &g_model.expoData[x] ;
return (!getSwitch( ped->drSw1,0) ? DR_HIGH :
!getSwitch( ped->drSw2,0) ? DR_MID : DR_LOW) ;
}
//#define DO_SQUARE(xx,yy,ww)
// lcd_vline(xx-ww/2,yy-ww/2,ww);
// lcd_hline(xx-ww/2,yy+ww/2,ww);
// lcd_vline(xx+ww/2,yy-ww/2,ww);
// lcd_hline(xx-ww/2,yy-ww/2,ww);
void DO_SQUARE(uint8_t x, uint8_t y, uint8_t w)
{
// uint8_t x,y,w ; x = xx; y = yy; w = ww ;
lcd_vline(x-w/2,y-w/2,w);
lcd_hline(x-w/2,y+w/2,w);
lcd_vline(x+w/2,y-w/2,w);
lcd_hline(x-w/2,y-w/2,w);
}
#define DO_CROSS(xx,yy,ww) \
lcd_vline(xx,yy-ww/2,ww); \
lcd_hline(xx-ww/2,yy,ww); \
#define V_BAR(xx,yy,ll) \
lcd_vline(xx-1,yy-ll,ll); \
lcd_vline(xx ,yy-ll,ll); \
lcd_vline(xx+1,yy-ll,ll); \
#define NO_HI_LEN 25
#define WCHART 32
#define X0 (128-WCHART-2)
#define Y0 32
#define WCHARTl 32l
#define X0l (128l-WCHARTl-2)
#define Y0l 32l
#define RESX (1<<10) // 1024
#define RESXu 1024u
#define RESXul 1024ul
#define RESXl 1024l
#define RESKul 100ul
#define RESX_PLUS_TRIM (RESX+128)
#define TRIM_EXTENDED_MAX 500
enum MainViews {
e_outputValues,
e_outputBars,
e_inputs1,
// e_inputs2,
// e_inputs3,
e_timer2,
#if (defined(FRSKY) | defined(HUB))
e_telemetry,
// e_telemetry2,
#endif
MAX_VIEWS
};
int16_t calibratedStick[7];
int16_t ex_chans[NUM_CHNOUT]; // Outputs + intermidiates
uint8_t s_pgOfs;
uint8_t s_editMode;
uint8_t s_editing;
uint8_t s_noHi;
#ifndef NOPOTSCROLL
int8_t scrollLR;
uint8_t scroll_disabled;
int8_t scrollUD;
#endif
int16_t g_chans512[NUM_CHNOUT];
extern bool warble;
extern MixData *mixaddress( uint8_t idx ) ;
extern LimitData *limitaddress( uint8_t idx ) ;
const
#include "sticks.lbm"
typedef PROGMEM void (*MenuFuncP_PROGMEM)(uint8_t event);
enum EnumTabModel {
// e_ModelSelect,
e_Model,
#ifndef NO_HELI
e_Heli,
#endif
#ifdef PHASES
e_Phases,
#endif
e_ExpoAll,
e_Mix,
// e_nMix,
e_Limits,
e_Curve,
e_Switches,
e_SafetySwitches,
#ifdef FRSKY
e_Telemetry,
e_Telemetry2,
#endif
#ifndef NO_TEMPLATES
e_Templates,
#endif
#if GVARS
e_Globals
#endif
};
const MenuFuncP_PROGMEM APM menuTabModel[] = {
// menuProcModelSelect,
menuProcModel,
#ifndef NO_HELI
menuProcHeli,
#endif
#ifdef PHASES
menuModelPhases,
#endif
menuProcExpoAll,
menuProcMix,
// menuProcnMix,
menuProcLimits,
menuProcCurve,
menuProcSwitches,
menuProcSafetySwitches,
#ifdef FRSKY
menuProcTelemetry,
menuProcTelemetry2,
#endif
#ifndef NO_TEMPLATES
menuProcTemplates,
#endif
#if GVARS
menuProcGlobals
#endif
};
enum EnumTabDiag {
e_Setup,
e_Trainer,
e_Vers,
e_Keys,
e_Ana,
e_Calib
};
const MenuFuncP_PROGMEM APM menuTabDiag[] = {
menuProcSetup,
menuProcTrainer,
menuProcDiagVers,
menuProcDiagKeys,
menuProcDiagAna,
menuProcDiagCalib
};
#define MENU_TAB_NONE 0
#define MENU_TAB_MODEL 1
#define MENU_TAB_DIAG 2
#define SIZE_MTAB_MODEL DIM(menuTabModel)
#define SIZE_MTAB_DIAG DIM(menuTabDiag)
uint8_t TITLEP( const prog_char *pstr) { return lcd_putsAtt(0,0,pstr,INVERS) ; }
static const prog_char *get_curve_string()
{
return PSTR(CURV_STR)+1 ;
}
void menu_lcd_onoff( uint8_t x,uint8_t y, uint8_t value, uint8_t mode )
{
lcd_putsAtt( x, y, value ? Str_ON : Str_OFF,mode ? INVERS:0) ;
}
void menu_lcd_HYPHINV( uint8_t x,uint8_t y, uint8_t value, uint8_t mode )
{
lcd_putsAttIdx( x, y, PSTR(STR_HYPH_INV),value,mode ? INVERS:0) ;
}
void MState2::check_simple(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, uint8_t maxrow)
{
check(event, curr, menuTab, menuTabSize, 0, 0, maxrow);
}
void MState2::check_submenu_simple(uint8_t event, uint8_t maxrow)
{
check_simple(event, 0, 0, 0, maxrow);
}
//extern uint16_t MixRate ;
static void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr)
{
uint8_t x ;
if ( RotaryState == ROTARY_MENU_LR )
{
attr = BLINK ;
}
lcd_outdezAtt(127,0,count,attr);
x = 1+128-FW*(count>9 ? 3 : 2) ;
lcd_putcAtt(x,0,'/',attr);
lcd_outdezAtt(x-1,0,index+1,attr);
// lcd_putc( x-12, 0, RotaryState + '0' ) ;
// lcd_outdezAtt(64,0,MixRate,0) ;
}
uint8_t g_posHorz ;
#define MAXCOL(row) (horTab ? pgm_read_byte(horTab+min(row, horTabMax)) : (const uint8_t)0)
#define INC(val,max) if(val<max) {val++;} else {val=0;}
#define DEC(val,max) if(val>0 ) {val--;} else {val=max;}
void MState2::check(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, const prog_uint8_t *horTab, uint8_t horTabMax, uint8_t maxrow)
{
uint8_t l_posHorz ;
l_posHorz = g_posHorz ;
#ifndef NOPOTSCROLL
int16_t c4, c5 ;
struct t_p1 *ptrp1 ;
// scrollLR = 0;
// scrollUD = 0;
//check pot 2 - if changed -> scroll menu
//check pot 3 if changed -> cursor down/up
//we do this in these brackets to prevent it from happening in the main screen
c4 = calibratedStick[4] ; // Read only once
c5 = calibratedStick[5] ; // Read only once
ptrp1 = &P1values ;
FORCE_INDIRECT(ptrp1) ;
scrollLR = ( ptrp1->p2valprev-c4)/SCROLL_TH;
scrollUD = ( ptrp1->p3valprev-c5)/SCROLL_TH;
if(scrollLR) ptrp1->p2valprev = c4;
if(scrollUD) ptrp1->p3valprev = c5;
if(scroll_disabled || g_eeGeneral.disablePotScroll)
{
scrollLR = 0;
scrollUD = 0;
scroll_disabled = 0;
}
if(scrollLR || scrollUD || ptrp1->p1valdiff) g_LightOffCounter = (g_eeGeneral.lightAutoOff*250) << 1; // on keypress turn the light on 5*100
// *250 then <<1 is the same as *500, but uses less code space
#endif
if (menuTab) {
uint8_t attr = m_posVert==0 ? INVERS : 0;
if(m_posVert==0)
{
// if ( s_editMode == 0 )
// {
if ( RotaryState == ROTARY_MENU_LR )
{
if ( Rotary.Rotary_diff > 0 )
{
event = EVT_KEY_FIRST(KEY_RIGHT) ;
}
else if ( Rotary.Rotary_diff < 0 )
{
event = EVT_KEY_FIRST(KEY_LEFT) ;
}
Rotary.Rotary_diff = 0 ;
if(event==EVT_KEY_BREAK(BTN_RE))
{
RotaryState = ROTARY_MENU_UD ;
event = 0 ;
}
}
else if ( RotaryState == ROTARY_MENU_UD )
{
if(event==EVT_KEY_BREAK(BTN_RE))
{
RotaryState = ROTARY_MENU_LR ;
event = 0 ;
}
}
// }
#ifndef NOPOTSCROLL
if(scrollLR && !s_editMode)
{
int8_t cc = curr - scrollLR;
if(cc<1) cc = 0;
if(cc>(menuTabSize-1)) cc = menuTabSize-1;
if(cc!=curr)
{
// if(((MenuFuncP)pgm_read_adr(&menuTab[cc])) == menuProcDiagCalib)
// chainMenu(menuProcDiagAna);
// else
chainMenu((MenuFuncP)pgm_read_adr(&menuTab[cc]));
return ;
}
scrollLR = 0;
}
#endif
if(event==EVT_KEY_FIRST(KEY_LEFT))
{
uint8_t index ;
if(curr>0)
index = curr ;
// chainMenu((MenuFuncP)pgm_read_adr(&menuTab[curr-1]));
else
index = menuTabSize ;
chainMenu((MenuFuncP)pgm_read_adr(&menuTab[index-1]));
return ;
}
if(event==EVT_KEY_FIRST(KEY_RIGHT))
{
uint8_t index ;
if(curr < (menuTabSize-1))