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_
26 #include <QStringList>
28 #include <QtXml> // This should be removed from here, and remove Xml dependency from all libs which don't need it.
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]= {
76 SWITCH_THR
= SWITCH_NONE
+1,
86 SWITCH_SA0
= SWITCH_NONE
+1,
132 FAILSAFE_LAST
= FAILSAFE_RECEIVER
145 #define TRIM_T6_DN 10
146 #define TRIM_T6_UP 11
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,
155 HELI_SWASH_TYPE_120X
,
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
,
176 TELEMETRY_SOURCE_ALT
,
177 TELEMETRY_SOURCE_RPM
,
178 TELEMETRY_SOURCE_FUEL
,
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
228 SOURCE_TYPE_VIRTUAL_INPUT
,
229 SOURCE_TYPE_LUA_OUTPUT
,
230 SOURCE_TYPE_STICK
, // and POTS
231 SOURCE_TYPE_ROTARY_ENCODER
,
235 SOURCE_TYPE_CUSTOM_SWITCH
,
241 SOURCE_TYPE_TELEMETRY
,
245 QString
RotaryEncoderString(int index
);
259 float getValue(int value
);
269 #define RANGE_SINGLE_PRECISION 1
270 #define RANGE_DELTA_FUNCTION 2
271 #define RANGE_DELTA_ABS_FUNCTION 4
276 type(SOURCE_TYPE_NONE
),
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):
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;
312 bool isSlider() const;
322 SWITCH_TYPE_MULTIPOS_POT
,
324 SWITCH_TYPE_ROTARY_ENCODER
,
328 SWITCH_TYPE_FLIGHT_MODE
,
329 SWITCH_TYPE_TIMER_MODE
335 type(SWITCH_TYPE_NONE
),
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):
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
);
371 class CurveReference
{
380 CurveReference() { clear(); }
382 CurveReference(CurveRefType type
, int value
):
388 void clear() { memset(this, 0, sizeof(CurveReference
)); }
393 QString
toString() const;
405 ExpoData() { clear(); }
411 unsigned int flightModes
; // -5=!FP4, 0=normal, 5=FP4
414 CurveReference curve
;
417 void clear() { memset(this, 0, sizeof(ExpoData
)); }
431 CURVE_TYPE_LAST
= CURVE_TYPE_CUSTOM
435 void clear(int count
);
436 bool isEmpty() const;
440 CurvePoint points
[CPN_MAX_POINTS
];
446 LimitData() { clear(); }
454 CurveReference curve
;
455 QString
minToString() const;
456 QString
maxToString() const;
457 QString
offsetToString() const;
458 QString
revertToString() const;
468 #define MIXDATA_NAME_LEN 10
472 MixData() { clear(); }
473 unsigned int destCh
; // 1..CPN_MAX_CHNOUT
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
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
488 char name
[MIXDATA_NAME_LEN
+1];
490 void clear() { memset(this, 0, sizeof(MixData
)); }
510 LS_FN_VEQUAL
, // added at the end to avoid everything renumbered
515 // later ... LS_FN_RANGE,
519 enum CSFunctionFamily
{
528 class LogicalSwitchData
{ // Logical Switches data
530 LogicalSwitchData(unsigned int func
=0)
540 unsigned int duration
;
542 void clear() { memset(this, 0, sizeof(LogicalSwitchData
)); }
543 CSFunctionFamily
getFunctionFamily() const;
544 unsigned int getRangeFlags() const;
545 QString
funcToString() const;
550 FuncOverrideCH32
= FuncOverrideCH1
+CPN_MAX_CHNOUT
-1,
573 FuncBackgroundMusicPause
,
575 FuncAdjustGVLast
= FuncAdjustGV1
+CPN_MAX_GVARS
-1,
576 FuncSetFailsafeInternalModule
,
577 FuncSetFailsafeExternalModule
,
578 FuncRangeCheckInternalModule
,
579 FuncRangeCheckExternalModule
,
580 FuncBindInternalModule
,
581 FuncBindExternalModule
,
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
596 CustomFunctionData(AssignFunc func
=FuncOverrideCH1
) { clear(); this->func
= func
; }
601 unsigned int enabled
; // TODO perhaps not any more the right name
602 unsigned int adjustMode
;
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
{
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
];
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
633 SwashRingData() { clear(); }
636 int collectiveWeight
;
638 RawSource collectiveSource
;
639 RawSource aileronSource
;
640 RawSource elevatorSource
;
642 void clear() { memset(this, 0, sizeof(SwashRingData
)); }
645 class FrSkyAlarmData
{
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
{
657 FrSkyRSSIAlarm() { clear(0, 50); }
660 void clear(unsigned int level
, int value
) { this->level
= level
; this->value
= value
;}
663 class FrSkyChannelData
{
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...
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
{
679 unsigned int barMin
; // minimum for bar display
680 unsigned int barMax
; // ditto for max display (would usually = ratio)
683 struct FrSkyLineData
{
687 struct TelemetryScriptData
{
691 enum TelemetryScreenEnum
{
692 TELEMETRY_SCREEN_NONE
,
693 TELEMETRY_SCREEN_NUMBERS
,
694 TELEMETRY_SCREEN_BARS
,
695 TELEMETRY_SCREEN_SCRIPT
698 class FrSkyScreenData
{
700 FrSkyScreenData() { clear(); }
703 FrSkyBarData bars
[4];
704 FrSkyLineData lines
[4];
705 TelemetryScriptData script
;
709 FrSkyScreenBody body
;
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
743 UART_MODE_TELEMETRY_MIRROR
,
745 UART_MODE_SBUS_TRAINER
,
750 TRAINER_MODE_MASTER_TRAINER_JACK
,
752 TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE
,
753 TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE
,
754 TRAINER_MODE_MASTER_BATTERY_COMPARTMENT
,
759 FrSkyData() { clear(); }
760 FrSkyChannelData channels
[4];
761 unsigned int usrProto
;
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
;
771 int varioCenterMin
; // if increment in 0.2m/s = 3.0m/s max
775 unsigned int storedMah
;
777 bool ignoreSensorIds
;
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
800 TimerData() { clear(); }
802 char name
[TIMER_NAME_LEN
+1];
804 unsigned int countdownBeep
;
806 unsigned int persistent
;
808 void clear() { memset(this, 0, sizeof(TimerData
)); mode
= RawSwitch(SWITCH_TYPE_TIMER_MODE
, 0); }
811 enum PulsesProtocol
{
832 enum MultiModuleRFProtocols
{
833 MM_RF_PROTO_FLYSKY
=0,
834 MM_RF_PROTO_FIRST
=MM_RF_PROTO_FLYSKY
,
860 MM_RF_PROTO_LAST
= MM_RF_PROTO_AFHDS2A
863 unsigned int getNumSubtypes(MultiModuleRFProtocols type
);
865 enum TrainerProtocol
{
868 TRAINER_MASTER_SBUS_MODULE
,
869 TRAINER_MASTER_CPPM_MODULE
,
870 TRAINER_MASTER_SBUS_BATT_COMPARTMENT
875 ModuleData() { clear(); }
876 unsigned int modelId
;
878 unsigned int subType
;
880 unsigned int channelsStart
;
881 int channelsCount
; // 0=8 channels
882 unsigned int failsafeMode
;
883 int failsafeChannels
[CPN_MAX_CHNOUT
];
888 bool pulsePol
; // false = positive
889 bool outputType
; // false = open drain, true = push pull
894 unsigned int rfProtocol
;
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
911 ScriptData() { clear(); }
914 int inputs
[CPN_MAX_SCRIPT_INPUTS
];
915 void clear() { memset(this, 0, sizeof(ScriptData
)); }
918 #define CPN_MAX_SENSORS 32
926 TELEM_TYPE_CALCULATED
932 TELEM_FORMULA_AVERAGE
,
935 TELEM_FORMULA_MULTIPLY
,
936 TELEM_FORMULA_TOTALIZE
,
938 TELEM_FORMULA_CONSUMPTION
,
940 TELEM_FORMULA_LAST
= TELEM_FORMULA_DIST
944 TELEM_CELL_INDEX_LOWEST
,
951 TELEM_CELL_INDEX_HIGHEST
,
952 TELEM_CELL_INDEX_DELTA
,
962 UNIT_METERS_PER_SECOND
,
963 UNIT_FEET_PER_SECOND
,
982 // FrSky format used for these fields, could be another format in the future
984 UNIT_CELLS
= UNIT_FIRST_VIRTUAL
,
989 UNIT_GPS_LONGITUDE_EW
,
990 UNIT_GPS_LATITUDE_NS
,
992 UNIT_DATETIME_DAY_MONTH
,
993 UNIT_DATETIME_HOUR_MIN
,
997 SensorData() { clear(); }
998 unsigned int type
; // custom / formula
1001 unsigned int instance
;
1002 unsigned int persistentValue
;
1003 unsigned int formula
;
1013 // for custom sensors
1021 unsigned int source
;
1031 bool isAvailable() const { return strlen(label
) > 0; }
1033 QString
unitString() const;
1034 void clear() { memset(this, 0, sizeof(SensorData
)); }
1041 class CustomScreenOptionData
{
1046 class CustomScreenZoneData
{
1048 char widgetName
[10+1];
1049 WidgetOptionData widgetOptions
[5];
1052 class CustomScreenData
{
1056 char layoutName
[10+1];
1057 CustomScreenZoneData zones
[];
1058 CustomScreenOptionData options
[];
1061 typedef char CustomScreenData
[610+1];
1062 typedef char TopbarData
[216+1];
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;
1082 char category
[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
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
;
1116 char gvars_names
[CPN_MAX_GVARS
][6+1];
1117 bool gvars_popups
[CPN_MAX_GVARS
];
1118 MavlinkData mavlink
;
1119 unsigned int telemetryProtocol
;
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
;
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();
1155 int getChannelsMax(bool forceExtendedLimits
=false) const;
1158 void removeGlobalVar(int & var
);
1164 TrainerMix() { clear(); }
1165 unsigned int src
; // 0-7 = ch1-8
1168 unsigned int mode
; // off, add-mode, subst-mode
1169 void clear() { memset(this, 0, sizeof(TrainerMix
)); }
1174 TrainerData() { clear(); }
1177 void clear() { memset(this, 0, sizeof(TrainerData
)); }
1180 class GeneralSettings
{
1185 BEEPER_ALARMS_ONLY
= -1,
1193 POT_MULTIPOS_SWITCH
,
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
;
1222 TrainerData trainer
;
1223 unsigned int view
; // main screen view // TODO enum
1224 bool disableThrottleWarning
;
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
1236 unsigned int inactivityTimer
;
1240 bool disablePotScroll
;
1241 bool frskyinternalalarm
;
1243 unsigned int splashMode
;
1245 unsigned int backlightDelay
;
1248 unsigned int templateSetup
; //RETA order according to chout_ar array
1251 unsigned int reNavigation
;
1252 unsigned int stickReverse
;
1253 bool hideNameOnSplash
;
1255 unsigned int speakerPitch
;
1257 unsigned int speakerMode
;
1258 unsigned int lightOnStickMove
; /* er9x / ersky9x only */
1259 char ownerName
[10+1];
1260 unsigned int switchWarningStates
;
1262 unsigned int gpsFormat
;
1264 unsigned int backlightBright
;
1265 unsigned int backlightOffBright
;
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
;
1279 unsigned int imperial
;
1281 char ttsLanguage
[2+1];
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];
1307 SwitchInfo(unsigned int index
, unsigned int position
):
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;
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
)];
1340 sprintf(filename
, "model%d.bin", ++index
);
1342 for (int i
=0; i
<CPN_MAX_MODELS
; i
++) {
1343 if (strcmp(filename
, models
[i
].filename
) == 0) {
1357 FlightModesHaveFades
,
1364 SafetyChannelCustomFunction
,
1414 NoTelemetryProtocol
,
1415 TelemetryCustomScreens
,
1416 TelemetryCustomScreensFieldsPerLine
,
1417 TelemetryMaxMultiplier
,
1424 PPMUnitMicroseconds
,
1426 HastxCurrentCalibration
,
1448 LuaOutputsPerScript
,
1454 MultiposPotsPositions
,
1464 class SimulatorInterface
;
1465 class EEPROMInterface
1469 EEPROMInterface(BoardEnum 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;
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
;
1527 const unsigned int stickModes
[]= {
1533 if (stick
>= 1 && stick
<= 4)
1534 return stickModes
[(mode
-1)*4 + stick
- 1];
1539 inline void applyStickModeToModel(ModelData
&model
, unsigned int mode
)
1541 ModelData model_copy
= model
;
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
;
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;
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
];
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;
1577 for (int i
=0; i
<CPN_MAX_CSW
; i
++) {
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();
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();
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
{
1610 UNSUPPORTED_NEWER_VERSION
,
1620 BACKUP_NOT_SUPPORTED
,
1624 WARNING_WRONG_FIRMWARE
,
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
);
1642 Firmware(const QString
& id
, const QString
& name
, const BoardEnum board
, EEPROMInterface
* eepromInterface
):
1646 eepromInterface(eepromInterface
),
1652 Firmware(Firmware
* base
, const QString
& id
, const QString
& name
, const BoardEnum board
, EEPROMInterface
* eepromInterface
):
1656 eepromInterface(eepromInterface
),
1664 delete eepromInterface
;
1667 inline const Firmware
* getFirmwareBase() const
1669 return base
? base
: this;
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
1706 inline QString
getName() const
1711 inline QString
getId() const
1716 inline EEPROMInterface
* getEepromInterface()
1718 return eepromInterface
;
1721 virtual int getCapability(Capability
) = 0;
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();
1748 QList
<const char *> languages
;
1749 QList
<const char *> ttslanguages
;
1750 QList
< QList
<Option
> > opts
;
1756 EEPROMInterface
* eepromInterface
;
1757 unsigned int variantBase
;
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_