[companion] Adjust GVAR not possible in global functions (fix #5425)
[opentx.git] / companion / src / radiodata.h
blob6911adb43c2ba66cc8f496287ed8fc39a5f6679a
1 #ifndef _RADIODATA_H_
2 #define _RADIODATA_H_
4 #include "boards.h"
5 #include "constants.h"
6 #include <QString>
7 #include <QComboBox>
9 class Firmware;
11 enum Switches {
12 SWITCH_NONE,
14 SWITCH_THR = SWITCH_NONE+1,
15 SWITCH_RUD,
16 SWITCH_ELE,
17 SWITCH_ID0,
18 SWITCH_ID1,
19 SWITCH_ID2,
20 SWITCH_AIL,
21 SWITCH_GEA,
22 SWITCH_TRN,
24 SWITCH_SA0 = SWITCH_NONE+1,
25 SWITCH_SA1,
26 SWITCH_SA2,
27 SWITCH_SB0,
28 SWITCH_SB1,
29 SWITCH_SB2,
30 SWITCH_SC0,
31 SWITCH_SC1,
32 SWITCH_SC2,
33 SWITCH_SD0,
34 SWITCH_SD1,
35 SWITCH_SD2,
36 SWITCH_SE0,
37 SWITCH_SE1,
38 SWITCH_SE2,
39 SWITCH_SF0,
40 SWITCH_SF1,
41 SWITCH_SG0,
42 SWITCH_SG1,
43 SWITCH_SG2,
44 SWITCH_SH0,
45 SWITCH_SH2,
46 SWITCH_SI0,
47 SWITCH_SI2,
48 SWITCH_SJ0,
49 SWITCH_SJ2,
50 SWITCH_SK0,
51 SWITCH_SK2,
54 enum TimerModes {
55 TMRMODE_NONE,
56 TMRMODE_ABS,
57 TMRMODE_THR,
58 TMRMODE_THR_REL,
59 TMRMODE_THR_TRG,
60 TMRMODE_FIRST_SWITCH
63 enum FailsafeModes {
64 FAILSAFE_NOT_SET,
65 FAILSAFE_HOLD,
66 FAILSAFE_CUSTOM,
67 FAILSAFE_NOPULSES,
68 FAILSAFE_RECEIVER,
69 FAILSAFE_LAST = FAILSAFE_RECEIVER
72 #define CHAR_FOR_NAMES " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
73 #define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"
75 enum HeliSwashTypes {
76 HELI_SWASH_TYPE_NONE=0,
77 HELI_SWASH_TYPE_120,
78 HELI_SWASH_TYPE_120X,
79 HELI_SWASH_TYPE_140,
80 HELI_SWASH_TYPE_90
83 class ModelData;
84 class GeneralSettings;
86 enum TelemetrySource {
87 TELEMETRY_SOURCE_TX_BATT,
88 TELEMETRY_SOURCE_TX_TIME,
89 TELEMETRY_SOURCE_TIMER1,
90 TELEMETRY_SOURCE_TIMER2,
91 TELEMETRY_SOURCE_TIMER3,
92 TELEMETRY_SOURCE_SWR,
93 TELEMETRY_SOURCE_RSSI_TX,
94 TELEMETRY_SOURCE_RSSI_RX,
95 TELEMETRY_SOURCE_A1,
96 TELEMETRY_SOURCE_A2,
97 TELEMETRY_SOURCE_A3,
98 TELEMETRY_SOURCE_A4,
99 TELEMETRY_SOURCE_ALT,
100 TELEMETRY_SOURCE_RPM,
101 TELEMETRY_SOURCE_FUEL,
102 TELEMETRY_SOURCE_T1,
103 TELEMETRY_SOURCE_T2,
104 TELEMETRY_SOURCE_SPEED,
105 TELEMETRY_SOURCE_DIST,
106 TELEMETRY_SOURCE_GPS_ALT,
107 TELEMETRY_SOURCE_CELL,
108 TELEMETRY_SOURCE_CELLS_SUM,
109 TELEMETRY_SOURCE_VFAS,
110 TELEMETRY_SOURCE_CURRENT,
111 TELEMETRY_SOURCE_CONSUMPTION,
112 TELEMETRY_SOURCE_POWER,
113 TELEMETRY_SOURCE_ACCX,
114 TELEMETRY_SOURCE_ACCY,
115 TELEMETRY_SOURCE_ACCZ,
116 TELEMETRY_SOURCE_HDG,
117 TELEMETRY_SOURCE_VERTICAL_SPEED,
118 TELEMETRY_SOURCE_ASPEED,
119 TELEMETRY_SOURCE_DTE,
120 TELEMETRY_SOURCE_A1_MIN,
121 TELEMETRY_SOURCE_A2_MIN,
122 TELEMETRY_SOURCE_A3_MIN,
123 TELEMETRY_SOURCE_A4_MIN,
124 TELEMETRY_SOURCE_ALT_MIN,
125 TELEMETRY_SOURCE_ALT_MAX,
126 TELEMETRY_SOURCE_RPM_MAX,
127 TELEMETRY_SOURCE_T1_MAX,
128 TELEMETRY_SOURCE_T2_MAX,
129 TELEMETRY_SOURCE_SPEED_MAX,
130 TELEMETRY_SOURCE_DIST_MAX,
131 TELEMETRY_SOURCE_ASPEED_MAX,
132 TELEMETRY_SOURCE_CELL_MIN,
133 TELEMETRY_SOURCE_CELLS_MIN,
134 TELEMETRY_SOURCE_VFAS_MIN,
135 TELEMETRY_SOURCE_CURRENT_MAX,
136 TELEMETRY_SOURCE_POWER_MAX,
137 TELEMETRY_SOURCE_ACC,
138 TELEMETRY_SOURCE_GPS_TIME,
139 TELEMETRY_SOURCES_STATUS_COUNT = TELEMETRY_SOURCE_GPS_TIME+1,
140 TELEMETRY_SOURCES_DISPLAY_COUNT = TELEMETRY_SOURCE_POWER_MAX+1,
141 TELEMETRY_SOURCES_COUNT = TELEMETRY_SOURCE_POWER_MAX+1,
142 TELEMETRY_SOURCE_RESERVE = -1
145 #define TM_HASTELEMETRY 0x01
146 #define TM_HASOFFSET 0x02
147 #define TM_HASWSHH 0x04
149 enum RawSourceType {
150 SOURCE_TYPE_NONE,
151 SOURCE_TYPE_VIRTUAL_INPUT,
152 SOURCE_TYPE_LUA_OUTPUT,
153 SOURCE_TYPE_STICK, // and POTS
154 SOURCE_TYPE_ROTARY_ENCODER,
155 SOURCE_TYPE_TRIM,
156 SOURCE_TYPE_MAX,
157 SOURCE_TYPE_SWITCH,
158 SOURCE_TYPE_CUSTOM_SWITCH,
159 SOURCE_TYPE_CYC,
160 SOURCE_TYPE_PPM,
161 SOURCE_TYPE_CH,
162 SOURCE_TYPE_GVAR,
163 SOURCE_TYPE_SPECIAL,
164 SOURCE_TYPE_TELEMETRY,
165 MAX_SOURCE_TYPE
168 class RawSourceRange
170 public:
171 RawSourceRange():
172 decimals(0),
173 min(0.0),
174 max(0.0),
175 step(1.0),
176 offset(0.0)
180 float getValue(int value);
182 int decimals;
183 double min;
184 double max;
185 double step;
186 double offset;
187 QString unit;
190 #define RANGE_SINGLE_PRECISION 1
191 #define RANGE_DELTA_FUNCTION 2
192 #define RANGE_DELTA_ABS_FUNCTION 4
194 class RawSource {
195 public:
196 RawSource():
197 type(SOURCE_TYPE_NONE),
198 index(0)
202 explicit RawSource(int value):
203 type(RawSourceType(abs(value)/65536)),
204 index(value >= 0 ? abs(value)%65536 : -(abs(value)%65536))
208 RawSource(RawSourceType type, int index=0):
209 type(type),
210 index(index)
214 RawSource convert(Board::Type before, Board::Type after);
216 inline const int toValue() const
218 return index >= 0 ? (type * 65536 + index) : -(type * 65536 - index);
221 QString toString(const ModelData * model = NULL, const GeneralSettings * const generalSettings = NULL) const;
223 RawSourceRange getRange(const ModelData * model, const GeneralSettings & settings, unsigned int flags=0) const;
225 bool operator == ( const RawSource & other) {
226 return (this->type == other.type) && (this->index == other.index);
229 bool operator != ( const RawSource & other) {
230 return (this->type != other.type) || (this->index != other.index);
233 bool isTimeBased() const;
234 bool isStick(int * potsIndex = NULL) const;
235 bool isPot(int * potsIndex = NULL) const;
236 bool isSlider(int * sliderIndex = NULL) const;
238 RawSourceType type;
239 int index;
242 enum RawSwitchType {
243 SWITCH_TYPE_NONE,
244 SWITCH_TYPE_SWITCH,
245 SWITCH_TYPE_VIRTUAL,
246 SWITCH_TYPE_MULTIPOS_POT,
247 SWITCH_TYPE_TRIM,
248 SWITCH_TYPE_ROTARY_ENCODER,
249 SWITCH_TYPE_ON,
250 SWITCH_TYPE_OFF,
251 SWITCH_TYPE_ONE,
252 SWITCH_TYPE_FLIGHT_MODE,
253 SWITCH_TYPE_TIMER_MODE,
254 SWITCH_TYPE_TELEMETRY,
255 SWITCH_TYPE_SENSOR,
258 class RawSwitch {
259 public:
260 RawSwitch():
261 type(SWITCH_TYPE_NONE),
262 index(0)
266 explicit RawSwitch(int value):
267 type(RawSwitchType(abs(value)/256)),
268 index(value >= 0 ? abs(value)%256 : -(abs(value)%256))
272 RawSwitch(RawSwitchType type, int index=0):
273 type(type),
274 index(index)
278 inline const int toValue() const
280 return index >= 0 ? (type * 256 + index) : -(type * 256 - index);
283 QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL) const;
285 bool operator== ( const RawSwitch& other) {
286 return (this->type == other.type) && (this->index == other.index);
289 bool operator!= ( const RawSwitch& other) {
290 return (this->type != other.type) || (this->index != other.index);
293 RawSwitch convert(Board::Type before, Board::Type after);
295 RawSwitchType type;
296 int index;
299 class CurveReference {
300 public:
301 enum CurveRefType {
302 CURVE_REF_DIFF,
303 CURVE_REF_EXPO,
304 CURVE_REF_FUNC,
305 CURVE_REF_CUSTOM
308 CurveReference() { clear(); }
310 CurveReference(CurveRefType type, int value):
311 type(type),
312 value(value)
316 void clear() { memset(this, 0, sizeof(CurveReference)); }
318 CurveRefType type;
319 int value;
321 QString toString(const ModelData * model = NULL, bool verbose = true) const;
324 enum InputMode {
325 INPUT_MODE_NONE,
326 INPUT_MODE_POS,
327 INPUT_MODE_NEG,
328 INPUT_MODE_BOTH
331 class ExpoData {
332 public:
333 ExpoData() { clear(); }
334 RawSource srcRaw;
335 unsigned int scale;
336 unsigned int mode;
337 unsigned int chn;
338 RawSwitch swtch;
339 unsigned int flightModes; // -5=!FP4, 0=normal, 5=FP4
340 int weight;
341 int offset;
342 CurveReference curve;
343 int carryTrim;
344 char name[10+1];
345 void clear() { memset(this, 0, sizeof(ExpoData)); }
346 void convert(Board::Type before, Board::Type after);
349 class CurvePoint {
350 public:
351 int8_t x;
352 int8_t y;
355 class CurveData {
356 public:
357 enum CurveType {
358 CURVE_TYPE_STANDARD,
359 CURVE_TYPE_CUSTOM,
360 CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM
363 CurveData();
364 void clear(int count);
365 bool isEmpty() const;
366 QString nameToString(const int idx) const;
368 CurveType type;
369 bool smooth;
370 int count;
371 CurvePoint points[CPN_MAX_POINTS];
372 char name[6+1];
375 class LimitData {
376 public:
377 LimitData() { clear(); }
378 int min;
379 int max;
380 bool revert;
381 int offset;
382 int ppmCenter;
383 bool symetrical;
384 char name[6+1];
385 CurveReference curve;
386 QString minToString() const;
387 QString maxToString() const;
388 QString offsetToString() const;
389 QString revertToString() const;
390 void clear();
393 enum MltpxValue {
394 MLTPX_ADD=0,
395 MLTPX_MUL=1,
396 MLTPX_REP=2
399 #define MIXDATA_NAME_LEN 10
401 class MixData {
402 public:
403 MixData() { clear(); }
404 void convert(Board::Type before, Board::Type after);
406 unsigned int destCh; // 1..CPN_MAX_CHNOUT
407 RawSource srcRaw;
408 int weight;
409 RawSwitch swtch;
410 CurveReference curve; //0=symmetrisch
411 unsigned int delayUp;
412 unsigned int delayDown;
413 unsigned int speedUp; // Servogeschwindigkeit aus Tabelle (10ms Cycle)
414 unsigned int speedDown; // 0 nichts
415 int carryTrim;
416 bool noExpo;
417 MltpxValue mltpx; // multiplex method 0=+ 1=* 2=replace
418 unsigned int mixWarn; // mixer warning
419 unsigned int flightModes; // -5=!FP4, 0=normal, 5=FP4
420 int sOffset;
421 char name[MIXDATA_NAME_LEN+1];
423 void clear() { memset(this, 0, sizeof(MixData)); }
426 enum CSFunction {
427 LS_FN_OFF,
428 LS_FN_VPOS,
429 LS_FN_VNEG,
430 LS_FN_APOS,
431 LS_FN_ANEG,
432 LS_FN_AND,
433 LS_FN_OR,
434 LS_FN_XOR,
435 LS_FN_EQUAL,
436 LS_FN_NEQUAL,
437 LS_FN_GREATER,
438 LS_FN_LESS,
439 LS_FN_EGREATER,
440 LS_FN_ELESS,
441 LS_FN_DPOS,
442 LS_FN_DAPOS,
443 LS_FN_VEQUAL, // added at the end to avoid everything renumbered
444 LS_FN_VALMOSTEQUAL,
445 LS_FN_TIMER,
446 LS_FN_STICKY,
447 LS_FN_EDGE,
448 // later ... LS_FN_RANGE,
449 LS_FN_MAX
452 enum CSFunctionFamily {
453 LS_FAMILY_VOFS,
454 LS_FAMILY_VBOOL,
455 LS_FAMILY_VCOMP,
456 LS_FAMILY_TIMER,
457 LS_FAMILY_STICKY,
458 LS_FAMILY_EDGE,
461 class LogicalSwitchData { // Logical Switches data
462 public:
463 LogicalSwitchData(unsigned int func=0)
465 clear();
466 this->func = func;
468 unsigned int func;
469 int val1;
470 int val2;
471 int val3;
472 unsigned int delay;
473 unsigned int duration;
474 int andsw;
476 void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
477 bool isEmpty() const;
478 CSFunctionFamily getFunctionFamily() const;
479 unsigned int getRangeFlags() const;
480 QString funcToString() const;
481 void convert(Board::Type before, Board::Type after);
484 enum AssignFunc {
485 FuncOverrideCH1 = 0,
486 FuncOverrideCH32 = FuncOverrideCH1+CPN_MAX_CHNOUT-1,
487 FuncTrainer,
488 FuncTrainerRUD,
489 FuncTrainerELE,
490 FuncTrainerTHR,
491 FuncTrainerAIL,
492 FuncInstantTrim,
493 FuncPlaySound,
494 FuncPlayHaptic,
495 FuncReset,
496 FuncSetTimer1,
497 FuncSetTimer2,
498 FuncSetTimer3,
499 FuncVario,
500 FuncPlayPrompt,
501 FuncPlayBoth,
502 FuncPlayValue,
503 FuncPlayScript,
504 FuncLogs,
505 FuncVolume,
506 FuncBacklight,
507 FuncScreenshot,
508 FuncBackgroundMusic,
509 FuncBackgroundMusicPause,
510 FuncAdjustGV1,
511 FuncAdjustGVLast = FuncAdjustGV1+CPN_MAX_GVARS-1,
512 FuncSetFailsafeInternalModule,
513 FuncSetFailsafeExternalModule,
514 FuncRangeCheckInternalModule,
515 FuncRangeCheckExternalModule,
516 FuncBindInternalModule,
517 FuncBindExternalModule,
518 FuncCount,
519 FuncReserve = -1
522 enum GVarAdjustModes
524 FUNC_ADJUST_GVAR_CONSTANT,
525 FUNC_ADJUST_GVAR_SOURCE,
526 FUNC_ADJUST_GVAR_GVAR,
527 FUNC_ADJUST_GVAR_INCDEC
530 class CustomFunctionData { // Function Switches data
531 public:
532 CustomFunctionData(AssignFunc func=FuncOverrideCH1) { clear(); this->func = func; }
533 RawSwitch swtch;
534 AssignFunc func;
535 int param;
536 char paramarm[10];
537 unsigned int enabled; // TODO perhaps not any more the right name
538 unsigned int adjustMode;
539 int repeatParam;
541 void clear();
542 bool isEmpty() const;
543 QString funcToString(const ModelData * model = NULL) const;
544 QString paramToString(const ModelData * model) const;
545 QString repeatToString() const;
546 QString enabledToString() const;
548 static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value);
549 static void populatePlaySoundParams(QStringList & qs);
550 static void populateHapticParams(QStringList & qs);
552 void convert(Board::Type before, Board::Type after);
556 class FlightModeData {
557 public:
558 FlightModeData() { clear(0); }
559 int trimMode[CPN_MAX_TRIMS];
560 int trimRef[CPN_MAX_TRIMS];
561 int trim[CPN_MAX_TRIMS];
562 RawSwitch swtch;
563 char name[10+1];
564 unsigned int fadeIn;
565 unsigned int fadeOut;
566 int rotaryEncoders[CPN_MAX_ENCODERS];
567 int gvars[CPN_MAX_GVARS];
568 void clear(const int phase);
569 void convert(Board::Type before, Board::Type after);
572 class SwashRingData { // Swash Ring data
573 public:
574 SwashRingData() { clear(); }
575 int elevatorWeight;
576 int aileronWeight;
577 int collectiveWeight;
578 unsigned int type;
579 RawSource collectiveSource;
580 RawSource aileronSource;
581 RawSource elevatorSource;
582 unsigned int value;
583 void clear() { memset(this, 0, sizeof(SwashRingData)); }
586 class FrSkyAlarmData {
587 public:
588 FrSkyAlarmData() { clear(); }
589 unsigned int level; // 0=none, 1=Yellow, 2=Orange, 3=Red
590 unsigned int greater; // 0=LT(<), 1=GT(>)
591 unsigned int value; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
593 void clear() { memset(this, 0, sizeof(FrSkyAlarmData)); }
596 class RSSIAlarmData {
597 public:
598 RSSIAlarmData() { clear(); }
599 unsigned int level[2]; // AVR Only
600 int warning;
601 int critical;
602 bool disabled;
603 void clear() {
604 this->level[0] = 2;
605 this->level[1] = 3;
606 this->warning = 45;
607 this->critical = 42;
608 this->disabled = false;
612 class FrSkyChannelData {
613 public:
614 FrSkyChannelData() { clear(); }
615 unsigned int ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
616 unsigned int type; // future use: 0=volts, 1=ml...
617 int offset;
618 unsigned int multiplier;
619 FrSkyAlarmData alarms[2];
621 float getRatio() const;
622 RawSourceRange getRange() const;
623 void clear() { memset(this, 0, sizeof(FrSkyChannelData)); }
626 struct FrSkyBarData {
627 RawSource source;
628 int barMin; // minimum for bar display
629 int barMax; // ditto for max display (would usually = ratio)
632 struct FrSkyLineData {
633 RawSource source[3];
636 struct TelemetryScriptData {
637 char filename[8+1];
640 enum TelemetryScreenEnum {
641 TELEMETRY_SCREEN_NONE,
642 TELEMETRY_SCREEN_NUMBERS,
643 TELEMETRY_SCREEN_BARS,
644 TELEMETRY_SCREEN_SCRIPT
647 class FrSkyScreenData {
648 public:
649 FrSkyScreenData() { clear(); }
651 typedef struct {
652 FrSkyBarData bars[4];
653 FrSkyLineData lines[4];
654 TelemetryScriptData script;
655 } FrSkyScreenBody;
657 unsigned int type;
658 FrSkyScreenBody body;
660 void clear();
663 enum TelemetryVarioSources {
664 TELEMETRY_VARIO_SOURCE_ALTI,
665 TELEMETRY_VARIO_SOURCE_ALTI_PLUS,
666 TELEMETRY_VARIO_SOURCE_VSPEED,
667 TELEMETRY_VARIO_SOURCE_A1,
668 TELEMETRY_VARIO_SOURCE_A2,
669 TELEMETRY_VARIO_SOURCE_DTE,
672 enum TelemetryVoltsSources {
673 TELEMETRY_VOLTS_SOURCE_A1,
674 TELEMETRY_VOLTS_SOURCE_A2,
675 TELEMETRY_VOLTS_SOURCE_A3,
676 TELEMETRY_VOLTS_SOURCE_A4,
677 TELEMETRY_VOLTS_SOURCE_FAS,
678 TELEMETRY_VOLTS_SOURCE_CELLS
681 enum TelemetryCurrentSources {
682 TELEMETRY_CURRENT_SOURCE_NONE,
683 TELEMETRY_CURRENT_SOURCE_A1,
684 TELEMETRY_CURRENT_SOURCE_A2,
685 TELEMETRY_CURRENT_SOURCE_A3,
686 TELEMETRY_CURRENT_SOURCE_A4,
687 TELEMETRY_CURRENT_SOURCE_FAS
690 enum UartModes {
691 UART_MODE_NONE,
692 UART_MODE_TELEMETRY_MIRROR,
693 UART_MODE_TELEMETRY,
694 UART_MODE_SBUS_TRAINER,
695 UART_MODE_DEBUG
698 enum TrainerMode {
699 TRAINER_MODE_MASTER_TRAINER_JACK,
700 TRAINER_MODE_SLAVE,
701 TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE,
702 TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE,
703 TRAINER_MODE_MASTER_BATTERY_COMPARTMENT,
706 class FrSkyData {
707 public:
708 FrSkyData() { clear(); }
709 FrSkyChannelData channels[4];
710 unsigned int usrProto;
711 int blades;
712 unsigned int voltsSource;
713 unsigned int altitudeSource;
714 unsigned int currentSource;
715 FrSkyScreenData screens[4];
716 unsigned int varioSource;
717 bool varioCenterSilent;
718 int varioMin;
719 int varioCenterMin; // if increment in 0.2m/s = 3.0m/s max
720 int varioCenterMax;
721 int varioMax;
722 bool mAhPersistent;
723 unsigned int storedMah;
724 int fasOffset;
725 bool ignoreSensorIds;
727 void clear();
730 class MavlinkData {
731 public:
732 MavlinkData() { clear();}
733 unsigned int rc_rssi_scale;
734 unsigned int pc_rssi_en;
735 void clear() { memset(this, 0, sizeof(MavlinkData)); }
738 #define TIMER_NAME_LEN 8
740 class TimerData {
741 public:
742 enum CountDownMode {
743 COUNTDOWN_SILENT,
744 COUNTDOWN_BEEPS,
745 COUNTDOWN_VOICE,
746 COUNTDOWN_HAPTIC
748 TimerData() { clear(); }
749 RawSwitch mode;
750 char name[TIMER_NAME_LEN+1];
751 bool minuteBeep;
752 unsigned int countdownBeep;
753 unsigned int val;
754 unsigned int persistent;
755 int pvalue;
756 void clear() { memset(this, 0, sizeof(TimerData)); mode = RawSwitch(SWITCH_TYPE_TIMER_MODE, 0); }
759 enum PulsesProtocol {
760 PULSES_OFF,
761 PULSES_PPM,
762 PULSES_SILV_A,
763 PULSES_SILV_B,
764 PULSES_SILV_C,
765 PULSES_CTP1009,
766 PULSES_LP45,
767 PULSES_DSM2,
768 PULSES_DSMX,
769 PULSES_PPM16,
770 PULSES_PPMSIM,
771 PULSES_PXX_XJT_X16,
772 PULSES_PXX_XJT_D8,
773 PULSES_PXX_XJT_LR12,
774 PULSES_PXX_DJT,
775 PULSES_CROSSFIRE,
776 PULSES_MULTIMODULE,
777 PULSES_PXX_R9M,
778 PULSES_SBUS,
779 PULSES_PROTOCOL_LAST
782 enum MultiModuleRFProtocols {
783 MM_RF_PROTO_FLYSKY=0,
784 MM_RF_PROTO_FIRST=MM_RF_PROTO_FLYSKY,
785 MM_RF_PROTO_HUBSAN,
786 MM_RF_PROTO_FRSKY,
787 MM_RF_PROTO_HISKY,
788 MM_RF_PROTO_V2X2,
789 MM_RF_PROTO_DSM2,
790 MM_RF_PROTO_DEVO,
791 MM_RF_PROTO_YD717,
792 MM_RF_PROTO_KN,
793 MM_RF_PROTO_SYMAX,
794 MM_RF_PROTO_SLT,
795 MM_RF_PROTO_CX10,
796 MM_RF_PROTO_CG023,
797 MM_RF_PROTO_BAYANG,
798 MM_RF_PROTO_ESky,
799 MM_RF_PROTO_MT99XX,
800 MM_RF_PROTO_MJXQ,
801 MM_RF_PROTO_SHENQI,
802 MM_RF_PROTO_FY326,
803 MM_RF_PROTO_SFHSS,
804 MM_RF_PROTO_J6PRO,
805 MM_RF_PROTO_FQ777,
806 MM_RF_PROTO_ASSAN,
807 MM_RF_PROTO_HONTAI,
808 MM_RF_PROTO_OLRS,
809 MM_RF_PROTO_FS_AFHDS2A,
810 MM_RF_PROTO_Q2X2,
811 MM_RF_PROTO_WK_2X01,
812 MM_RF_PROTO_Q303,
813 MM_RF_PROTO_GW008,
814 MM_RF_PROTO_DM002,
815 MM_RF_PROTO_LAST=MM_RF_PROTO_DM002
818 enum TrainerProtocol {
819 TRAINER_MASTER_JACK,
820 TRAINER_SLAVE_JACK,
821 TRAINER_MASTER_SBUS_MODULE,
822 TRAINER_MASTER_CPPM_MODULE,
823 TRAINER_MASTER_SBUS_BATT_COMPARTMENT
826 class ModuleData {
827 public:
828 ModuleData() { clear(); }
829 unsigned int modelId;
830 int protocol;
831 unsigned int subType;
832 bool invertedSerial;
833 unsigned int channelsStart;
834 int channelsCount; // 0=8 channels
835 unsigned int failsafeMode;
836 int failsafeChannels[CPN_MAX_CHNOUT];
839 struct {
840 int delay;
841 bool pulsePol; // false = positive
842 bool outputType; // false = open drain, true = push pull
843 int frameLength;
844 } ppm;
846 struct {
847 unsigned int rfProtocol;
848 bool autoBindMode;
849 bool lowPowerMode;
850 bool customProto;
851 int optionValue;
852 } multi;
854 struct {
855 int power; // 0 10 mW, 1 100 mW, 2 500 mW, 3 1W
856 bool receiver_telem_off; // false = receiver telem enabled
857 bool receiver_channel_9_16; // false = pwm out 1-8, true 9-16
858 bool external_antenna; // false = internal antenna, true = external antenna
859 bool sport_out;
860 } pxx;
863 void clear() { memset(this, 0, sizeof(ModuleData)); }
864 QString polarityToString() const { return ppm.pulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter
867 #define CPN_MAX_SCRIPTS 9
868 #define CPN_MAX_SCRIPT_INPUTS 10
869 class ScriptData {
870 public:
871 ScriptData() { clear(); }
872 char filename[10+1];
873 char name[10+1];
874 int inputs[CPN_MAX_SCRIPT_INPUTS];
875 void clear() { memset(this, 0, sizeof(ScriptData)); }
878 #define CPN_MAX_SENSORS 32
879 class SensorData {
881 public:
883 enum
885 TELEM_TYPE_CUSTOM,
886 TELEM_TYPE_CALCULATED
889 enum
891 TELEM_FORMULA_ADD,
892 TELEM_FORMULA_AVERAGE,
893 TELEM_FORMULA_MIN,
894 TELEM_FORMULA_MAX,
895 TELEM_FORMULA_MULTIPLY,
896 TELEM_FORMULA_TOTALIZE,
897 TELEM_FORMULA_CELL,
898 TELEM_FORMULA_CONSUMPTION,
899 TELEM_FORMULA_DIST,
900 TELEM_FORMULA_LAST = TELEM_FORMULA_DIST
903 enum {
904 TELEM_CELL_INDEX_LOWEST,
905 TELEM_CELL_INDEX_1,
906 TELEM_CELL_INDEX_2,
907 TELEM_CELL_INDEX_3,
908 TELEM_CELL_INDEX_4,
909 TELEM_CELL_INDEX_5,
910 TELEM_CELL_INDEX_6,
911 TELEM_CELL_INDEX_HIGHEST,
912 TELEM_CELL_INDEX_DELTA,
915 enum
917 UNIT_RAW,
918 UNIT_VOLTS,
919 UNIT_AMPS,
920 UNIT_MILLIAMPS,
921 UNIT_KTS,
922 UNIT_METERS_PER_SECOND,
923 UNIT_FEET_PER_SECOND,
924 UNIT_KMH,
925 UNIT_MPH,
926 UNIT_METERS,
927 UNIT_FEET,
928 UNIT_CELSIUS,
929 UNIT_FAHRENHEIT,
930 UNIT_PERCENT,
931 UNIT_MAH,
932 UNIT_WATTS,
933 UNIT_MILLIWATTS,
934 UNIT_DB,
935 UNIT_RPMS,
936 UNIT_G,
937 UNIT_DEGREE,
938 UNIT_RADIANS,
939 UNIT_MILLILITERS,
940 UNIT_FLOZ,
941 UNIT_HOURS,
942 UNIT_MINUTES,
943 UNIT_SECONDS,
944 // FrSky format used for these fields, could be another format in the future
945 UNIT_FIRST_VIRTUAL,
946 UNIT_CELLS = UNIT_FIRST_VIRTUAL,
947 UNIT_DATETIME,
948 UNIT_GPS,
949 UNIT_GPS_LONGITUDE,
950 UNIT_GPS_LATITUDE,
951 UNIT_GPS_LONGITUDE_EW,
952 UNIT_GPS_LATITUDE_NS,
953 UNIT_DATETIME_YEAR,
954 UNIT_DATETIME_DAY_MONTH,
955 UNIT_DATETIME_HOUR_MIN,
956 UNIT_DATETIME_SEC
959 SensorData() { clear(); }
960 unsigned int type; // custom / formula
961 unsigned int id;
962 unsigned int subid;
963 unsigned int instance;
964 unsigned int persistentValue;
965 unsigned int formula;
966 char label[4+1];
967 unsigned int unit;
968 unsigned int prec;
969 bool autoOffset;
970 bool filter;
971 bool logs;
972 bool persistent;
973 bool onlyPositive;
975 // for custom sensors
976 unsigned int ratio;
977 int offset;
979 // for consumption
980 unsigned int amps;
982 // for cell
983 unsigned int source;
984 unsigned int index;
986 // for calculations
987 int sources[4];
989 // for GPS dist
990 unsigned int gps;
991 unsigned int alt;
993 bool isAvailable() const { return strlen(label) > 0; }
994 void updateUnit();
995 QString unitString() const;
996 void clear() { memset(this, 0, sizeof(SensorData)); }
1000 * TODO ...
1002 #if 0
1003 class CustomScreenOptionData {
1004 public:
1008 class CustomScreenZoneData {
1009 public:
1010 char widgetName[10+1];
1011 WidgetOptionData widgetOptions[5];
1014 class CustomScreenData {
1015 public:
1016 CustomScreenData();
1018 char layoutName[10+1];
1019 CustomScreenZoneData zones[];
1020 CustomScreenOptionData options[];
1022 #else
1023 typedef char CustomScreenData[610+1];
1024 typedef char TopbarData[216+1];
1025 #endif
1027 #define GVAR_NAME_LEN 3
1028 #define GVAR_MAX_VALUE 1024
1029 #define GVAR_MIN_VALUE -GVAR_MAX_VALUE
1031 class GVarData {
1032 public:
1033 GVarData() { clear(); }
1035 enum {
1036 GVAR_UNIT_NUMBER,
1037 GVAR_UNIT_PERCENT
1040 enum {
1041 GVAR_PREC_MUL10,
1042 GVAR_PREC_MUL1
1045 char name[GVAR_NAME_LEN+1];
1046 int min;
1047 int max;
1048 bool popup;
1049 unsigned int prec; // 0 0._ 1 0.0
1050 unsigned int unit; // 0 _ 1 %
1052 void clear() {memset(this, 0, sizeof(GVarData)); }
1053 QString unitToString() const;
1054 QString precToString() const;
1055 int multiplierSet();
1056 float multiplierGet() const;
1057 void setMin(float val);
1058 void setMax(float val);
1059 int getMin() const;
1060 int getMax() const;
1061 float getMinPrec() const;
1062 float getMaxPrec() const;
1065 class ModelData {
1066 public:
1067 ModelData();
1068 ModelData(const ModelData & src);
1069 ModelData & operator = (const ModelData & src);
1071 void convert(Board::Type before, Board::Type after);
1073 ExpoData * insertInput(const int idx);
1074 void removeInput(const int idx);
1076 bool isInputValid(const unsigned int idx) const;
1077 bool hasExpos(uint8_t inputIdx) const;
1078 bool hasMixes(uint8_t output) const;
1080 QVector<const ExpoData *> expos(int input) const;
1081 QVector<const MixData *> mixes(int channel) const;
1083 bool used;
1084 int category;
1085 char name[15+1];
1086 char filename[16+1];
1087 int modelIndex; // Companion only, temporary index position managed by data model.
1089 TimerData timers[CPN_MAX_TIMERS];
1090 bool noGlobalFunctions;
1091 bool thrTrim; // Enable Throttle Trim
1092 int trimInc; // Trim Increments
1093 unsigned int trimsDisplay;
1094 bool disableThrottleWarning;
1096 unsigned int beepANACenter; // 1<<0->A1.. 1<<6->A7
1098 bool extendedLimits; // TODO xml
1099 bool extendedTrims;
1100 bool throttleReversed;
1101 FlightModeData flightModeData[CPN_MAX_FLIGHT_MODES];
1102 MixData mixData[CPN_MAX_MIXERS];
1103 LimitData limitData[CPN_MAX_CHNOUT];
1105 char inputNames[CPN_MAX_INPUTS][4+1];
1106 ExpoData expoData[CPN_MAX_EXPOS];
1108 CurveData curves[CPN_MAX_CURVES];
1109 LogicalSwitchData logicalSw[CPN_MAX_LOGICAL_SWITCHES];
1110 CustomFunctionData customFn[CPN_MAX_SPECIAL_FUNCTIONS];
1111 SwashRingData swashRingData;
1112 unsigned int thrTraceSrc;
1113 uint64_t switchWarningStates;
1114 unsigned int switchWarningEnable;
1115 unsigned int potsWarningMode;
1116 bool potsWarningEnabled[CPN_MAX_POTS];
1117 int potPosition[CPN_MAX_POTS];
1118 bool displayChecklist;
1119 GVarData gvarData[CPN_MAX_GVARS];
1120 MavlinkData mavlink;
1121 unsigned int telemetryProtocol;
1122 FrSkyData frsky;
1123 RSSIAlarmData rssiAlarms;
1125 char bitmap[10+1];
1127 unsigned int trainerMode;
1129 ModuleData moduleData[CPN_MAX_MODULES+1/*trainer*/];
1131 ScriptData scriptData[CPN_MAX_SCRIPTS];
1133 SensorData sensorData[CPN_MAX_SENSORS];
1135 unsigned int toplcdTimer;
1137 CustomScreenData customScreenData[5];
1139 TopbarData topbarData;
1141 void clear();
1142 bool isEmpty() const;
1143 void setDefaultInputs(const GeneralSettings & settings);
1144 void setDefaultMixes(const GeneralSettings & settings);
1145 void setDefaultValues(unsigned int id, const GeneralSettings & settings);
1147 int getTrimValue(int phaseIdx, int trimIdx);
1148 void setTrimValue(int phaseIdx, int trimIdx, int value);
1150 bool isGVarLinked(int phaseIdx, int gvarIdx);
1151 int getGVarFieldValue(int phaseIdx, int gvarIdx);
1152 float getGVarFieldValuePrec(int phaseIdx, int gvarIdx);
1154 ModelData removeGlobalVars();
1156 void clearMixes();
1157 void clearInputs();
1159 int getChannelsMax(bool forceExtendedLimits=false) const;
1161 bool isAvailable(const RawSwitch & swtch) const;
1163 protected:
1164 void removeGlobalVar(int & var);
1168 class TrainerMix {
1169 public:
1170 TrainerMix() { clear(); }
1171 unsigned int src; // 0-7 = ch1-8
1172 RawSwitch swtch;
1173 int weight;
1174 unsigned int mode; // off, add-mode, subst-mode
1175 void clear() { memset(this, 0, sizeof(TrainerMix)); }
1178 class TrainerData {
1179 public:
1180 TrainerData() { clear(); }
1181 int calib[4];
1182 TrainerMix mix[4];
1183 void clear() { memset(this, 0, sizeof(TrainerData)); }
1186 class GeneralSettings {
1187 public:
1189 enum BeeperMode {
1190 BEEPER_QUIET = -2,
1191 BEEPER_ALARMS_ONLY = -1,
1192 BEEPER_NOKEYS = 0,
1193 BEEPER_ALL = 1
1196 GeneralSettings();
1197 void convert(Board::Type before, Board::Type after);
1199 int getDefaultStick(unsigned int channel) const;
1200 RawSource getDefaultSource(unsigned int channel) const;
1201 int getDefaultChannel(unsigned int stick) const;
1203 unsigned int version;
1204 unsigned int variant;
1205 int calibMid[CPN_MAX_ANALOGS];
1206 int calibSpanNeg[CPN_MAX_ANALOGS];
1207 int calibSpanPos[CPN_MAX_ANALOGS];
1208 unsigned int currModelIndex;
1209 char currModelFilename[16+1];
1210 unsigned int contrast;
1211 unsigned int vBatWarn;
1212 int txVoltageCalibration;
1213 int txCurrentCalibration;
1214 int vBatMin;
1215 int vBatMax;
1216 int backlightMode;
1217 TrainerData trainer;
1218 unsigned int view; // main screen view // TODO enum
1219 bool disableThrottleWarning;
1220 bool fai;
1221 bool disableMemoryWarning;
1222 BeeperMode beeperMode;
1223 bool disableAlarmWarning;
1224 bool disableRssiPoweroffAlarm;
1225 unsigned int usbMode;
1226 BeeperMode hapticMode;
1227 unsigned int stickMode; // TODO enum
1228 int timezone;
1229 bool adjustRTC;
1230 bool optrexDisplay;
1231 unsigned int inactivityTimer;
1232 bool minuteBeep;
1233 bool preBeep;
1234 bool flashBeep;
1235 unsigned int splashMode;
1236 int splashDuration;
1237 unsigned int backlightDelay;
1238 unsigned int templateSetup; //RETA order according to chout_ar array
1239 int PPM_Multiplier;
1240 int hapticLength;
1241 unsigned int reNavigation;
1242 unsigned int stickReverse;
1243 unsigned int speakerPitch;
1244 int hapticStrength;
1245 unsigned int speakerMode;
1246 char ownerName[10+1];
1247 int beeperLength;
1248 unsigned int gpsFormat;
1249 int speakerVolume;
1250 unsigned int backlightBright;
1251 unsigned int backlightOffBright;
1252 int switchesDelay;
1253 int temperatureCalib;
1254 int temperatureWarn;
1255 unsigned int mAhWarn;
1256 unsigned int mAhUsed;
1257 unsigned int globalTimer;
1258 bool bluetoothEnable;
1259 char bluetoothName[10+1];
1260 unsigned int bluetoothBaudrate;
1261 unsigned int bluetoothMode;
1262 unsigned int sticksGain;
1263 unsigned int rotarySteps;
1264 unsigned int countryCode;
1265 bool jitterFilter;
1266 unsigned int imperial;
1267 char ttsLanguage[2+1];
1268 int beepVolume;
1269 int wavVolume;
1270 int varioVolume;
1271 int varioPitch;
1272 int varioRange;
1273 int varioRepeat;
1274 int backgroundVolume;
1275 unsigned int mavbaud;
1276 unsigned int switchUnlockStates;
1277 unsigned int hw_uartMode;
1278 unsigned int backlightColor;
1279 CustomFunctionData customFn[CPN_MAX_SPECIAL_FUNCTIONS];
1280 char switchName[CPN_MAX_SWITCHES][3+1];
1281 unsigned int switchConfig[CPN_MAX_SWITCHES];
1282 char stickName[CPN_MAX_STICKS][3+1];
1283 char potName[CPN_MAX_KNOBS][3+1];
1284 unsigned int potConfig[CPN_MAX_KNOBS];
1285 char sliderName[CPN_MAX_SLIDERS][3+1];
1286 unsigned int sliderConfig[CPN_MAX_SLIDERS];
1288 char themeName[8+1];
1289 typedef uint8_t ThemeOptionData[8+1];
1290 ThemeOptionData themeOptionValue[5];
1292 bool switchPositionAllowedTaranis(int index) const;
1293 bool switchSourceAllowedTaranis(int index) const;
1294 bool isPotAvailable(int index) const;
1295 bool isSliderAvailable(int index) const;
1298 class CategoryData {
1299 public:
1300 CategoryData(const char * name) {
1301 strncpy(this->name, name, sizeof(CategoryData::name));
1303 char name[15+1];
1306 class RadioData {
1307 public:
1308 RadioData();
1310 GeneralSettings generalSettings;
1311 std::vector<CategoryData> categories;
1312 std::vector<ModelData> models;
1314 void convert(Board::Type before, Board::Type after);
1316 void setCurrentModel(unsigned int index);
1317 void fixModelFilenames();
1318 QString getNextModelFilename();
1320 protected:
1321 void fixModelFilename(unsigned int index);
1324 #endif // _RADIODATA_H_