[Companion] MdiChild now use a QTreeWidget instead of a QListWidget (… (#4096)
[opentx.git] / companion / src / eeprominterface.h
blob08de67b6244635369403d8328b7e19abf6a50f15
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _EEPROMINTERFACE_H_
22 #define _EEPROMINTERFACE_H_
24 #include <string.h>
25 #include <QString>
26 #include <QStringList>
27 #include <QList>
28 #include <QtXml> // This should be removed from here, and remove Xml dependency from all libs which don't need it.
29 #include <QComboBox>
30 #include <iostream>
31 #include <bitset>
32 #include "constants.h"
33 #include "../../radio/src/definitions.h"
34 #include "simulatorinterface.h"
36 #define EESIZE_STOCK 2048
37 #define EESIZE_M128 4096
38 #define EESIZE_GRUVIN9X 4096
39 #define EESIZE_TARANIS (32*1024)
40 #define EESIZE_SKY9X (128*4096)
41 #define EESIZE_9XRPRO (128*4096)
42 #define EESIZE_MAX EESIZE_9XRPRO
44 #define FSIZE_STOCK (64*1024)
45 #define FSIZE_M128 (128*1024)
46 #define FSIZE_GRUVIN9X (256*1024)
47 #define FSIZE_TARANIS (512*1024)
48 #define FSIZE_SKY9X (256*1024)
49 #define FSIZE_9XRPRO (512*1024)
50 #define FSIZE_HORUS (2048*1024)
51 #define FSIZE_MAX FSIZE_HORUS
53 #define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
54 #define IS_STOCK(board) (board==BOARD_STOCK)
55 #define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
56 #define IS_SKY9X(board) (board==BOARD_SKY9X || board==BOARD_9XRPRO || board==BOARD_AR9X)
57 #define IS_9XRPRO(board) (board==BOARD_9XRPRO)
58 #define IS_TARANIS(board) (board==BOARD_TARANIS_X9D || board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E || board==BOARD_X7D)
59 #define IS_TARANIS_PLUS(board) (board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E)
60 #define IS_TARANIS_X9E(board) (board==BOARD_TARANIS_X9E)
61 #define IS_HORUS(board) (board==BOARD_HORUS)
62 #define IS_FLAMENCO(board) (board==BOARD_FLAMENCO)
63 #define IS_STM32(board) (IS_TARANIS(board) || IS_HORUS(board) || IS_FLAMENCO(board))
64 #define IS_ARM(board) (IS_STM32(board) || IS_SKY9X(board))
65 #define HAS_LARGE_LCD(board) (IS_HORUS(board) || (IS_TARANIS(board) && board != BOARD_X7D))
67 const uint8_t modn12x3[4][4]= {
68 {1, 2, 3, 4},
69 {1, 3, 2, 4},
70 {4, 2, 3, 1},
71 {4, 3, 2, 1} };
73 enum Switches {
74 SWITCH_NONE,
76 SWITCH_THR = SWITCH_NONE+1,
77 SWITCH_RUD,
78 SWITCH_ELE,
79 SWITCH_ID0,
80 SWITCH_ID1,
81 SWITCH_ID2,
82 SWITCH_AIL,
83 SWITCH_GEA,
84 SWITCH_TRN,
86 SWITCH_SA0 = SWITCH_NONE+1,
87 SWITCH_SA1,
88 SWITCH_SA2,
89 SWITCH_SB0,
90 SWITCH_SB1,
91 SWITCH_SB2,
92 SWITCH_SC0,
93 SWITCH_SC1,
94 SWITCH_SC2,
95 SWITCH_SD0,
96 SWITCH_SD1,
97 SWITCH_SD2,
98 SWITCH_SE0,
99 SWITCH_SE1,
100 SWITCH_SE2,
101 SWITCH_SF0,
102 SWITCH_SF1,
103 SWITCH_SG0,
104 SWITCH_SG1,
105 SWITCH_SG2,
106 SWITCH_SH0,
107 SWITCH_SH2,
108 SWITCH_SI0,
109 SWITCH_SI2,
110 SWITCH_SJ0,
111 SWITCH_SJ2,
112 SWITCH_SK0,
113 SWITCH_SK2,
117 enum TimerModes {
118 TMRMODE_NONE,
119 TMRMODE_ABS,
120 TMRMODE_THR,
121 TMRMODE_THR_REL,
122 TMRMODE_THR_TRG,
123 TMRMODE_FIRST_SWITCH
126 enum FailsafeModes {
127 FAILSAFE_NOT_SET,
128 FAILSAFE_HOLD,
129 FAILSAFE_CUSTOM,
130 FAILSAFE_NOPULSES,
131 FAILSAFE_RECEIVER,
132 FAILSAFE_LAST = FAILSAFE_RECEIVER
135 #define TRIM_LH_L 0
136 #define TRIM_LH_R 1
137 #define TRIM_LV_DN 2
138 #define TRIM_LV_UP 3
139 #define TRIM_RV_DN 4
140 #define TRIM_RV_UP 5
141 #define TRIM_RH_L 6
142 #define TRIM_RH_R 7
143 #define TRIM_T5_DN 8
144 #define TRIM_T5_UP 9
145 #define TRIM_T6_DN 10
146 #define TRIM_T6_UP 11
147 #define TRIM_NONE 12
149 #define CHAR_FOR_NAMES " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
150 #define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"
152 enum HeliSwashTypes {
153 HELI_SWASH_TYPE_NONE=0,
154 HELI_SWASH_TYPE_120,
155 HELI_SWASH_TYPE_120X,
156 HELI_SWASH_TYPE_140,
157 HELI_SWASH_TYPE_90
160 class ModelData;
161 class GeneralSettings;
163 enum TelemetrySource {
164 TELEMETRY_SOURCE_TX_BATT,
165 TELEMETRY_SOURCE_TX_TIME,
166 TELEMETRY_SOURCE_TIMER1,
167 TELEMETRY_SOURCE_TIMER2,
168 TELEMETRY_SOURCE_TIMER3,
169 TELEMETRY_SOURCE_SWR,
170 TELEMETRY_SOURCE_RSSI_TX,
171 TELEMETRY_SOURCE_RSSI_RX,
172 TELEMETRY_SOURCE_A1,
173 TELEMETRY_SOURCE_A2,
174 TELEMETRY_SOURCE_A3,
175 TELEMETRY_SOURCE_A4,
176 TELEMETRY_SOURCE_ALT,
177 TELEMETRY_SOURCE_RPM,
178 TELEMETRY_SOURCE_FUEL,
179 TELEMETRY_SOURCE_T1,
180 TELEMETRY_SOURCE_T2,
181 TELEMETRY_SOURCE_SPEED,
182 TELEMETRY_SOURCE_DIST,
183 TELEMETRY_SOURCE_GPS_ALT,
184 TELEMETRY_SOURCE_CELL,
185 TELEMETRY_SOURCE_CELLS_SUM,
186 TELEMETRY_SOURCE_VFAS,
187 TELEMETRY_SOURCE_CURRENT,
188 TELEMETRY_SOURCE_CONSUMPTION,
189 TELEMETRY_SOURCE_POWER,
190 TELEMETRY_SOURCE_ACCX,
191 TELEMETRY_SOURCE_ACCY,
192 TELEMETRY_SOURCE_ACCZ,
193 TELEMETRY_SOURCE_HDG,
194 TELEMETRY_SOURCE_VERTICAL_SPEED,
195 TELEMETRY_SOURCE_ASPEED,
196 TELEMETRY_SOURCE_DTE,
197 TELEMETRY_SOURCE_A1_MIN,
198 TELEMETRY_SOURCE_A2_MIN,
199 TELEMETRY_SOURCE_A3_MIN,
200 TELEMETRY_SOURCE_A4_MIN,
201 TELEMETRY_SOURCE_ALT_MIN,
202 TELEMETRY_SOURCE_ALT_MAX,
203 TELEMETRY_SOURCE_RPM_MAX,
204 TELEMETRY_SOURCE_T1_MAX,
205 TELEMETRY_SOURCE_T2_MAX,
206 TELEMETRY_SOURCE_SPEED_MAX,
207 TELEMETRY_SOURCE_DIST_MAX,
208 TELEMETRY_SOURCE_ASPEED_MAX,
209 TELEMETRY_SOURCE_CELL_MIN,
210 TELEMETRY_SOURCE_CELLS_MIN,
211 TELEMETRY_SOURCE_VFAS_MIN,
212 TELEMETRY_SOURCE_CURRENT_MAX,
213 TELEMETRY_SOURCE_POWER_MAX,
214 TELEMETRY_SOURCE_ACC,
215 TELEMETRY_SOURCE_GPS_TIME,
216 TELEMETRY_SOURCES_STATUS_COUNT = TELEMETRY_SOURCE_GPS_TIME+1,
217 TELEMETRY_SOURCES_DISPLAY_COUNT = TELEMETRY_SOURCE_POWER_MAX+1,
218 TELEMETRY_SOURCES_COUNT = TELEMETRY_SOURCE_POWER_MAX+1,
219 TELEMETRY_SOURCE_RESERVE = -1
222 #define TM_HASTELEMETRY 0x01
223 #define TM_HASOFFSET 0x02
224 #define TM_HASWSHH 0x04
226 enum RawSourceType {
227 SOURCE_TYPE_NONE,
228 SOURCE_TYPE_VIRTUAL_INPUT,
229 SOURCE_TYPE_LUA_OUTPUT,
230 SOURCE_TYPE_STICK, // and POTS
231 SOURCE_TYPE_ROTARY_ENCODER,
232 SOURCE_TYPE_TRIM,
233 SOURCE_TYPE_MAX,
234 SOURCE_TYPE_SWITCH,
235 SOURCE_TYPE_CUSTOM_SWITCH,
236 SOURCE_TYPE_CYC,
237 SOURCE_TYPE_PPM,
238 SOURCE_TYPE_CH,
239 SOURCE_TYPE_GVAR,
240 SOURCE_TYPE_SPECIAL,
241 SOURCE_TYPE_TELEMETRY,
242 MAX_SOURCE_TYPE
245 QString RotaryEncoderString(int index);
247 class RawSourceRange
249 public:
250 RawSourceRange():
251 decimals(0),
252 min(0.0),
253 max(0.0),
254 step(1.0),
255 offset(0.0)
259 float getValue(int value);
261 int decimals;
262 double min;
263 double max;
264 double step;
265 double offset;
266 QString unit;
269 #define RANGE_SINGLE_PRECISION 1
270 #define RANGE_DELTA_FUNCTION 2
271 #define RANGE_DELTA_ABS_FUNCTION 4
273 class RawSource {
274 public:
275 RawSource():
276 type(SOURCE_TYPE_NONE),
277 index(0)
281 explicit RawSource(int value):
282 type(RawSourceType(abs(value)/65536)),
283 index(value >= 0 ? abs(value)%65536 : -(abs(value)%65536))
287 RawSource(RawSourceType type, int index=0):
288 type(type),
289 index(index)
293 inline const int toValue() const
295 return index >= 0 ? (type * 65536 + index) : -(type * 65536 - index);
298 QString toString(const ModelData * model = NULL) const;
300 RawSourceRange getRange(const ModelData * model, const GeneralSettings & settings, unsigned int flags=0) const;
302 bool operator == ( const RawSource & other) {
303 return (this->type == other.type) && (this->index == other.index);
306 bool operator != ( const RawSource & other) {
307 return (this->type != other.type) || (this->index != other.index);
310 bool isTimeBased() const;
311 bool isPot() const;
312 bool isSlider() const;
314 RawSourceType type;
315 int index;
318 enum RawSwitchType {
319 SWITCH_TYPE_NONE,
320 SWITCH_TYPE_SWITCH,
321 SWITCH_TYPE_VIRTUAL,
322 SWITCH_TYPE_MULTIPOS_POT,
323 SWITCH_TYPE_TRIM,
324 SWITCH_TYPE_ROTARY_ENCODER,
325 SWITCH_TYPE_ON,
326 SWITCH_TYPE_OFF,
327 SWITCH_TYPE_ONE,
328 SWITCH_TYPE_FLIGHT_MODE,
329 SWITCH_TYPE_TIMER_MODE
332 class RawSwitch {
333 public:
334 RawSwitch():
335 type(SWITCH_TYPE_NONE),
336 index(0)
340 explicit RawSwitch(int value):
341 type(RawSwitchType(abs(value)/256)),
342 index(value >= 0 ? abs(value)%256 : -(abs(value)%256))
346 RawSwitch(RawSwitchType type, int index=0):
347 type(type),
348 index(index)
352 inline const int toValue() const
354 return index >= 0 ? (type * 256 + index) : -(type * 256 - index);
357 QString toString() const;
359 bool operator== ( const RawSwitch& other) {
360 return (this->type == other.type) && (this->index == other.index);
363 bool operator!= ( const RawSwitch& other) {
364 return (this->type != other.type) || (this->index != other.index);
367 RawSwitchType type;
368 int index;
371 class CurveReference {
372 public:
373 enum CurveRefType {
374 CURVE_REF_DIFF,
375 CURVE_REF_EXPO,
376 CURVE_REF_FUNC,
377 CURVE_REF_CUSTOM
380 CurveReference() { clear(); }
382 CurveReference(CurveRefType type, int value):
383 type(type),
384 value(value)
388 void clear() { memset(this, 0, sizeof(CurveReference)); }
390 CurveRefType type;
391 int value;
393 QString toString() const;
396 enum InputMode {
397 INPUT_MODE_NONE,
398 INPUT_MODE_POS,
399 INPUT_MODE_NEG,
400 INPUT_MODE_BOTH
403 class ExpoData {
404 public:
405 ExpoData() { clear(); }
406 RawSource srcRaw;
407 unsigned int scale;
408 unsigned int mode;
409 unsigned int chn;
410 RawSwitch swtch;
411 unsigned int flightModes; // -5=!FP4, 0=normal, 5=FP4
412 int weight;
413 int offset;
414 CurveReference curve;
415 int carryTrim;
416 char name[10+1];
417 void clear() { memset(this, 0, sizeof(ExpoData)); }
420 class CurvePoint {
421 public:
422 int8_t x;
423 int8_t y;
426 class CurveData {
427 public:
428 enum CurveType {
429 CURVE_TYPE_STANDARD,
430 CURVE_TYPE_CUSTOM,
431 CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM
434 CurveData();
435 void clear(int count);
436 bool isEmpty() const;
437 CurveType type;
438 bool smooth;
439 int count;
440 CurvePoint points[CPN_MAX_POINTS];
441 char name[6+1];
444 class LimitData {
445 public:
446 LimitData() { clear(); }
447 int min;
448 int max;
449 bool revert;
450 int offset;
451 int ppmCenter;
452 bool symetrical;
453 char name[6+1];
454 CurveReference curve;
455 QString minToString() const;
456 QString maxToString() const;
457 QString offsetToString() const;
458 QString revertToString() const;
459 void clear();
462 enum MltpxValue {
463 MLTPX_ADD=0,
464 MLTPX_MUL=1,
465 MLTPX_REP=2
468 #define MIXDATA_NAME_LEN 10
470 class MixData {
471 public:
472 MixData() { clear(); }
473 unsigned int destCh; // 1..CPN_MAX_CHNOUT
474 RawSource srcRaw;
475 int weight;
476 RawSwitch swtch;
477 CurveReference curve; //0=symmetrisch
478 unsigned int delayUp;
479 unsigned int delayDown;
480 unsigned int speedUp; // Servogeschwindigkeit aus Tabelle (10ms Cycle)
481 unsigned int speedDown; // 0 nichts
482 int carryTrim;
483 bool noExpo;
484 MltpxValue mltpx; // multiplex method 0=+ 1=* 2=replace
485 unsigned int mixWarn; // mixer warning
486 unsigned int flightModes; // -5=!FP4, 0=normal, 5=FP4
487 int sOffset;
488 char name[MIXDATA_NAME_LEN+1];
490 void clear() { memset(this, 0, sizeof(MixData)); }
493 enum CSFunction {
494 LS_FN_OFF,
495 LS_FN_VPOS,
496 LS_FN_VNEG,
497 LS_FN_APOS,
498 LS_FN_ANEG,
499 LS_FN_AND,
500 LS_FN_OR,
501 LS_FN_XOR,
502 LS_FN_EQUAL,
503 LS_FN_NEQUAL,
504 LS_FN_GREATER,
505 LS_FN_LESS,
506 LS_FN_EGREATER,
507 LS_FN_ELESS,
508 LS_FN_DPOS,
509 LS_FN_DAPOS,
510 LS_FN_VEQUAL, // added at the end to avoid everything renumbered
511 LS_FN_VALMOSTEQUAL,
512 LS_FN_TIMER,
513 LS_FN_STICKY,
514 LS_FN_EDGE,
515 // later ... LS_FN_RANGE,
516 LS_FN_MAX
519 enum CSFunctionFamily {
520 LS_FAMILY_VOFS,
521 LS_FAMILY_VBOOL,
522 LS_FAMILY_VCOMP,
523 LS_FAMILY_TIMER,
524 LS_FAMILY_STICKY,
525 LS_FAMILY_EDGE,
528 class LogicalSwitchData { // Logical Switches data
529 public:
530 LogicalSwitchData(unsigned int func=0)
532 clear();
533 this->func = func;
535 unsigned int func;
536 int val1;
537 int val2;
538 int val3;
539 unsigned int delay;
540 unsigned int duration;
541 int andsw;
542 void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
543 CSFunctionFamily getFunctionFamily() const;
544 unsigned int getRangeFlags() const;
545 QString funcToString() const;
548 enum AssignFunc {
549 FuncOverrideCH1 = 0,
550 FuncOverrideCH32 = FuncOverrideCH1+CPN_MAX_CHNOUT-1,
551 FuncTrainer,
552 FuncTrainerRUD,
553 FuncTrainerELE,
554 FuncTrainerTHR,
555 FuncTrainerAIL,
556 FuncInstantTrim,
557 FuncPlaySound,
558 FuncPlayHaptic,
559 FuncReset,
560 FuncSetTimer1,
561 FuncSetTimer2,
562 FuncSetTimer3,
563 FuncVario,
564 FuncPlayPrompt,
565 FuncPlayBoth,
566 FuncPlayValue,
567 FuncPlayScript,
568 FuncLogs,
569 FuncVolume,
570 FuncBacklight,
571 FuncScreenshot,
572 FuncBackgroundMusic,
573 FuncBackgroundMusicPause,
574 FuncAdjustGV1,
575 FuncAdjustGVLast = FuncAdjustGV1+CPN_MAX_GVARS-1,
576 FuncSetFailsafeInternalModule,
577 FuncSetFailsafeExternalModule,
578 FuncRangeCheckInternalModule,
579 FuncRangeCheckExternalModule,
580 FuncBindInternalModule,
581 FuncBindExternalModule,
582 FuncCount,
583 FuncReserve = -1
586 enum GVarAdjustModes
588 FUNC_ADJUST_GVAR_CONSTANT,
589 FUNC_ADJUST_GVAR_SOURCE,
590 FUNC_ADJUST_GVAR_GVAR,
591 FUNC_ADJUST_GVAR_INCDEC
594 class CustomFunctionData { // Function Switches data
595 public:
596 CustomFunctionData(AssignFunc func=FuncOverrideCH1) { clear(); this->func = func; }
597 RawSwitch swtch;
598 AssignFunc func;
599 int param;
600 char paramarm[10];
601 unsigned int enabled; // TODO perhaps not any more the right name
602 unsigned int adjustMode;
603 int repeatParam;
604 void clear();
605 QString funcToString() const;
606 QString paramToString(const ModelData * model) const;
607 QString repeatToString() const;
608 QString enabledToString() const;
610 static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value);
611 static void populatePlaySoundParams(QStringList & qs);
612 static void populateHapticParams(QStringList & qs);
616 class FlightModeData {
617 public:
618 FlightModeData() { clear(0); }
619 int trimMode[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
620 int trimRef[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
621 int trim[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
622 RawSwitch swtch;
623 char name[10+1];
624 unsigned int fadeIn;
625 unsigned int fadeOut;
626 int rotaryEncoders[CPN_MAX_ENCODERS];
627 int gvars[CPN_MAX_GVARS];
628 void clear(const int phase);
631 class SwashRingData { // Swash Ring data
632 public:
633 SwashRingData() { clear(); }
634 int elevatorWeight;
635 int aileronWeight;
636 int collectiveWeight;
637 unsigned int type;
638 RawSource collectiveSource;
639 RawSource aileronSource;
640 RawSource elevatorSource;
641 unsigned int value;
642 void clear() { memset(this, 0, sizeof(SwashRingData)); }
645 class FrSkyAlarmData {
646 public:
647 FrSkyAlarmData() { clear(); }
648 unsigned int level; // 0=none, 1=Yellow, 2=Orange, 3=Red
649 unsigned int greater; // 0=LT(<), 1=GT(>)
650 unsigned int value; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
652 void clear() { memset(this, 0, sizeof(FrSkyAlarmData)); }
655 class FrSkyRSSIAlarm {
656 public:
657 FrSkyRSSIAlarm() { clear(0, 50); }
658 unsigned int level;
659 int value;
660 void clear(unsigned int level, int value) { this->level = level; this->value = value;}
663 class FrSkyChannelData {
664 public:
665 FrSkyChannelData() { clear(); }
666 unsigned int ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
667 unsigned int type; // future use: 0=volts, 1=ml...
668 int offset;
669 unsigned int multiplier;
670 FrSkyAlarmData alarms[2];
672 float getRatio() const;
673 RawSourceRange getRange() const;
674 void clear() { memset(this, 0, sizeof(FrSkyChannelData)); }
677 struct FrSkyBarData {
678 RawSource source;
679 unsigned int barMin; // minimum for bar display
680 unsigned int barMax; // ditto for max display (would usually = ratio)
683 struct FrSkyLineData {
684 RawSource source[3];
687 struct TelemetryScriptData {
688 char filename[8+1];
691 enum TelemetryScreenEnum {
692 TELEMETRY_SCREEN_NONE,
693 TELEMETRY_SCREEN_NUMBERS,
694 TELEMETRY_SCREEN_BARS,
695 TELEMETRY_SCREEN_SCRIPT
698 class FrSkyScreenData {
699 public:
700 FrSkyScreenData() { clear(); }
702 typedef struct {
703 FrSkyBarData bars[4];
704 FrSkyLineData lines[4];
705 TelemetryScriptData script;
706 } FrSkyScreenBody;
708 unsigned int type;
709 FrSkyScreenBody body;
711 void clear();
714 enum TelemetryVarioSources {
715 TELEMETRY_VARIO_SOURCE_ALTI,
716 TELEMETRY_VARIO_SOURCE_ALTI_PLUS,
717 TELEMETRY_VARIO_SOURCE_VSPEED,
718 TELEMETRY_VARIO_SOURCE_A1,
719 TELEMETRY_VARIO_SOURCE_A2,
720 TELEMETRY_VARIO_SOURCE_DTE,
723 enum TelemetryVoltsSources {
724 TELEMETRY_VOLTS_SOURCE_A1,
725 TELEMETRY_VOLTS_SOURCE_A2,
726 TELEMETRY_VOLTS_SOURCE_A3,
727 TELEMETRY_VOLTS_SOURCE_A4,
728 TELEMETRY_VOLTS_SOURCE_FAS,
729 TELEMETRY_VOLTS_SOURCE_CELLS
732 enum TelemetryCurrentSources {
733 TELEMETRY_CURRENT_SOURCE_NONE,
734 TELEMETRY_CURRENT_SOURCE_A1,
735 TELEMETRY_CURRENT_SOURCE_A2,
736 TELEMETRY_CURRENT_SOURCE_A3,
737 TELEMETRY_CURRENT_SOURCE_A4,
738 TELEMETRY_CURRENT_SOURCE_FAS
741 enum UartModes {
742 UART_MODE_NONE,
743 UART_MODE_TELEMETRY_MIRROR,
744 UART_MODE_TELEMETRY,
745 UART_MODE_SBUS_TRAINER,
746 UART_MODE_DEBUG
749 enum TrainerMode {
750 TRAINER_MODE_MASTER_TRAINER_JACK,
751 TRAINER_MODE_SLAVE,
752 TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE,
753 TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE,
754 TRAINER_MODE_MASTER_BATTERY_COMPARTMENT,
757 class FrSkyData {
758 public:
759 FrSkyData() { clear(); }
760 FrSkyChannelData channels[4];
761 unsigned int usrProto;
762 int blades;
763 unsigned int voltsSource;
764 unsigned int altitudeSource;
765 unsigned int currentSource;
766 FrSkyScreenData screens[4];
767 FrSkyRSSIAlarm rssiAlarms[2];
768 unsigned int varioSource;
769 bool varioCenterSilent;
770 int varioMin;
771 int varioCenterMin; // if increment in 0.2m/s = 3.0m/s max
772 int varioCenterMax;
773 int varioMax;
774 bool mAhPersistent;
775 unsigned int storedMah;
776 int fasOffset;
777 bool ignoreSensorIds;
779 void clear();
782 class MavlinkData {
783 public:
784 MavlinkData() { clear();}
785 unsigned int rc_rssi_scale;
786 unsigned int pc_rssi_en;
787 void clear() { memset(this, 0, sizeof(MavlinkData)); }
790 #define TIMER_NAME_LEN 8
792 class TimerData {
793 public:
794 enum CountDownMode {
795 COUNTDOWN_SILENT,
796 COUNTDOWN_BEEPS,
797 COUNTDOWN_VOICE,
798 COUNTDOWN_HAPTIC
800 TimerData() { clear(); }
801 RawSwitch mode;
802 char name[TIMER_NAME_LEN+1];
803 bool minuteBeep;
804 unsigned int countdownBeep;
805 unsigned int val;
806 unsigned int persistent;
807 int pvalue;
808 void clear() { memset(this, 0, sizeof(TimerData)); mode = RawSwitch(SWITCH_TYPE_TIMER_MODE, 0); }
811 enum PulsesProtocol {
812 PULSES_OFF,
813 PULSES_PPM,
814 PULSES_SILV_A,
815 PULSES_SILV_B,
816 PULSES_SILV_C,
817 PULSES_CTP1009,
818 PULSES_LP45,
819 PULSES_DSM2,
820 PULSES_DSMX,
821 PULSES_PPM16,
822 PULSES_PPMSIM,
823 PULSES_PXX_XJT_X16,
824 PULSES_PXX_XJT_D8,
825 PULSES_PXX_XJT_LR12,
826 PULSES_PXX_DJT,
827 PULSES_CROSSFIRE,
828 PULSES_MULTIMODULE,
829 PULSES_PROTOCOL_LAST
832 enum MultiModuleRFProtocols {
833 MM_RF_PROTO_FLYSKY=0,
834 MM_RF_PROTO_FIRST=MM_RF_PROTO_FLYSKY,
835 MM_RF_PROTO_HUBSAN,
836 MM_RF_PROTO_FRSKY,
837 MM_RF_PROTO_HISKY,
838 MM_RF_PROTO_V2X2,
839 MM_RF_PROTO_DSM2,
840 MM_RF_PROTO_DEVO,
841 MM_RF_PROTO_YD717,
842 MM_RF_PROTO_KN,
843 MM_RF_PROTO_SYMAX,
844 MM_RF_PROTO_SLT,
845 MM_RF_PROTO_CX10,
846 MM_RF_PROTO_CG023,
847 MM_RF_PROTO_BAYANG,
848 MM_RF_PROTO_ESky,
849 MM_RF_PROTO_MT99XX,
850 MM_RF_PROTO_MJXQ,
851 MM_RF_PROTO_SHENQI,
852 MM_RF_PROTO_FY326,
853 MM_RF_PROTO_SFHSS,
854 MM_RF_PROTO_J6PRO,
855 MM_RF_PROTO_FQ777,
856 MM_RF_PROTO_ASSAN,
857 MM_RF_PROTO_HONTAI,
858 MM_RF_PROTO_OLRS,
859 MM_RF_PROTO_AFHDS2A,
860 MM_RF_PROTO_LAST= MM_RF_PROTO_AFHDS2A
863 unsigned int getNumSubtypes(MultiModuleRFProtocols type);
865 enum TrainerProtocol {
866 TRAINER_MASTER_JACK,
867 TRAINER_SLAVE_JACK,
868 TRAINER_MASTER_SBUS_MODULE,
869 TRAINER_MASTER_CPPM_MODULE,
870 TRAINER_MASTER_SBUS_BATT_COMPARTMENT
873 class ModuleData {
874 public:
875 ModuleData() { clear(); }
876 unsigned int modelId;
877 int protocol;
878 unsigned int subType;
879 bool invertedSerial;
880 unsigned int channelsStart;
881 int channelsCount; // 0=8 channels
882 unsigned int failsafeMode;
883 int failsafeChannels[CPN_MAX_CHNOUT];
886 struct {
887 int delay;
888 bool pulsePol; // false = positive
889 bool outputType; // false = open drain, true = push pull
890 int frameLength;
891 } ppm;
893 struct {
894 unsigned int rfProtocol;
895 bool autoBindMode;
896 bool lowPowerMode;
897 bool customProto;
898 int optionValue;
899 } multi;
903 void clear() { memset(this, 0, sizeof(ModuleData)); }
904 QString polarityToString() const { return ppm.pulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter
907 #define CPN_MAX_SCRIPTS 7
908 #define CPN_MAX_SCRIPT_INPUTS 10
909 class ScriptData {
910 public:
911 ScriptData() { clear(); }
912 char filename[10+1];
913 char name[10+1];
914 int inputs[CPN_MAX_SCRIPT_INPUTS];
915 void clear() { memset(this, 0, sizeof(ScriptData)); }
918 #define CPN_MAX_SENSORS 32
919 class SensorData {
921 public:
923 enum
925 TELEM_TYPE_CUSTOM,
926 TELEM_TYPE_CALCULATED
929 enum
931 TELEM_FORMULA_ADD,
932 TELEM_FORMULA_AVERAGE,
933 TELEM_FORMULA_MIN,
934 TELEM_FORMULA_MAX,
935 TELEM_FORMULA_MULTIPLY,
936 TELEM_FORMULA_TOTALIZE,
937 TELEM_FORMULA_CELL,
938 TELEM_FORMULA_CONSUMPTION,
939 TELEM_FORMULA_DIST,
940 TELEM_FORMULA_LAST = TELEM_FORMULA_DIST
943 enum {
944 TELEM_CELL_INDEX_LOWEST,
945 TELEM_CELL_INDEX_1,
946 TELEM_CELL_INDEX_2,
947 TELEM_CELL_INDEX_3,
948 TELEM_CELL_INDEX_4,
949 TELEM_CELL_INDEX_5,
950 TELEM_CELL_INDEX_6,
951 TELEM_CELL_INDEX_HIGHEST,
952 TELEM_CELL_INDEX_DELTA,
955 enum
957 UNIT_RAW,
958 UNIT_VOLTS,
959 UNIT_AMPS,
960 UNIT_MILLIAMPS,
961 UNIT_KTS,
962 UNIT_METERS_PER_SECOND,
963 UNIT_FEET_PER_SECOND,
964 UNIT_KMH,
965 UNIT_MPH,
966 UNIT_METERS,
967 UNIT_FEET,
968 UNIT_CELSIUS,
969 UNIT_FAHRENHEIT,
970 UNIT_PERCENT,
971 UNIT_MAH,
972 UNIT_WATTS,
973 UNIT_DB,
974 UNIT_RPMS,
975 UNIT_G,
976 UNIT_DEGREE,
977 UNIT_MILLILITERS,
978 UNIT_FLOZ,
979 UNIT_HOURS,
980 UNIT_MINUTES,
981 UNIT_SECONDS,
982 // FrSky format used for these fields, could be another format in the future
983 UNIT_FIRST_VIRTUAL,
984 UNIT_CELLS = UNIT_FIRST_VIRTUAL,
985 UNIT_DATETIME,
986 UNIT_GPS,
987 UNIT_GPS_LONGITUDE,
988 UNIT_GPS_LATITUDE,
989 UNIT_GPS_LONGITUDE_EW,
990 UNIT_GPS_LATITUDE_NS,
991 UNIT_DATETIME_YEAR,
992 UNIT_DATETIME_DAY_MONTH,
993 UNIT_DATETIME_HOUR_MIN,
994 UNIT_DATETIME_SEC
997 SensorData() { clear(); }
998 unsigned int type; // custom / formula
999 unsigned int id;
1000 unsigned int subid;
1001 unsigned int instance;
1002 unsigned int persistentValue;
1003 unsigned int formula;
1004 char label[4+1];
1005 unsigned int unit;
1006 unsigned int prec;
1007 bool autoOffset;
1008 bool filter;
1009 bool logs;
1010 bool persistent;
1011 bool onlyPositive;
1013 // for custom sensors
1014 unsigned int ratio;
1015 int offset;
1017 // for consumption
1018 unsigned int amps;
1020 // for cell
1021 unsigned int source;
1022 unsigned int index;
1024 // for calculations
1025 int sources[4];
1027 // for GPS dist
1028 unsigned int gps;
1029 unsigned int alt;
1031 bool isAvailable() const { return strlen(label) > 0; }
1032 void updateUnit();
1033 QString unitString() const;
1034 void clear() { memset(this, 0, sizeof(SensorData)); }
1038 * TODO ...
1040 #if 0
1041 class CustomScreenOptionData {
1042 public:
1046 class CustomScreenZoneData {
1047 public:
1048 char widgetName[10+1];
1049 WidgetOptionData widgetOptions[5];
1052 class CustomScreenData {
1053 public:
1054 CustomScreenData();
1056 char layoutName[10+1];
1057 CustomScreenZoneData zones[];
1058 CustomScreenOptionData options[];
1060 #else
1061 typedef char CustomScreenData[610+1];
1062 typedef char TopbarData[216+1];
1063 #endif
1065 class ModelData {
1066 public:
1067 ModelData();
1068 ModelData(const ModelData & src);
1069 ModelData & operator = (const ModelData & src);
1071 ExpoData * insertInput(const int idx);
1072 void removeInput(const int idx);
1074 bool isInputValid(const unsigned int idx) const;
1075 bool hasExpos(uint8_t inputIdx) const;
1076 bool hasMixes(uint8_t output) const;
1078 QVector<const ExpoData *> expos(int input) const;
1079 QVector<const MixData *> mixes(int channel) const;
1081 bool used;
1082 char category[15+1];
1083 char name[15+1];
1084 char filename[16+1];
1085 TimerData timers[CPN_MAX_TIMERS];
1086 bool noGlobalFunctions;
1087 bool thrTrim; // Enable Throttle Trim
1088 int trimInc; // Trim Increments
1089 unsigned int trimsDisplay;
1090 bool disableThrottleWarning;
1092 unsigned int beepANACenter; // 1<<0->A1.. 1<<6->A7
1094 bool extendedLimits; // TODO xml
1095 bool extendedTrims;
1096 bool throttleReversed;
1097 FlightModeData flightModeData[CPN_MAX_FLIGHT_MODES];
1098 MixData mixData[CPN_MAX_MIXERS];
1099 LimitData limitData[CPN_MAX_CHNOUT];
1101 char inputNames[CPN_MAX_INPUTS][4+1];
1102 ExpoData expoData[CPN_MAX_EXPOS];
1104 CurveData curves[CPN_MAX_CURVES];
1105 LogicalSwitchData logicalSw[CPN_MAX_CSW];
1106 CustomFunctionData customFn[CPN_MAX_CUSTOM_FUNCTIONS];
1107 SwashRingData swashRingData;
1108 unsigned int thrTraceSrc;
1109 uint64_t switchWarningStates;
1110 unsigned int switchWarningEnable;
1111 unsigned int potsWarningMode;
1112 bool potsWarningEnabled[CPN_MAX_POTS];
1113 int potPosition[CPN_MAX_POTS];
1114 bool displayChecklist;
1115 // TODO structure
1116 char gvars_names[CPN_MAX_GVARS][6+1];
1117 bool gvars_popups[CPN_MAX_GVARS];
1118 MavlinkData mavlink;
1119 unsigned int telemetryProtocol;
1120 FrSkyData frsky;
1122 char bitmap[10+1];
1124 unsigned int trainerMode;
1126 ModuleData moduleData[CPN_MAX_MODULES+1/*trainer*/];
1128 ScriptData scriptData[CPN_MAX_SCRIPTS];
1130 SensorData sensorData[CPN_MAX_SENSORS];
1132 unsigned int toplcdTimer;
1134 CustomScreenData customScreenData[5];
1136 TopbarData topbarData;
1138 void clear();
1139 bool isEmpty() const;
1140 void setDefaultInputs(const GeneralSettings & settings);
1141 void setDefaultMixes(const GeneralSettings & settings);
1142 void setDefaultValues(unsigned int id, const GeneralSettings & settings);
1144 int getTrimValue(int phaseIdx, int trimIdx);
1145 void setTrimValue(int phaseIdx, int trimIdx, int value);
1147 bool isGVarLinked(int phaseIdx, int gvarIdx);
1148 int getGVarFieldValue(int phaseIdx, int gvarIdx);
1150 ModelData removeGlobalVars();
1152 void clearMixes();
1153 void clearInputs();
1155 int getChannelsMax(bool forceExtendedLimits=false) const;
1157 protected:
1158 void removeGlobalVar(int & var);
1162 class TrainerMix {
1163 public:
1164 TrainerMix() { clear(); }
1165 unsigned int src; // 0-7 = ch1-8
1166 RawSwitch swtch;
1167 int weight;
1168 unsigned int mode; // off, add-mode, subst-mode
1169 void clear() { memset(this, 0, sizeof(TrainerMix)); }
1172 class TrainerData {
1173 public:
1174 TrainerData() { clear(); }
1175 int calib[4];
1176 TrainerMix mix[4];
1177 void clear() { memset(this, 0, sizeof(TrainerData)); }
1180 class GeneralSettings {
1181 public:
1183 enum BeeperMode {
1184 BEEPER_QUIET = -2,
1185 BEEPER_ALARMS_ONLY = -1,
1186 BEEPER_NOKEYS = 0,
1187 BEEPER_ALL = 1
1190 enum PotConfig {
1191 POT_NONE,
1192 POT_WITH_DETENT,
1193 POT_MULTIPOS_SWITCH,
1194 POT_WITHOUT_DETENT
1197 enum SliderConfig {
1198 SLIDER_NONE,
1199 SLIDER_WITH_DETENT
1202 GeneralSettings();
1204 int getDefaultStick(unsigned int channel) const;
1205 RawSource getDefaultSource(unsigned int channel) const;
1206 int getDefaultChannel(unsigned int stick) const;
1208 unsigned int version;
1209 unsigned int variant;
1210 int calibMid[CPN_MAX_STICKS+CPN_MAX_POTS+CPN_MAX_MOUSE_ANALOGS];
1211 int calibSpanNeg[CPN_MAX_STICKS+CPN_MAX_POTS+CPN_MAX_MOUSE_ANALOGS];
1212 int calibSpanPos[CPN_MAX_STICKS+CPN_MAX_POTS+CPN_MAX_MOUSE_ANALOGS];
1213 unsigned int currModelIndex;
1214 char currModelFilename[16+1];
1215 unsigned int contrast;
1216 unsigned int vBatWarn;
1217 int txVoltageCalibration;
1218 int txCurrentCalibration;
1219 int vBatMin;
1220 int vBatMax;
1221 int backlightMode;
1222 TrainerData trainer;
1223 unsigned int view; // main screen view // TODO enum
1224 bool disableThrottleWarning;
1225 bool fai;
1226 int switchWarning; // -1=down, 0=off, 1=up
1227 bool disableMemoryWarning;
1228 BeeperMode beeperMode;
1229 bool disableAlarmWarning;
1230 bool enableTelemetryAlarm;
1231 BeeperMode hapticMode;
1232 unsigned int stickMode; // TODO enum
1233 int timezone;
1234 bool adjustRTC;
1235 bool optrexDisplay;
1236 unsigned int inactivityTimer;
1237 bool minuteBeep;
1238 bool preBeep;
1239 bool flashBeep;
1240 bool disablePotScroll;
1241 bool frskyinternalalarm;
1242 bool disableBG;
1243 unsigned int splashMode;
1244 int splashDuration;
1245 unsigned int backlightDelay;
1246 bool blightinv;
1247 bool stickScroll;
1248 unsigned int templateSetup; //RETA order according to chout_ar array
1249 int PPM_Multiplier;
1250 int hapticLength;
1251 unsigned int reNavigation;
1252 unsigned int stickReverse;
1253 bool hideNameOnSplash;
1254 bool enablePpmsim;
1255 unsigned int speakerPitch;
1256 int hapticStrength;
1257 unsigned int speakerMode;
1258 unsigned int lightOnStickMove; /* er9x / ersky9x only */
1259 char ownerName[10+1];
1260 unsigned int switchWarningStates;
1261 int beeperLength;
1262 unsigned int gpsFormat;
1263 int speakerVolume;
1264 unsigned int backlightBright;
1265 unsigned int backlightOffBright;
1266 int switchesDelay;
1267 int temperatureCalib;
1268 int temperatureWarn;
1269 unsigned int mAhWarn;
1270 unsigned int mAhUsed;
1271 unsigned int globalTimer;
1272 bool bluetoothEnable;
1273 char bluetoothName[10+1];
1274 unsigned int btBaudrate;
1275 unsigned int sticksGain;
1276 unsigned int rotarySteps;
1277 unsigned int countryCode;
1278 bool jitterFilter;
1279 unsigned int imperial;
1280 bool crosstrim;
1281 char ttsLanguage[2+1];
1282 int beepVolume;
1283 int wavVolume;
1284 int varioVolume;
1285 int varioPitch;
1286 int varioRange;
1287 int varioRepeat;
1288 int backgroundVolume;
1289 unsigned int mavbaud;
1290 unsigned int switchUnlockStates;
1291 unsigned int hw_uartMode;
1292 unsigned int backlightColor;
1293 CustomFunctionData customFn[CPN_MAX_CUSTOM_FUNCTIONS];
1294 char switchName[18][3+1];
1295 unsigned int switchConfig[18];
1296 char stickName[4][3+1];
1297 char potName[4][3+1];
1298 unsigned int potConfig[4];
1299 char sliderName[4][3+1];
1300 unsigned int sliderConfig[4];
1302 char themeName[8+1];
1303 typedef uint8_t ThemeOptionData[8+1];
1304 ThemeOptionData themeOptionValue[5];
1306 struct SwitchInfo {
1307 SwitchInfo(unsigned int index, unsigned int position):
1308 index(index),
1309 position(position)
1312 unsigned int index;
1313 unsigned int position;
1316 static SwitchInfo switchInfoFromSwitchPositionTaranis(unsigned int index);
1317 bool switchPositionAllowedTaranis(int index) const;
1318 bool switchSourceAllowedTaranis(int index) const;
1319 bool isPotAvailable(int index) const;
1320 bool isSliderAvailable(int index) const;
1323 class RadioData {
1324 public:
1325 GeneralSettings generalSettings;
1326 ModelData models[CPN_MAX_MODELS];
1328 void setCurrentModel(unsigned int index)
1330 generalSettings.currModelIndex = index;
1331 strcpy(generalSettings.currModelFilename, models[index].filename);
1334 QString getNextModelFilename()
1336 char filename[sizeof(ModelData::filename)];
1337 int index = 0;
1338 bool found = true;
1339 while (found) {
1340 sprintf(filename, "model%d.bin", ++index);
1341 found = false;
1342 for (int i=0; i<CPN_MAX_MODELS; i++) {
1343 if (strcmp(filename, models[i].filename) == 0) {
1344 found = true;
1345 break;
1349 return filename;
1353 enum Capability {
1354 ModelName,
1355 FlightModes,
1356 FlightModesName,
1357 FlightModesHaveFades,
1358 Imperial,
1359 Mixes,
1360 Timers,
1361 TimersName,
1362 TimeDivisions,
1363 CustomFunctions,
1364 SafetyChannelCustomFunction,
1365 VoicesAsNumbers,
1366 VoicesMaxLength,
1367 ModelVoice,
1368 MultiLangVoice,
1369 ModelImage,
1370 Pots,
1371 Sliders,
1372 Switches,
1373 SwitchesPositions,
1374 LogicalSwitches,
1375 CustomAndSwitches,
1376 HasNegAndSwitches,
1377 LogicalSwitchesExt,
1378 RotaryEncoders,
1379 Outputs,
1380 ChannelsName,
1381 ExtraInputs,
1382 ExtendedTrims,
1383 NumCurves,
1384 NumCurvePoints,
1385 OffsetWeight,
1386 Simulation,
1387 SoundMod,
1388 SoundPitch,
1389 MaxVolume,
1390 EepromBackup,
1391 Haptic,
1392 HasBeeper,
1393 ModelTrainerEnable,
1394 HasExpoNames,
1395 HasNoExpo,
1396 HasMixerNames,
1397 HasCvNames,
1398 HasPxxCountry,
1399 HasPPMStart,
1400 HasGeneralUnits,
1401 HasFAIMode,
1402 OptrexDisplay,
1403 PPMExtCtrl,
1404 PPMFrameLength,
1405 Telemetry,
1406 TelemetryUnits,
1407 TelemetryBars,
1408 Heli,
1409 Gvars,
1410 GvarsInCS,
1411 GvarsAreNamed,
1412 GvarsFlightModes,
1413 GvarsName,
1414 NoTelemetryProtocol,
1415 TelemetryCustomScreens,
1416 TelemetryCustomScreensFieldsPerLine,
1417 TelemetryMaxMultiplier,
1418 HasVario,
1419 HasVarioSink,
1420 HasFailsafe,
1421 HasSoundMixer,
1422 NumModules,
1423 PPMCenter,
1424 PPMUnitMicroseconds,
1425 SYMLimits,
1426 HastxCurrentCalibration,
1427 HasVolume,
1428 HasBrightness,
1429 PerModelTimers,
1430 SlowScale,
1431 SlowRange,
1432 PermTimers,
1433 HasSDLogs,
1434 CSFunc,
1435 LcdWidth,
1436 LcdHeight,
1437 LcdDepth,
1438 GetThrSwitch,
1439 HasDisplayText,
1440 HasTopLcd,
1441 GlobalFunctions,
1442 VirtualInputs,
1443 TrainerInputs,
1444 RtcTime,
1445 SportTelemetry,
1446 LuaScripts,
1447 LuaInputsPerScript,
1448 LuaOutputsPerScript,
1449 LimitsPer1000,
1450 EnhancedCurves,
1451 HasFasOffset,
1452 HasMahPersistent,
1453 MultiposPots,
1454 MultiposPotsPositions,
1455 SimulatorVariant,
1456 MavlinkTelemetry,
1457 HasInputDiff,
1458 HasMixerExpo,
1459 MixersMonitor,
1460 HasBatMeterRange,
1461 DangerousFunctions,
1464 class SimulatorInterface;
1465 class EEPROMInterface
1467 public:
1469 EEPROMInterface(BoardEnum board):
1470 board(board)
1474 virtual ~EEPROMInterface() {}
1476 inline BoardEnum getBoard() { return board; }
1478 virtual unsigned long load(RadioData &radioData, const uint8_t * eeprom, int size) = 0;
1480 virtual unsigned long loadBackup(RadioData & radioData, const uint8_t * eeprom, int esize, int index) = 0;
1482 virtual unsigned long loadxml(RadioData & radioData, QDomDocument &doc) = 0;
1484 virtual int save(uint8_t * eeprom, RadioData & radioData, uint8_t version=0, uint32_t variant=0) = 0;
1486 virtual int getSize(const ModelData &) = 0;
1488 virtual int getSize(const GeneralSettings &) = 0;
1490 virtual const int getEEpromSize() = 0;
1492 virtual const int getMaxModels() = 0;
1494 virtual int loadFile(RadioData & radioData, const QString & filename) = 0;
1496 virtual int saveFile(const RadioData & radioData, const QString & filename) = 0;
1498 protected:
1500 BoardEnum board;
1502 private:
1504 EEPROMInterface();
1508 extern std::list<QString> EEPROMWarnings;
1510 /* EEPROM string conversion functions */
1511 void setEEPROMString(char *dst, const char *src, int size);
1512 void getEEPROMString(char *dst, const char *src, int size);
1514 float ValToTim(int value);
1515 int TimToVal(float value);
1517 QString getSignedStr(int value);
1518 QString getGVarString(int16_t val, bool sign=false);
1520 inline int applyStickMode(int stick, unsigned int mode)
1522 if (mode == 0 || mode > 4) {
1523 std::cerr << "Incorrect stick mode" << mode;
1524 return stick;
1527 const unsigned int stickModes[]= {
1528 1, 2, 3, 4,
1529 1, 3, 2, 4,
1530 4, 2, 3, 1,
1531 4, 3, 2, 1 };
1533 if (stick >= 1 && stick <= 4)
1534 return stickModes[(mode-1)*4 + stick - 1];
1535 else
1536 return stick;
1539 inline void applyStickModeToModel(ModelData &model, unsigned int mode)
1541 ModelData model_copy = model;
1543 // trims
1544 for (int p=0; p<CPN_MAX_FLIGHT_MODES; p++) {
1545 for (int i=0; i<CPN_MAX_STICKS/2; i++) {
1546 int converted_stick = applyStickMode(i+1, mode) - 1;
1547 int tmp = model.flightModeData[p].trim[i];
1548 model.flightModeData[p].trim[i] = model.flightModeData[p].trim[converted_stick];
1549 model.flightModeData[p].trim[converted_stick] = tmp;
1550 tmp = model.flightModeData[p].trimRef[i];
1551 model.flightModeData[p].trimRef[i] = model.flightModeData[p].trimRef[converted_stick];
1552 model.flightModeData[p].trimRef[converted_stick] = tmp;
1556 // expos
1557 for (unsigned int i=0; i<sizeof(model.expoData) / sizeof(model.expoData[1]); i++) {
1558 if (model.expoData[i].mode)
1559 model_copy.expoData[i].chn = applyStickMode(model.expoData[i].chn+1, mode) - 1;
1561 int index=0;
1562 for (unsigned int i=0; i<CPN_MAX_STICKS; i++) {
1563 for (unsigned int e=0; e<sizeof(model.expoData) / sizeof(model.expoData[1]); e++) {
1564 if (model_copy.expoData[e].mode && model_copy.expoData[e].chn == i)
1565 model.expoData[index++] = model_copy.expoData[e];
1569 // mixers
1570 for (int i=0; i<CPN_MAX_MIXERS; i++) {
1571 if (model.mixData[i].srcRaw.type == SOURCE_TYPE_STICK) {
1572 model.mixData[i].srcRaw.index = applyStickMode(model.mixData[i].srcRaw.index + 1, mode) - 1;
1576 // virtual switches
1577 for (int i=0; i<CPN_MAX_CSW; i++) {
1578 RawSource source;
1579 switch (model.logicalSw[i].getFunctionFamily()) {
1580 case LS_FAMILY_VCOMP:
1581 source = RawSource(model.logicalSw[i].val2);
1582 if (source.type == SOURCE_TYPE_STICK)
1583 source.index = applyStickMode(source.index + 1, mode) - 1;
1584 model.logicalSw[i].val2 = source.toValue();
1585 // no break
1586 case LS_FAMILY_VOFS:
1587 source = RawSource(model.logicalSw[i].val1);
1588 if (source.type == SOURCE_TYPE_STICK)
1589 source.index = applyStickMode(source.index + 1, mode) - 1;
1590 model.logicalSw[i].val1 = source.toValue();
1591 break;
1592 default:
1593 break;
1597 // heli
1598 if (model.swashRingData.collectiveSource.type == SOURCE_TYPE_STICK)
1599 model.swashRingData.collectiveSource.index = applyStickMode(model.swashRingData.collectiveSource.index + 1, mode) - 1;
1602 void registerEEpromInterfaces();
1603 void unregisterEEpromInterfaces();
1604 void registerOpenTxFirmwares();
1605 void unregisterOpenTxFirmwares();
1607 enum EepromLoadErrors {
1608 ALL_OK,
1609 UNKNOWN_ERROR,
1610 UNSUPPORTED_NEWER_VERSION,
1611 WRONG_SIZE,
1612 WRONG_FILE_SYSTEM,
1613 NOT_OPENTX,
1614 NOT_TH9X,
1615 NOT_GRUVIN9X,
1616 NOT_ERSKY9X,
1617 NOT_ER9X,
1618 UNKNOWN_BOARD,
1619 WRONG_BOARD,
1620 BACKUP_NOT_SUPPORTED,
1622 HAS_WARNINGS,
1623 OLD_VERSION,
1624 WARNING_WRONG_FIRMWARE,
1626 NUM_ERRORS
1629 void ShowEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound);
1630 void ShowEepromWarnings(QWidget *parent, const QString &title, unsigned long errorsFound);
1633 struct Option {
1634 const char * name;
1635 QString tooltip;
1636 uint32_t variant;
1639 class Firmware {
1641 public:
1642 Firmware(const QString & id, const QString & name, const BoardEnum board, EEPROMInterface * eepromInterface):
1643 id(id),
1644 name(name),
1645 board(board),
1646 eepromInterface(eepromInterface),
1647 variantBase(0),
1648 base(NULL)
1652 Firmware(Firmware * base, const QString & id, const QString & name, const BoardEnum board, EEPROMInterface * eepromInterface):
1653 id(id),
1654 name(name),
1655 board(board),
1656 eepromInterface(eepromInterface),
1657 variantBase(0),
1658 base(base)
1662 virtual ~Firmware()
1664 delete eepromInterface;
1667 inline const Firmware * getFirmwareBase() const
1669 return base ? base : this;
1672 // TODO needed?
1673 inline void setVariantBase(unsigned int variant)
1675 variantBase = variant;
1678 virtual Firmware * getFirmwareVariant(const QString & id) { return NULL; }
1680 unsigned int getVariantNumber();
1682 virtual void addLanguage(const char *lang);
1684 virtual void addTTSLanguage(const char *lang);
1686 virtual void addOption(const char *option, QString tooltip="", uint32_t variant=0);
1688 virtual void addOptions(Option options[]);
1690 inline int saveEEPROM(uint8_t * eeprom, RadioData & radioData, uint8_t version=0, uint32_t variant=0)
1692 return eepromInterface->save(eeprom, radioData, version, variant);
1695 virtual QString getStampUrl() = 0;
1697 virtual QString getReleaseNotesUrl() = 0;
1699 virtual QString getFirmwareUrl() = 0;
1701 inline BoardEnum getBoard() const
1703 return board;
1706 inline QString getName() const
1708 return name;
1711 inline QString getId() const
1713 return id;
1716 inline EEPROMInterface * getEepromInterface()
1718 return eepromInterface;
1721 virtual int getCapability(Capability) = 0;
1723 enum SwitchType {
1724 SWITCH_NONE,
1725 SWITCH_TOGGLE,
1726 SWITCH_2POS,
1727 SWITCH_3POS
1730 struct Switch {
1731 SwitchType type;
1732 const char * name;
1735 virtual Switch getSwitch(unsigned int index) = 0;
1737 virtual QString getAnalogInputName(unsigned int index) = 0;
1739 virtual QTime getMaxTimerStart() = 0;
1741 virtual bool isTelemetrySourceAvailable(int source) = 0;
1743 virtual int isAvailable(PulsesProtocol proto, int port=0) = 0;
1745 const int getFlashSize();
1747 public:
1748 QList<const char *> languages;
1749 QList<const char *> ttslanguages;
1750 QList< QList<Option> > opts;
1752 protected:
1753 QString id;
1754 QString name;
1755 BoardEnum board;
1756 EEPROMInterface * eepromInterface;
1757 unsigned int variantBase;
1758 Firmware * base;
1760 private:
1761 Firmware();
1765 extern QList<Firmware *> firmwares;
1766 extern Firmware * default_firmware_variant;
1767 extern Firmware * current_firmware_variant;
1769 Firmware * GetFirmware(QString id);
1771 inline Firmware * GetCurrentFirmware()
1773 return current_firmware_variant;
1776 SimulatorInterface *getCurrentFirmwareSimulator();
1778 inline EEPROMInterface * GetEepromInterface()
1780 return GetCurrentFirmware()->getEepromInterface();
1783 inline int divRoundClosest(const int n, const int d)
1785 return ((n < 0) ^ (d < 0)) ? ((n - d/2)/d) : ((n + d/2)/d);
1788 #define CHECK_IN_ARRAY(T, index) ((unsigned int)index < (unsigned int)(sizeof(T)/sizeof(T[0])) ? T[(unsigned int)index] : "???")
1790 SimulatorInterface * GetCurrentFirmwareSimulator();
1792 extern QList<EEPROMInterface *> eepromInterfaces;
1794 #endif // _EEPROMINTERFACE_H_