Companion build on Linux
This commit is contained in:
@@ -0,0 +1,955 @@
|
||||
#include <algorithm>
|
||||
#include "er9xeeprom.h"
|
||||
#include "helpers.h"
|
||||
#include <QObject>
|
||||
|
||||
int8_t er9xFromSwitch(const RawSwitch & sw)
|
||||
{
|
||||
switch (sw.type) {
|
||||
case SWITCH_TYPE_SWITCH:
|
||||
return sw.index;
|
||||
case SWITCH_TYPE_VIRTUAL:
|
||||
return sw.index > 0 ? (9 + sw.index) : (-9 + sw.index);
|
||||
case SWITCH_TYPE_ON:
|
||||
return 22;
|
||||
case SWITCH_TYPE_OFF:
|
||||
return -22;
|
||||
case SWITCH_TYPE_MOMENT_SWITCH:
|
||||
return sw.index > 0 ? (22 + sw.index) : (-22 + sw.index);
|
||||
case SWITCH_TYPE_MOMENT_VIRTUAL:
|
||||
return sw.index > 0 ? (31 + sw.index) : (-31 + sw.index);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
RawSwitch er9xToSwitch(int8_t sw)
|
||||
{
|
||||
uint8_t swa = abs(sw);
|
||||
if (swa == 0)
|
||||
return RawSwitch(SWITCH_TYPE_NONE);
|
||||
else if (swa <= 9)
|
||||
return RawSwitch(SWITCH_TYPE_SWITCH, sw);
|
||||
else if (swa <= 21)
|
||||
return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9);
|
||||
else if (sw == 22)
|
||||
return RawSwitch(SWITCH_TYPE_ON);
|
||||
else if (sw == -22)
|
||||
return RawSwitch(SWITCH_TYPE_OFF);
|
||||
else if (swa <= 22+9)
|
||||
return RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, sw > 0 ? sw-22 : sw+22);
|
||||
else
|
||||
return RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, sw > 0 ? sw-22-9 : sw+22+9);
|
||||
}
|
||||
|
||||
t_Er9xTrainerMix::t_Er9xTrainerMix()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xTrainerMix));
|
||||
}
|
||||
|
||||
t_Er9xTrainerMix::t_Er9xTrainerMix(TrainerMix &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xTrainerMix));
|
||||
srcChn = c9x.src;
|
||||
swtch = er9xFromSwitch(c9x.swtch);
|
||||
studWeight = (8 * c9x.weight) / 25;
|
||||
mode = c9x.mode;
|
||||
}
|
||||
|
||||
t_Er9xTrainerMix::operator TrainerMix()
|
||||
{
|
||||
TrainerMix c9x;
|
||||
c9x.src = srcChn;
|
||||
c9x.swtch = er9xToSwitch(swtch);
|
||||
c9x.weight = (25 * studWeight) / 8;
|
||||
c9x.mode = mode;
|
||||
return c9x;
|
||||
}
|
||||
|
||||
t_Er9xTrainerData::t_Er9xTrainerData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xTrainerData));
|
||||
}
|
||||
|
||||
t_Er9xTrainerData::t_Er9xTrainerData(TrainerData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xTrainerData));
|
||||
for (int i=0; i<NUM_STICKS; i++) {
|
||||
calib[i] = c9x.calib[i];
|
||||
mix[i] = c9x.mix[i];
|
||||
}
|
||||
}
|
||||
|
||||
t_Er9xTrainerData::operator TrainerData ()
|
||||
{
|
||||
TrainerData c9x;
|
||||
for (int i=0; i<NUM_STICKS; i++) {
|
||||
c9x.calib[i] = calib[i];
|
||||
c9x.mix[i] = mix[i];
|
||||
}
|
||||
return c9x;
|
||||
}
|
||||
|
||||
t_Er9xGeneral::t_Er9xGeneral()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xGeneral));
|
||||
}
|
||||
|
||||
t_Er9xGeneral::t_Er9xGeneral(GeneralSettings &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xGeneral));
|
||||
|
||||
myVers = MDVERS;
|
||||
|
||||
for (int i=0; i<NUM_STICKSnPOTS; i++) {
|
||||
calibMid[i] = c9x.calibMid[i];
|
||||
calibSpanNeg[i] = c9x.calibSpanNeg[i];
|
||||
calibSpanPos[i] = c9x.calibSpanPos[i];
|
||||
}
|
||||
|
||||
uint16_t sum = 0;
|
||||
for (int i=0; i<12; i++)
|
||||
sum += calibMid[i];
|
||||
chkSum = sum;
|
||||
|
||||
currModel = c9x.currModel;
|
||||
contrast = c9x.contrast;
|
||||
vBatWarn = c9x.vBatWarn;
|
||||
vBatCalib = c9x.vBatCalib;
|
||||
|
||||
trainer = c9x.trainer;
|
||||
view = c9x.view;
|
||||
disableThrottleWarning = c9x.disableThrottleWarning;
|
||||
disableSwitchWarning = (c9x.switchWarning != -1);
|
||||
disableMemoryWarning = c9x.disableMemoryWarning;
|
||||
|
||||
if (c9x.beeperMode == e_quiet)
|
||||
beeperVal = 0;
|
||||
else if (c9x.beeperMode < e_all)
|
||||
beeperVal = 1;
|
||||
else
|
||||
beeperVal = c9x.beeperLength + 4;
|
||||
|
||||
disableAlarmWarning = c9x.disableAlarmWarning;
|
||||
stickMode = c9x.stickMode;
|
||||
inactivityTimer = c9x.inactivityTimer - 10;
|
||||
throttleReversed = c9x.throttleReversed;
|
||||
minuteBeep = c9x.minuteBeep;
|
||||
preBeep = c9x.preBeep;
|
||||
flashBeep = c9x.flashBeep;
|
||||
disableSplashScreen = c9x.splashMode;
|
||||
disablePotScroll=(c9x.disablePotScroll ? 1 : 0);
|
||||
disableBG=(c9x.disableBG ? 1 :0);
|
||||
frskyinternalalarm = c9x.frskyinternalalarm;
|
||||
blightinv=(c9x.blightinv ? 1 : 0);
|
||||
stickScroll=(c9x.stickScroll ? 1 : 0);
|
||||
|
||||
if (c9x.backlightMode == 4)
|
||||
lightSw = 22;
|
||||
if (c9x.backlightMode & 1)
|
||||
lightAutoOff = c9x.backlightDelay;
|
||||
if (c9x.backlightMode & 2)
|
||||
lightOnStickMove = c9x.backlightDelay;
|
||||
|
||||
templateSetup = c9x.templateSetup;
|
||||
PPM_Multiplier = c9x.PPM_Multiplier;
|
||||
setEEPROMString(ownerName, c9x.ownerName, sizeof(ownerName));
|
||||
speakerPitch = c9x.speakerPitch;
|
||||
hapticStrength = c9x.hapticStrength;
|
||||
hideNameOnSplash = (c9x.hideNameOnSplash ? 1 : 0);
|
||||
enablePpmsim = (c9x.enablePpmsim ? 1 : 0);;
|
||||
|
||||
speakerMode = c9x.speakerMode;
|
||||
switchWarningStates =c9x.switchWarningStates;
|
||||
crosstrim=(c9x.crosstrim ? 1 : 0);
|
||||
|
||||
}
|
||||
|
||||
Er9xGeneral::operator GeneralSettings ()
|
||||
{
|
||||
GeneralSettings result;
|
||||
result.version = myVers;
|
||||
for (int i=0; i<NUM_STICKSnPOTS; i++) {
|
||||
result.calibMid[i] = calibMid[i];
|
||||
result.calibSpanNeg[i] = calibSpanNeg[i];
|
||||
result.calibSpanPos[i] = calibSpanPos[i];
|
||||
}
|
||||
|
||||
result.currModel = currModel;
|
||||
result.contrast = contrast;
|
||||
result.vBatWarn = vBatWarn;
|
||||
result.vBatCalib = vBatCalib;
|
||||
result.trainer = trainer;
|
||||
result.blightinv=blightinv;
|
||||
result.stickScroll=stickScroll;
|
||||
result.crosstrim=crosstrim;
|
||||
result.hideNameOnSplash=hideNameOnSplash;
|
||||
result.enablePpmsim=enablePpmsim;
|
||||
|
||||
result.view = std::min((uint8_t)4, view);
|
||||
result.disableThrottleWarning = disableThrottleWarning;
|
||||
result.switchWarning = disableSwitchWarning ? 0 : -1;
|
||||
result.disableMemoryWarning = disableMemoryWarning;
|
||||
|
||||
switch (beeperVal) {
|
||||
case 0:
|
||||
result.beeperMode = e_quiet;
|
||||
break;
|
||||
case 1:
|
||||
result.beeperMode = e_no_keys;
|
||||
break;
|
||||
default:
|
||||
result.beeperMode = e_all;
|
||||
result.beeperLength = beeperVal - 4;
|
||||
break;
|
||||
}
|
||||
|
||||
result.disableAlarmWarning = disableAlarmWarning;
|
||||
result.stickMode = std::max((uint8_t)0, std::min(stickMode, (uint8_t)3));
|
||||
result.inactivityTimer = inactivityTimer + 10;
|
||||
result.throttleReversed = throttleReversed;
|
||||
result.minuteBeep = minuteBeep;
|
||||
result.preBeep = preBeep;
|
||||
result.flashBeep = flashBeep;
|
||||
result.splashMode = disableSplashScreen;
|
||||
result.disablePotScroll=(disablePotScroll==1);
|
||||
result.disableBG=(disableBG==1);
|
||||
result.frskyinternalalarm = frskyinternalalarm;
|
||||
|
||||
result.backlightMode = 0;
|
||||
if (lightSw == 22) {
|
||||
result.backlightMode = 4;
|
||||
}
|
||||
else if (lightAutoOff) {
|
||||
result.backlightMode |= 1;
|
||||
result.backlightDelay = lightAutoOff;
|
||||
}
|
||||
else if (lightOnStickMove) {
|
||||
result.backlightMode |= 2;
|
||||
result.backlightDelay = lightOnStickMove;
|
||||
}
|
||||
|
||||
result.templateSetup = templateSetup;
|
||||
result.PPM_Multiplier = PPM_Multiplier;
|
||||
getEEPROMString(result.ownerName, ownerName, sizeof(ownerName));
|
||||
result.speakerPitch = speakerPitch;
|
||||
result.hapticStrength = hapticStrength;
|
||||
result.speakerMode = speakerMode;
|
||||
result.switchWarningStates =switchWarningStates;
|
||||
return result;
|
||||
}
|
||||
|
||||
t_Er9xLimitData::t_Er9xLimitData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xLimitData));
|
||||
}
|
||||
|
||||
t_Er9xLimitData::t_Er9xLimitData(LimitData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xLimitData));
|
||||
min = c9x.min+100;
|
||||
max = c9x.max-100;
|
||||
revert = c9x.revert;
|
||||
offset = c9x.offset;
|
||||
}
|
||||
|
||||
t_Er9xLimitData::operator LimitData ()
|
||||
{
|
||||
LimitData c9x;
|
||||
c9x.min = min-100;
|
||||
c9x.max = max+100;
|
||||
c9x.revert = revert;
|
||||
c9x.offset = offset;
|
||||
return c9x;
|
||||
}
|
||||
|
||||
t_Er9xMixData::t_Er9xMixData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xMixData));
|
||||
}
|
||||
|
||||
t_Er9xMixData::t_Er9xMixData(MixData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xMixData));
|
||||
destCh = c9x.destCh;
|
||||
swtch = er9xFromSwitch(c9x.swtch);
|
||||
|
||||
if (c9x.srcRaw.type == SOURCE_TYPE_NONE) {
|
||||
srcRaw = 0;
|
||||
swtch = 0;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_STICK) {
|
||||
srcRaw = 1 + c9x.srcRaw.index;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_ROTARY_ENCODER) {
|
||||
EEPROMWarnings += ::QObject::tr("er9x doesn't have Rotary Encoders") + "\n";
|
||||
srcRaw = 5 + c9x.srcRaw.index; // use pots instead
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_MAX) {
|
||||
srcRaw = 8; // MAX
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_SWITCH) {
|
||||
srcRaw = 9; // FULL
|
||||
swtch = er9xFromSwitch(RawSwitch(c9x.srcRaw.index));
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_CYC) {
|
||||
srcRaw = 10 + c9x.srcRaw.index;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_PPM) {
|
||||
srcRaw = 13 + c9x.srcRaw.index;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_CH) {
|
||||
srcRaw = 21 + c9x.srcRaw.index;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_GVAR) {
|
||||
srcRaw = 38 + c9x.srcRaw.index;
|
||||
}
|
||||
else if (c9x.srcRaw.type == SOURCE_TYPE_TRIM) {
|
||||
EEPROMWarnings += ::QObject::tr("er9x doesn't have trims as source") + "\n";
|
||||
srcRaw = 0; // use pots instead
|
||||
}
|
||||
if (abs(c9x.weight)>125) {
|
||||
if (c9x.weight>0) {
|
||||
int index=abs(c9x.weight)-10000;
|
||||
int gvar=125+index;
|
||||
if (gvar>127) {
|
||||
gvar-=256;
|
||||
}
|
||||
weight = gvar;
|
||||
} else {
|
||||
EEPROMWarnings += ::QObject::tr("er9x doesn't have negative gvars as weight") + "\n";
|
||||
weight=0;
|
||||
}
|
||||
} else {
|
||||
weight = c9x.weight;
|
||||
}
|
||||
|
||||
if (abs(c9x.sOffset)>125) {
|
||||
if (c9x.sOffset>0) {
|
||||
int index=abs(c9x.sOffset)-10000;
|
||||
int gvar=125+index;
|
||||
if (gvar>127) {
|
||||
gvar-=256;
|
||||
}
|
||||
sOffset = gvar;
|
||||
} else {
|
||||
EEPROMWarnings += ::QObject::tr("er9x doesn't have negative gvars as offset") + "\n";
|
||||
sOffset=0;
|
||||
}
|
||||
} else {
|
||||
sOffset = c9x.sOffset;
|
||||
}
|
||||
|
||||
if (c9x.curve!=0) {
|
||||
curve = c9x.curve;
|
||||
differential=0;
|
||||
} else {
|
||||
if (c9x.differential!=0) {
|
||||
curve=c9x.differential;
|
||||
differential=1;
|
||||
} else {
|
||||
curve=0;
|
||||
differential=0;
|
||||
}
|
||||
}
|
||||
lateOffset=c9x.lateOffset;
|
||||
delayUp = c9x.delayUp;
|
||||
delayDown = c9x.delayDown;
|
||||
speedUp = c9x.speedUp;
|
||||
speedDown = c9x.speedDown;
|
||||
if (c9x.carryTrim<0) {
|
||||
EEPROMWarnings += ::QObject::tr("er9x doesn't have swappable trims") + "\n";
|
||||
carryTrim=1;
|
||||
} else {
|
||||
carryTrim = c9x.carryTrim;
|
||||
}
|
||||
mltpx = (MltpxValue)c9x.mltpx;
|
||||
mixWarn = c9x.mixWarn;
|
||||
enableFmTrim=c9x.enableFmTrim;
|
||||
|
||||
}
|
||||
|
||||
t_Er9xMixData::operator MixData ()
|
||||
{
|
||||
MixData c9x;
|
||||
c9x.destCh = destCh;
|
||||
if (abs(weight)>125) {
|
||||
int gvar;
|
||||
if (weight>0) {
|
||||
gvar=weight-125;
|
||||
} else {
|
||||
gvar=weight+131;
|
||||
}
|
||||
gvar+=10000;
|
||||
c9x.weight=gvar;
|
||||
} else {
|
||||
c9x.weight = weight;
|
||||
}
|
||||
if (abs(sOffset)>125) {
|
||||
int gvar;
|
||||
if (sOffset>0) {
|
||||
gvar=sOffset-125;
|
||||
} else {
|
||||
gvar=sOffset+131;
|
||||
}
|
||||
gvar+=10000;
|
||||
c9x.sOffset=gvar;
|
||||
} else {
|
||||
c9x.sOffset=sOffset;
|
||||
}
|
||||
c9x.swtch = er9xToSwitch(swtch);
|
||||
|
||||
if (srcRaw == 0) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_NONE);
|
||||
}
|
||||
else if (srcRaw <= 7) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1);
|
||||
}
|
||||
else if (srcRaw == 8) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_MAX);
|
||||
}
|
||||
else if (srcRaw == 9) {
|
||||
if (swtch < 0) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, swtch < -3 ? -swtch-3 : -swtch);
|
||||
c9x.weight = -weight;
|
||||
}
|
||||
else if (swtch > 0) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, swtch > 3 ? swtch-3 : swtch);
|
||||
}
|
||||
else {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_MAX);
|
||||
}
|
||||
if (mltpx != MLTPX_REP)
|
||||
c9x.swtch = RawSwitch(SWITCH_TYPE_NONE);
|
||||
}
|
||||
else if (srcRaw <= 12) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-10);
|
||||
}
|
||||
else if (srcRaw <= 20) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-13);
|
||||
}
|
||||
else if (srcRaw <=37) {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-21);
|
||||
}
|
||||
else {
|
||||
c9x.srcRaw = RawSource(SOURCE_TYPE_GVAR, srcRaw-38);
|
||||
}
|
||||
if (differential==1) {
|
||||
c9x.differential=curve;
|
||||
c9x.curve=0;
|
||||
} else {
|
||||
c9x.differential=0;
|
||||
c9x.curve=curve;
|
||||
}
|
||||
c9x.lateOffset=lateOffset;
|
||||
c9x.delayUp = delayUp;
|
||||
c9x.delayDown = delayDown;
|
||||
c9x.speedUp = speedUp;
|
||||
c9x.speedDown = speedDown;
|
||||
c9x.carryTrim = carryTrim;
|
||||
c9x.mltpx = (MltpxValue)mltpx;
|
||||
c9x.mixWarn = mixWarn;
|
||||
c9x.enableFmTrim=enableFmTrim;
|
||||
return c9x;
|
||||
}
|
||||
|
||||
int8_t er9xFromSource(RawSource source)
|
||||
{
|
||||
int v1 = 0;
|
||||
if (source.type == SOURCE_TYPE_STICK)
|
||||
v1 = 1+source.index;
|
||||
else if (source.type == SOURCE_TYPE_ROTARY_ENCODER) {
|
||||
EEPROMWarnings += ::QObject::tr("er9x on this board doesn't have Rotary Encoders") + "\n";
|
||||
v1 = 5+source.index;
|
||||
}
|
||||
else if (source.type == SOURCE_TYPE_MAX)
|
||||
v1 = 8;
|
||||
else if (source.type == SOURCE_TYPE_CYC)
|
||||
v1 = 10+source.index;
|
||||
else if (source.type == SOURCE_TYPE_PPM)
|
||||
v1 = 13+source.index;
|
||||
else if (source.type == SOURCE_TYPE_CH)
|
||||
v1 = 21+source.index;
|
||||
else if (source.type == SOURCE_TYPE_TELEMETRY)
|
||||
v1 = 36+source.index;
|
||||
return v1;
|
||||
}
|
||||
|
||||
RawSource er9xToSource(int8_t value)
|
||||
{
|
||||
if (value == 0) {
|
||||
return RawSource(SOURCE_TYPE_NONE);
|
||||
}
|
||||
else if (value <= 7) {
|
||||
return RawSource(SOURCE_TYPE_STICK, value - 1);
|
||||
}
|
||||
else if (value == 8) {
|
||||
return RawSource(SOURCE_TYPE_MAX);
|
||||
}
|
||||
else if (value == 9) {
|
||||
return RawSource(SOURCE_TYPE_MAX);
|
||||
}
|
||||
else if (value <= 12) {
|
||||
return RawSource(SOURCE_TYPE_CYC, value-10);
|
||||
}
|
||||
else if (value <= 20) {
|
||||
return RawSource(SOURCE_TYPE_PPM, value-13);
|
||||
}
|
||||
else if (value <= 36) {
|
||||
return RawSource(SOURCE_TYPE_CH, value-21);
|
||||
}
|
||||
else {
|
||||
return RawSource(SOURCE_TYPE_TELEMETRY, value-36);
|
||||
}
|
||||
}
|
||||
|
||||
t_Er9xCustomSwData::t_Er9xCustomSwData(CustomSwData &c9x)
|
||||
{
|
||||
func = c9x.func;
|
||||
v1 = c9x.val1;
|
||||
v2 = c9x.val2;
|
||||
|
||||
if ((c9x.func >= CS_FN_VPOS && c9x.func <= CS_FN_ANEG) || c9x.func >= CS_FN_EQUAL) {
|
||||
v1 = er9xFromSource(RawSource(c9x.val1));
|
||||
}
|
||||
|
||||
if (c9x.func >= CS_FN_EQUAL) {
|
||||
v2 = er9xFromSource(RawSource(c9x.val2));
|
||||
}
|
||||
|
||||
if (c9x.func >= CS_FN_AND && c9x.func <= CS_FN_XOR) {
|
||||
v1 = er9xFromSwitch(RawSwitch(c9x.val1));
|
||||
v2 = er9xFromSwitch(RawSwitch(c9x.val2));
|
||||
}
|
||||
|
||||
if (func>ER9X_MAX_CSFUNC ) {
|
||||
EEPROMWarnings += ::QObject::tr("er9x does not support Custom Switch function %1").arg(getFuncName(func)) + "\n";
|
||||
func=0;
|
||||
v1=0;
|
||||
v2=0;
|
||||
}
|
||||
}
|
||||
|
||||
Er9xCustomSwData::operator CustomSwData ()
|
||||
{
|
||||
CustomSwData c9x;
|
||||
c9x.func = func;
|
||||
c9x.val1 = v1;
|
||||
c9x.val2 = v2;
|
||||
|
||||
if ((c9x.func >= CS_FN_VPOS && c9x.func <= CS_FN_ANEG) || c9x.func >= CS_FN_EQUAL) {
|
||||
c9x.val1 = er9xToSource(v1).toValue();
|
||||
}
|
||||
|
||||
if (c9x.func >= CS_FN_EQUAL) {
|
||||
c9x.val2 = er9xToSource(v2).toValue();
|
||||
}
|
||||
|
||||
if (c9x.func >= CS_FN_AND && c9x.func <= CS_FN_XOR) {
|
||||
c9x.val1 = er9xToSwitch(v1).toValue();
|
||||
c9x.val2 = er9xToSwitch(v2).toValue();
|
||||
}
|
||||
|
||||
return c9x;
|
||||
}
|
||||
|
||||
|
||||
t_Er9xSafetySwData::t_Er9xSafetySwData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xSafetySwData));
|
||||
}
|
||||
|
||||
t_Er9xSafetySwData::t_Er9xSafetySwData(SafetySwData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xSafetySwData));
|
||||
swtch = er9xFromSwitch(c9x.swtch);
|
||||
val = c9x.val;
|
||||
}
|
||||
|
||||
t_Er9xSafetySwData::operator SafetySwData ()
|
||||
{
|
||||
SafetySwData c9x;
|
||||
c9x.swtch = er9xToSwitch(swtch);
|
||||
c9x.val = val;
|
||||
return c9x;
|
||||
}
|
||||
|
||||
|
||||
t_Er9xFrSkyChannelData::t_Er9xFrSkyChannelData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xFrSkyChannelData));
|
||||
}
|
||||
|
||||
t_Er9xFrSkyChannelData::t_Er9xFrSkyChannelData(FrSkyChannelData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xFrSkyChannelData));
|
||||
ratio = c9x.ratio;
|
||||
alarms_value[0] = c9x.alarms[0].value;
|
||||
alarms_value[1] = c9x.alarms[1].value;
|
||||
alarms_level = (c9x.alarms[1].level << 2) + c9x.alarms[0].level;
|
||||
alarms_greater = (c9x.alarms[1].greater << 1) + c9x.alarms[0].greater;
|
||||
if (c9x.type==0) {
|
||||
if (c9x.multiplier==0) {
|
||||
type = 0;
|
||||
} else if (c9x.multiplier==1) {
|
||||
type = 2;
|
||||
} else {
|
||||
EEPROMWarnings += ::QObject::tr("er9x does not support this range for A1/A2") + "\n";
|
||||
}
|
||||
} else if (c9x.type==1 || c9x.type==3) {
|
||||
type=c9x.type;
|
||||
} else {
|
||||
EEPROMWarnings += ::QObject::tr("er9x does not support this telemetry units") + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
t_Er9xFrSkyChannelData::operator FrSkyChannelData ()
|
||||
{
|
||||
FrSkyChannelData c9x;
|
||||
c9x.ratio = ratio;
|
||||
c9x.alarms[0].value = alarms_value[0];
|
||||
c9x.alarms[0].level = alarms_level & 3;
|
||||
c9x.alarms[0].greater = alarms_greater & 1;
|
||||
c9x.alarms[1].value = alarms_value[1];
|
||||
c9x.alarms[1].level = (alarms_level >> 2) & 3;
|
||||
c9x.alarms[1].greater = (alarms_greater >> 1) & 1;
|
||||
if (type==2) {
|
||||
c9x.type = 0;
|
||||
c9x.multiplier=1;
|
||||
} else {
|
||||
c9x.type = type;
|
||||
}
|
||||
return c9x;
|
||||
}
|
||||
|
||||
|
||||
t_Er9xFrSkyData::t_Er9xFrSkyData()
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xFrSkyData));
|
||||
}
|
||||
|
||||
t_Er9xFrSkyData::t_Er9xFrSkyData(FrSkyData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xFrSkyData));
|
||||
channels[0] = c9x.channels[0];
|
||||
channels[1] = c9x.channels[1];
|
||||
}
|
||||
|
||||
t_Er9xFrSkyData::operator FrSkyData ()
|
||||
{
|
||||
FrSkyData c9x;
|
||||
c9x.channels[0] = channels[0];
|
||||
c9x.channels[1] = channels[1];
|
||||
return c9x;
|
||||
}
|
||||
|
||||
int setEr9xTimerMode(TimerMode mode)
|
||||
{
|
||||
if (mode == TMRMODE_OFF || mode == TMRMODE_ABS)
|
||||
return mode;
|
||||
else if (mode == TMRMODE_THs || mode == TMRMODE_THp)
|
||||
return mode + 4;
|
||||
else if (mode >= TMRMODE_FIRST_MOMENT_SWITCH)
|
||||
return 37+mode-TMRMODE_FIRST_MOMENT_SWITCH;
|
||||
else if (mode >= TMRMODE_FIRST_SWITCH)
|
||||
return 16+mode-TMRMODE_FIRST_SWITCH;
|
||||
else if (mode <= TMRMODE_FIRST_NEG_MOMENT_SWITCH)
|
||||
return -37+mode-TMRMODE_FIRST_NEG_MOMENT_SWITCH;
|
||||
else if (mode <= TMRMODE_FIRST_NEG_SWITCH)
|
||||
return -16+mode-TMRMODE_FIRST_NEG_SWITCH;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
TimerMode getEr9xTimerMode(int mode)
|
||||
{
|
||||
if (mode <= -33)
|
||||
return TimerMode(TMRMODE_FIRST_NEG_MOMENT_SWITCH+(mode+33));
|
||||
else if (mode <= -1)
|
||||
return TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+1));
|
||||
else if (mode < 16)
|
||||
return TimerMode(mode);
|
||||
else if (mode < 16+21)
|
||||
return TimerMode(TMRMODE_FIRST_SWITCH+(mode-16));
|
||||
else
|
||||
return TimerMode(TMRMODE_FIRST_MOMENT_SWITCH+(mode-16-21));
|
||||
}
|
||||
|
||||
t_Er9xModelData::t_Er9xModelData(ModelData &c9x)
|
||||
{
|
||||
memset(this, 0, sizeof(t_Er9xModelData));
|
||||
|
||||
if (c9x.used) {
|
||||
setEEPROMString(name, c9x.name, sizeof(name));
|
||||
modelVoice=c9x.modelVoice;
|
||||
tmrMode = setEr9xTimerMode(c9x.timers[0].mode);
|
||||
tmrModeB = c9x.timers[0].modeB;
|
||||
tmrDir = c9x.timers[0].dir;
|
||||
tmrVal = c9x.timers[0].val;
|
||||
switch(c9x.moduleData[0].protocol) {
|
||||
case PPM:
|
||||
protocol = 0;
|
||||
break;
|
||||
case PXX_DJT:
|
||||
protocol = 1;
|
||||
break;
|
||||
case DSM2:
|
||||
protocol = 2;
|
||||
break;
|
||||
case PPM16:
|
||||
protocol = 3;
|
||||
break;
|
||||
default:
|
||||
protocol = 0;
|
||||
EEPROMWarnings += QObject::tr("Er9x doesn't accept this protocol") + "\n";
|
||||
// TODO more explicit warning for each protocol
|
||||
break;
|
||||
}
|
||||
traineron = c9x.traineron;
|
||||
t2throttle = c9x.t2throttle;
|
||||
ppmFrameLength = c9x.moduleData[0].ppmFrameLength;
|
||||
ppmNCH = (c9x.moduleData[0].channelsCount - 8) / 2;
|
||||
thrTrim = c9x.thrTrim;
|
||||
thrExpo = c9x.thrExpo;
|
||||
trimInc = c9x.trimInc;
|
||||
ppmDelay = (c9x.moduleData[0].ppmDelay - 300) / 50;
|
||||
for (unsigned int i=0; i<C9X_MAX_CUSTOM_FUNCTIONS; i++)
|
||||
if (c9x.funcSw[i].func == FuncInstantTrim && c9x.funcSw[i].swtch.type != SWITCH_TYPE_NONE) {
|
||||
trimSw = er9xFromSwitch(c9x.funcSw[i].swtch);
|
||||
break;
|
||||
}
|
||||
beepANACenter = (uint8_t)(c9x.beepANACenter & 0x7F);
|
||||
pulsePol = c9x.moduleData[0].ppmPulsePol;
|
||||
extendedLimits = c9x.extendedLimits;
|
||||
swashInvertELE = c9x.swashRingData.invertELE;
|
||||
swashInvertAIL = c9x.swashRingData.invertAIL;
|
||||
swashInvertCOL = c9x.swashRingData.invertCOL;
|
||||
swashType = c9x.swashRingData.type;
|
||||
swashCollectiveSource = er9xFromSource(c9x.swashRingData.collectiveSource);
|
||||
swashRingValue = c9x.swashRingData.value;
|
||||
for (int i=0; i<ER9X_MAX_MIXERS; i++)
|
||||
mixData[i] = c9x.mixData[i];
|
||||
for (int i=0; i<ER9X_NUM_CHNOUT; i++)
|
||||
limitData[i] = c9x.limitData[i];
|
||||
|
||||
// expoData
|
||||
for (unsigned int i=0; i<NUM_STICKS; i++) {
|
||||
// first we find the switches
|
||||
for (int e=0; e<C9X_MAX_EXPOS && c9x.expoData[e].mode; e++) {
|
||||
if (c9x.expoData[e].chn == i) {
|
||||
if (c9x.expoData[e].swtch.type!=SWITCH_TYPE_NONE) {
|
||||
if (!expoData[i].drSw1)
|
||||
expoData[i].drSw1 = -er9xFromSwitch(c9x.expoData[e].swtch);
|
||||
else if (er9xFromSwitch(c9x.expoData[e].swtch) != -expoData[i].drSw1 && !expoData[i].drSw2) {
|
||||
expoData[i].drSw2 = -er9xFromSwitch(c9x.expoData[e].swtch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expoData[i].drSw1 && !expoData[i].drSw2) {
|
||||
expoData[i].drSw1 = -expoData[i].drSw1;
|
||||
}
|
||||
|
||||
for (int pos=0; pos<3; pos++) {
|
||||
int swtch1=0, swtch2=0;
|
||||
if (expoData[i].drSw1 && !expoData[i].drSw2) {
|
||||
switch (pos) {
|
||||
case 0:
|
||||
swtch1 = -expoData[i].drSw1;
|
||||
break;
|
||||
case 1:
|
||||
swtch1 = expoData[i].drSw1;
|
||||
break;
|
||||
default:
|
||||
swtch1 = expoData[i].drSw1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (pos) {
|
||||
case 0:
|
||||
swtch1 = -expoData[i].drSw1;
|
||||
break;
|
||||
case 1:
|
||||
swtch1 = expoData[i].drSw1;
|
||||
swtch2 = -expoData[i].drSw2;
|
||||
break;
|
||||
default:
|
||||
swtch1 = expoData[i].drSw1;
|
||||
swtch2 = expoData[i].drSw2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int mode=0; mode<2; mode++) {
|
||||
for (int e=0; e<C9X_MAX_EXPOS && c9x.expoData[e].mode; e++) {
|
||||
if (c9x.expoData[e].chn == i && !c9x.expoData[e].phases) {
|
||||
if (c9x.expoData[e].swtch.type==SWITCH_TYPE_NONE || c9x.expoData[e].swtch == er9xToSwitch(swtch1) || c9x.expoData[e].swtch == er9xToSwitch(swtch2)) {
|
||||
if (c9x.expoData[e].mode == 3 || (c9x.expoData[e].mode==2 && mode==0) || (c9x.expoData[e].mode==1 && mode==1)) {
|
||||
expoData[i].expo[pos][0][mode] = c9x.expoData[e].expo;
|
||||
expoData[i].expo[pos][1][mode] = c9x.expoData[e].weight - 100;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_STICKS; i++)
|
||||
trim[i] = std::max(-125, std::min(125, c9x.phaseData[0].trim[i]));
|
||||
|
||||
for (int i=0; i<ER9X_MAX_CURVE5; i++)
|
||||
if (c9x.curves[i].count==5) {
|
||||
if (c9x.curves[i].custom)
|
||||
EEPROMWarnings += QObject::tr("Er9x doesn't support custom curves as curve%1, curve as been exported as fixed point ").arg(i+1) + "\n";
|
||||
for (int j=0; j<5; j++)
|
||||
curves5[i][j] = c9x.curves[i].points[j].y;
|
||||
} else {
|
||||
EEPROMWarnings += QObject::tr("Er9x doesn't support curve with %1 point as curve%2 ").arg(c9x.curves[i].count).arg(i+1) + "\n";
|
||||
}
|
||||
for (int i=0; i<ER9X_MAX_CURVE9; i++)
|
||||
if (c9x.curves[i+ER9X_MAX_CURVE5].count==9) {
|
||||
if (c9x.curves[i+ER9X_MAX_CURVE5].custom)
|
||||
EEPROMWarnings += QObject::tr("Er9x doesn't support custom curves as curve%1, curve as been exported as fixed point ").arg(i+1+ER9X_MAX_CURVE5) + "\n";
|
||||
for (int j=0; j<9; j++)
|
||||
curves9[i][j] = c9x.curves[i+ER9X_MAX_CURVE5].points[j].y;
|
||||
} else {
|
||||
EEPROMWarnings += QObject::tr("Er9x doesn't support curve with %1 point as curve%2 ").arg(c9x.curves[i+ER9X_MAX_CURVE5].count).arg(i+1+ER9X_MAX_CURVE5) + "\n";
|
||||
}
|
||||
|
||||
for (int i=0; i<ER9X_NUM_CSW; i++)
|
||||
customSw[i] = c9x.customSw[i];
|
||||
|
||||
for (int i=0; i<ER9X_NUM_CHNOUT; i++)
|
||||
safetySw[i] = c9x.safetySw[i];
|
||||
frsky = c9x.frsky;
|
||||
FrSkyUsrProto = c9x.frsky.usrProto;
|
||||
FrSkyImperial = c9x.frsky.imperial;
|
||||
FrSkyGpsAlt = c9x.frsky.FrSkyGpsAlt;
|
||||
}
|
||||
}
|
||||
|
||||
t_Er9xModelData::operator ModelData ()
|
||||
{
|
||||
ModelData c9x;
|
||||
c9x.used = true;
|
||||
c9x.modelVoice = modelVoice;
|
||||
getEEPROMString(c9x.name, name, sizeof(name));
|
||||
c9x.timers[0].mode = getEr9xTimerMode(tmrMode);
|
||||
c9x.timers[0].dir = tmrDir;
|
||||
c9x.timers[0].val = tmrVal;
|
||||
c9x.timers[0].modeB = tmrModeB;
|
||||
|
||||
switch(protocol) {
|
||||
case 1:
|
||||
c9x.moduleData[0].protocol = PXX_DJT;
|
||||
break;
|
||||
case 2:
|
||||
c9x.moduleData[0].protocol = DSM2;
|
||||
break;
|
||||
case 3:
|
||||
c9x.moduleData[0].protocol = PPM16;
|
||||
break;
|
||||
default:
|
||||
c9x.moduleData[0].protocol = PPM;
|
||||
break;
|
||||
}
|
||||
c9x.traineron= traineron;
|
||||
c9x.t2throttle = t2throttle;
|
||||
c9x.moduleData[0].ppmFrameLength=ppmFrameLength;
|
||||
c9x.moduleData[0].channelsCount = 8 + 2 * ppmNCH;
|
||||
c9x.thrTrim = thrTrim;
|
||||
c9x.thrExpo = thrExpo;
|
||||
c9x.trimInc = trimInc;
|
||||
c9x.moduleData[0].ppmDelay = 300 + 50 * ppmDelay;
|
||||
c9x.funcSw[0].func = FuncInstantTrim;
|
||||
if (trimSw) {
|
||||
c9x.funcSw[0].swtch = er9xToSwitch(trimSw);
|
||||
}
|
||||
c9x.beepANACenter = beepANACenter;
|
||||
c9x.moduleData[0].ppmPulsePol = pulsePol;
|
||||
c9x.extendedLimits = extendedLimits;
|
||||
c9x.swashRingData.invertELE = swashInvertELE;
|
||||
c9x.swashRingData.invertAIL = swashInvertAIL;
|
||||
c9x.swashRingData.invertCOL = swashInvertCOL;
|
||||
c9x.swashRingData.type = swashType;
|
||||
c9x.swashRingData.collectiveSource = er9xToSource(swashCollectiveSource);
|
||||
c9x.swashRingData.value = swashRingValue;
|
||||
|
||||
for (int i=0; i<ER9X_MAX_MIXERS; i++) {
|
||||
Er9xMixData mix = mixData[i];
|
||||
c9x.mixData[i] = mix;
|
||||
}
|
||||
|
||||
for (int i=0; i<ER9X_NUM_CHNOUT; i++)
|
||||
c9x.limitData[i] = limitData[i];
|
||||
|
||||
// expoData
|
||||
int e = 0;
|
||||
for (int ch = 0; ch < 4 && e < C9X_MAX_EXPOS; ch++) {
|
||||
for (int dr = 0, pos = 0; dr < 3 && e < C9X_MAX_EXPOS; dr++, pos++) {
|
||||
if ((dr == 0 && !expoData[ch].drSw1) || (dr == 1 && !expoData[ch].drSw2))
|
||||
dr = 2;
|
||||
if (dr == 2 && !expoData[ch].expo[0][0][0] && !expoData[ch].expo[0][0][1] && !expoData[ch].expo[0][1][0] && !expoData[ch].expo[0][1][1])
|
||||
break;
|
||||
if (expoData[ch].drSw1 && !expoData[ch].drSw2) {
|
||||
c9x.expoData[e].swtch = er9xToSwitch(dr == 0 ? expoData[ch].drSw1 : 0);
|
||||
pos = dr == 0 ? 1 : 0;
|
||||
}
|
||||
else {
|
||||
c9x.expoData[e].swtch = er9xToSwitch(dr == 0 ? -expoData[ch].drSw1 : (dr == 1 ? -expoData[ch].drSw2 : 0));
|
||||
}
|
||||
c9x.expoData[e].chn = ch;
|
||||
c9x.expoData[e].expo = expoData[ch].expo[pos][0][0];
|
||||
c9x.expoData[e].weight = 100 + expoData[ch].expo[pos][1][0];
|
||||
if (expoData[ch].expo[pos][0][0] == expoData[ch].expo[pos][0][1] && expoData[ch].expo[pos][1][0] == expoData[ch].expo[pos][1][1]) {
|
||||
c9x.expoData[e++].mode = 3;
|
||||
}
|
||||
else {
|
||||
c9x.expoData[e].mode = 2;
|
||||
if (e < C9X_MAX_EXPOS - 1) {
|
||||
c9x.expoData[e + 1].swtch = c9x.expoData[e].swtch;
|
||||
c9x.expoData[++e].chn = ch;
|
||||
c9x.expoData[e].mode = 1;
|
||||
c9x.expoData[e].expo = expoData[ch].expo[pos][0][1];
|
||||
c9x.expoData[e++].weight = 100 + expoData[ch].expo[pos][1][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_STICKS; i++)
|
||||
c9x.phaseData[0].trim[i] = trim[i];
|
||||
|
||||
for (int i=0; i<ER9X_MAX_CURVE5; i++) {
|
||||
c9x.curves[i].custom = false;
|
||||
c9x.curves[i].count = 5;
|
||||
for (int j = 0; j < 5; j++) {
|
||||
c9x.curves[i].points[j].x = -100 + 50 * i;
|
||||
c9x.curves[i].points[j].y = curves5[i][j];
|
||||
}
|
||||
}
|
||||
for (int i=0; i<ER9X_MAX_CURVE9; i++) {
|
||||
c9x.curves[ER9X_MAX_CURVE5 + i].custom = false;
|
||||
c9x.curves[ER9X_MAX_CURVE5 + i].count = 9;
|
||||
for (int j = 0; j < 9; j++) {
|
||||
c9x.curves[ER9X_MAX_CURVE5 + i].points[j].x = -100 + 25 * i;
|
||||
c9x.curves[ER9X_MAX_CURVE5 + i].points[j].y = curves9[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<ER9X_NUM_CSW; i++)
|
||||
c9x.customSw[i] = customSw[i];
|
||||
|
||||
for (int i=0; i<ER9X_NUM_CHNOUT; i++)
|
||||
c9x.safetySw[i] = safetySw[i];
|
||||
|
||||
c9x.frsky = frsky;
|
||||
c9x.frsky.usrProto=FrSkyUsrProto;
|
||||
c9x.frsky.imperial=FrSkyImperial;
|
||||
c9x.frsky.FrSkyGpsAlt=FrSkyGpsAlt;
|
||||
return c9x;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
#ifndef er9xeeprom_h
|
||||
#define er9xeeprom_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "eeprominterface.h"
|
||||
|
||||
//eeprom data
|
||||
#define ER9X_MAX_MIXERS 32
|
||||
#define ER9X_MAX_CURVE5 8
|
||||
#define ER9X_MAX_CURVE9 8
|
||||
#define ER9X_MAX_CSFUNC 13
|
||||
|
||||
#define MDVERS 10
|
||||
|
||||
#define ER9X_NUM_CHNOUT 16 //number of real outputchannels CH1-CH8
|
||||
#define ER9X_NUM_CSW 12 //number of custom switches
|
||||
#define NUM_STICKSnPOTS 7 //number of sticks and pots
|
||||
#define ER9X_MAX_GVARS 7
|
||||
|
||||
#define ER9X_MAX_MODES 4
|
||||
|
||||
PACK(typedef struct t_Er9xTrainerMix {
|
||||
uint8_t srcChn:3; //0-7 = ch1-8
|
||||
int8_t swtch:5;
|
||||
int8_t studWeight:6;
|
||||
uint8_t mode:2; // off, add-mode, subst-mode
|
||||
|
||||
operator TrainerMix();
|
||||
t_Er9xTrainerMix();
|
||||
t_Er9xTrainerMix(TrainerMix&);
|
||||
|
||||
}) Er9xTrainerMix; //
|
||||
|
||||
PACK(typedef struct t_Er9xTrainerData {
|
||||
int16_t calib[4];
|
||||
Er9xTrainerMix mix[4];
|
||||
|
||||
operator TrainerData();
|
||||
t_Er9xTrainerData();
|
||||
t_Er9xTrainerData(TrainerData&);
|
||||
|
||||
}) Er9xTrainerData;
|
||||
|
||||
PACK(typedef struct t_Er9xGeneral {
|
||||
uint8_t myVers;
|
||||
int16_t calibMid[NUM_STICKSnPOTS];
|
||||
int16_t calibSpanNeg[NUM_STICKSnPOTS];
|
||||
int16_t calibSpanPos[NUM_STICKSnPOTS];
|
||||
uint16_t chkSum;
|
||||
uint8_t currModel; //0..15
|
||||
uint8_t contrast;
|
||||
uint8_t vBatWarn;
|
||||
int8_t vBatCalib;
|
||||
int8_t lightSw;
|
||||
Er9xTrainerData trainer;
|
||||
uint8_t view;
|
||||
uint8_t disableThrottleWarning:1;
|
||||
uint8_t disableSwitchWarning:1;
|
||||
uint8_t disableMemoryWarning:1;
|
||||
uint8_t beeperVal:3;
|
||||
uint8_t reserveWarning:1;
|
||||
uint8_t disableAlarmWarning:1;
|
||||
uint8_t stickMode;
|
||||
int8_t inactivityTimer;
|
||||
uint8_t throttleReversed:1;
|
||||
uint8_t minuteBeep:1;
|
||||
uint8_t preBeep:1;
|
||||
uint8_t flashBeep:1;
|
||||
uint8_t disableSplashScreen:1;
|
||||
uint8_t disablePotScroll:1;
|
||||
uint8_t disableBG:1;
|
||||
uint8_t frskyinternalalarm:1;
|
||||
uint8_t spare_filter ; // No longer needed, left for eepe compatibility for now
|
||||
uint8_t lightAutoOff;
|
||||
uint8_t templateSetup; //RETA order according to chout_ar array
|
||||
int8_t PPM_Multiplier;
|
||||
uint8_t unused1;
|
||||
uint8_t unused2:4;
|
||||
uint8_t hideNameOnSplash:1;
|
||||
uint8_t enablePpmsim:1;
|
||||
uint8_t blightinv:1;
|
||||
uint8_t stickScroll:1;
|
||||
uint8_t speakerPitch;
|
||||
uint8_t hapticStrength;
|
||||
uint8_t speakerMode;
|
||||
uint8_t lightOnStickMove;
|
||||
|
||||
char ownerName[10];
|
||||
uint8_t switchWarningStates;
|
||||
uint8_t volume ;
|
||||
uint8_t res[3];
|
||||
uint8_t crosstrim:1;
|
||||
uint8_t spare1:7;
|
||||
|
||||
operator GeneralSettings();
|
||||
t_Er9xGeneral();
|
||||
t_Er9xGeneral(GeneralSettings&);
|
||||
|
||||
}) Er9xGeneral;
|
||||
|
||||
PACK(typedef struct t_Er9xExpoData {
|
||||
int8_t expo[3][2][2];
|
||||
int8_t drSw1;
|
||||
int8_t drSw2;
|
||||
|
||||
t_Er9xExpoData() { memset(this, 0, sizeof(t_Er9xExpoData)); }
|
||||
}) Er9xExpoData;
|
||||
|
||||
|
||||
PACK(typedef struct t_Er9xLimitData {
|
||||
int8_t min;
|
||||
int8_t max;
|
||||
bool revert;
|
||||
int16_t offset;
|
||||
|
||||
operator LimitData();
|
||||
t_Er9xLimitData();
|
||||
t_Er9xLimitData(LimitData&);
|
||||
}) Er9xLimitData;
|
||||
|
||||
#define MLTPX_ADD 0
|
||||
#define MLTPX_MUL 1
|
||||
#define MLTPX_REP 2
|
||||
|
||||
PACK(typedef struct t_Er9xMixData {
|
||||
uint8_t destCh; // 1..C9X_NUM_CHNOUT
|
||||
uint8_t srcRaw; //
|
||||
int8_t weight;
|
||||
int8_t swtch;
|
||||
uint8_t curve; //0=symmetrisch 1=no neg 2=no pos
|
||||
uint8_t delayUp:4;
|
||||
uint8_t delayDown:4;
|
||||
uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle)
|
||||
uint8_t speedDown:4; // 0 nichts
|
||||
uint8_t carryTrim:1;
|
||||
uint8_t mltpx:2; // multiplex method 0=+ 1=* 2=replace
|
||||
uint8_t lateOffset:1; // Add offset later
|
||||
uint8_t mixWarn:2; // mixer warning
|
||||
uint8_t enableFmTrim:1;
|
||||
uint8_t differential:1;
|
||||
int8_t sOffset;
|
||||
int8_t res;
|
||||
|
||||
operator MixData();
|
||||
t_Er9xMixData();
|
||||
t_Er9xMixData(MixData&);
|
||||
}) Er9xMixData;
|
||||
|
||||
|
||||
PACK(typedef struct t_Er9xCustomSwData { // Custom Switches data
|
||||
int8_t v1; //input
|
||||
int8_t v2; //offset
|
||||
uint8_t func:4;
|
||||
uint8_t andsw:4;
|
||||
|
||||
operator CustomSwData();
|
||||
t_Er9xCustomSwData() { memset(this, 0, sizeof(t_Er9xCustomSwData)); }
|
||||
t_Er9xCustomSwData(CustomSwData&);
|
||||
}) Er9xCustomSwData;
|
||||
|
||||
PACK(typedef struct t_Er9xSafetySwData { // Custom Switches data
|
||||
int8_t swtch;
|
||||
int8_t val;
|
||||
|
||||
operator SafetySwData();
|
||||
t_Er9xSafetySwData();
|
||||
t_Er9xSafetySwData(SafetySwData&);
|
||||
}) Er9xSafetySwData;
|
||||
|
||||
PACK(typedef struct t_Er9xFrSkyChannelData {
|
||||
uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
|
||||
uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc.
|
||||
uint8_t alarms_level:4;
|
||||
uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>)
|
||||
uint8_t type:2; // future use: 0=volts, ...
|
||||
|
||||
operator FrSkyChannelData();
|
||||
t_Er9xFrSkyChannelData();
|
||||
t_Er9xFrSkyChannelData(FrSkyChannelData&);
|
||||
}) Er9xFrSkyChannelData;
|
||||
|
||||
PACK(typedef struct t_Er9xFrSkyData {
|
||||
Er9xFrSkyChannelData channels[2];
|
||||
|
||||
operator FrSkyData();
|
||||
t_Er9xFrSkyData();
|
||||
t_Er9xFrSkyData(FrSkyData&);
|
||||
}) Er9xFrSkyData;
|
||||
|
||||
PACK(typedef struct t_gvar {
|
||||
int8_t gvar ;
|
||||
uint8_t gvsource ;
|
||||
// int8_t gvswitch ;
|
||||
}) Er9xGvarData ;
|
||||
|
||||
PACK(typedef struct t_PhaseData {
|
||||
// Trim store as -1001 to -1, trim value-501, 0-5 use trim of phase 0-5
|
||||
int16_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of modes 1|2|3|4 instead
|
||||
int8_t swtch; // Try 0-5 use trim of phase 0-5, 1000-2000, trim + 1500 ???
|
||||
uint8_t fadeIn:4;
|
||||
uint8_t fadeOut:4;
|
||||
}) Er9xPhaseData;
|
||||
|
||||
PACK(typedef struct t_Er9xModelData {
|
||||
char name[10]; // 10 must be first for eeLoadModelName
|
||||
uint8_t modelVoice ; // Index to model name voice (260+value)
|
||||
int8_t tmrMode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
|
||||
uint8_t tmrDir:1; //0=>Count Down, 1=>Count Up
|
||||
uint8_t traineron:1; // 0 disable trainer, 1 allow trainer
|
||||
uint8_t t2throttle:1 ; // Start timer2 using throttle
|
||||
uint8_t FrSkyUsrProto:1 ; // Protocol in FrSky User Data, 0=FrSky Hub, 1=WS HowHigh
|
||||
uint8_t FrSkyGpsAlt:1 ; // Use Gps Altitude as main altitude reading
|
||||
uint8_t FrSkyImperial:1 ; // Convert FrSky values to imperial units
|
||||
uint8_t FrSkyAltAlarm:2;
|
||||
uint16_t tmrVal;
|
||||
uint8_t protocol;
|
||||
int8_t ppmNCH;
|
||||
uint8_t thrTrim:1; // Enable Throttle Trim
|
||||
uint8_t xnumBlades:2; // RPM scaling
|
||||
uint8_t spare10:1;
|
||||
uint8_t thrExpo:1; // Enable Throttle Expo
|
||||
uint8_t ppmStart:3 ; // Start channel for PPM
|
||||
int8_t trimInc; // Trim Increments
|
||||
int8_t ppmDelay;
|
||||
int8_t trimSw;
|
||||
uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7
|
||||
uint8_t pulsePol:1;
|
||||
uint8_t extendedLimits:1;
|
||||
uint8_t swashInvertELE:1;
|
||||
uint8_t swashInvertAIL:1;
|
||||
uint8_t swashInvertCOL:1;
|
||||
uint8_t swashType:3;
|
||||
uint8_t swashCollectiveSource;
|
||||
uint8_t swashRingValue;
|
||||
int8_t ppmFrameLength;
|
||||
Er9xMixData mixData[ER9X_MAX_MIXERS];
|
||||
Er9xLimitData limitData[ER9X_NUM_CHNOUT];
|
||||
Er9xExpoData expoData[4];
|
||||
int8_t trim[4];
|
||||
int8_t curves5[ER9X_MAX_CURVE5][5];
|
||||
int8_t curves9[ER9X_MAX_CURVE9][9];
|
||||
Er9xCustomSwData customSw[ER9X_NUM_CSW];
|
||||
uint8_t frSkyVoltThreshold ;
|
||||
int8_t tmrModeB;
|
||||
uint8_t numVoice;
|
||||
Er9xSafetySwData safetySw[ER9X_NUM_CHNOUT];
|
||||
Er9xFrSkyData frsky;
|
||||
uint8_t numBlades ;
|
||||
uint8_t unused1[8] ;
|
||||
uint8_t CustomDisplayIndex[6] ;
|
||||
Er9xGvarData gvars[ER9X_MAX_GVARS] ;
|
||||
Er9xPhaseData phaseData[ER9X_MAX_MODES] ;
|
||||
|
||||
operator ModelData();
|
||||
t_Er9xModelData() { memset(this, 0, sizeof(t_Er9xModelData)); }
|
||||
t_Er9xModelData(ModelData&);
|
||||
}) Er9xModelData;
|
||||
|
||||
|
||||
#endif
|
||||
/*eof*/
|
||||
@@ -0,0 +1,474 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "er9xinterface.h"
|
||||
#include "er9xeeprom.h"
|
||||
#include "er9xsimulator.h"
|
||||
#include "file.h"
|
||||
|
||||
#define FILE_TYP_GENERAL 1
|
||||
#define FILE_TYP_MODEL 2
|
||||
|
||||
#define FILE_GENERAL 0
|
||||
#define FILE_MODEL(n) (1+n)
|
||||
|
||||
Er9xInterface::Er9xInterface():
|
||||
EEPROMInterface(BOARD_STOCK),
|
||||
efile(new EFile())
|
||||
{
|
||||
}
|
||||
|
||||
Er9xInterface::~Er9xInterface()
|
||||
{
|
||||
delete efile;
|
||||
}
|
||||
|
||||
const char * Er9xInterface::getName()
|
||||
{
|
||||
return "Er9x";
|
||||
}
|
||||
|
||||
const int Er9xInterface::getEEpromSize()
|
||||
{
|
||||
QSettings settings("companion9x", "companion9x");
|
||||
QString avrMCU = settings.value("mcu", QString("m64")).toString();
|
||||
if (avrMCU==QString("m128")) {
|
||||
return 2*EESIZE_STOCK;
|
||||
}
|
||||
return EESIZE_STOCK;
|
||||
}
|
||||
|
||||
const int Er9xInterface::getMaxModels()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
inline void applyStickModeToModel(Er9xModelData & model, unsigned int mode)
|
||||
{
|
||||
for (int i=0; i<2; i++) {
|
||||
int stick = applyStickMode(i+1, mode) - 1;
|
||||
{
|
||||
int tmp = model.trim[i];
|
||||
model.trim[i] = model.trim[stick];
|
||||
model.trim[stick] = tmp;
|
||||
}
|
||||
{
|
||||
Er9xExpoData tmp = model.expoData[i];
|
||||
model.expoData[i] = model.expoData[stick];
|
||||
model.expoData[stick] = tmp;
|
||||
}
|
||||
}
|
||||
for (int i=0; i<ER9X_MAX_MIXERS; i++)
|
||||
model.mixData[i].srcRaw = applyStickMode(model.mixData[i].srcRaw, mode);
|
||||
for (int i=0; i<ER9X_NUM_CSW; i++) {
|
||||
switch (getCSFunctionFamily(model.customSw[i].func)) {
|
||||
case CS_FAMILY_VCOMP:
|
||||
model.customSw[i].v2 = applyStickMode(model.customSw[i].v2, mode);
|
||||
// no break
|
||||
case CS_FAMILY_VOFS:
|
||||
model.customSw[i].v1 = applyStickMode(model.customSw[i].v1, mode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
model.swashCollectiveSource = applyStickMode(model.swashCollectiveSource, mode);
|
||||
}
|
||||
|
||||
bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
||||
{
|
||||
std::cout << "trying er9x xml import... ";
|
||||
|
||||
Er9xGeneral er9xGeneral;
|
||||
memset(&er9xGeneral,0,sizeof(er9xGeneral));
|
||||
if(!loadGeneralDataXML(&doc, &er9xGeneral)) {
|
||||
return false;
|
||||
} else {
|
||||
radioData.generalSettings=er9xGeneral;
|
||||
std::cout << "version " << (unsigned int)er9xGeneral.myVers << " ";
|
||||
}
|
||||
for(int i=0; i<getMaxModels(); i++)
|
||||
{
|
||||
Er9xModelData er9xModel;
|
||||
memset(&er9xModel,0,sizeof(er9xModel));
|
||||
if(loadModelDataXML(&doc, &er9xModel, i)) {
|
||||
applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1);
|
||||
radioData.models[i] = er9xModel;
|
||||
}
|
||||
}
|
||||
std::cout << "ok\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Er9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying er9x import... ";
|
||||
|
||||
if (size != getEEpromSize()) {
|
||||
std::cout << "wrong size\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, BOARD_STOCK)) {
|
||||
std::cout << "wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
efile->openRd(FILE_GENERAL);
|
||||
Er9xGeneral er9xGeneral;
|
||||
|
||||
if (efile->readRlc1((uint8_t*)&er9xGeneral, 1) != 1) {
|
||||
std::cout << "no\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "version " << (unsigned int)er9xGeneral.myVers << " ";
|
||||
|
||||
switch(er9xGeneral.myVers) {
|
||||
case 3:
|
||||
std::cout << "(old gruvin9x) ";
|
||||
case 4:
|
||||
// case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
break;
|
||||
default:
|
||||
std::cout << "not er9x\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
efile->openRd(FILE_GENERAL);
|
||||
if (!efile->readRlc1((uint8_t*)&er9xGeneral, sizeof(Er9xGeneral))) {
|
||||
std::cout << "ko\n";
|
||||
return false;
|
||||
}
|
||||
radioData.generalSettings = er9xGeneral;
|
||||
|
||||
for (int i=0; i<getMaxModels(); i++) {
|
||||
Er9xModelData er9xModel;
|
||||
efile->openRd(FILE_MODEL(i));
|
||||
if (!efile->readRlc1((uint8_t*)&er9xModel, sizeof(Er9xModelData))) {
|
||||
radioData.models[i].clear();
|
||||
}
|
||||
else {
|
||||
applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1);
|
||||
radioData.models[i] = er9xModel;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "ok\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Er9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int Er9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)
|
||||
{
|
||||
EEPROMWarnings.clear();
|
||||
|
||||
efile->EeFsCreate(eeprom, getEEpromSize(), BOARD_STOCK);
|
||||
|
||||
Er9xGeneral er9xGeneral(radioData.generalSettings);
|
||||
int sz = efile->writeRlc1(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&er9xGeneral, sizeof(Er9xGeneral));
|
||||
if(sz != sizeof(Er9xGeneral)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i=0; i<getMaxModels(); i++) {
|
||||
if (!radioData.models[i].isempty()) {
|
||||
Er9xModelData er9xModel(radioData.models[i]);
|
||||
applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1);
|
||||
sz = efile->writeRlc1(FILE_MODEL(i), FILE_TYP_MODEL, (uint8_t*)&er9xModel, sizeof(Er9xModelData));
|
||||
if(sz != sizeof(Er9xModelData)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getEEpromSize();
|
||||
}
|
||||
|
||||
int Er9xInterface::getSize(ModelData &model)
|
||||
{
|
||||
if (model.isempty())
|
||||
return 0;
|
||||
|
||||
uint8_t tmp[2*EESIZE_STOCK];
|
||||
efile->EeFsCreate(tmp, getEEpromSize(), BOARD_STOCK);
|
||||
|
||||
Er9xModelData er9xModel(model);
|
||||
int sz = efile->writeRlc1(0, FILE_TYP_MODEL, (uint8_t*)&er9xModel, sizeof(Er9xModelData));
|
||||
if(sz != sizeof(Er9xModelData)) {
|
||||
return -1;
|
||||
}
|
||||
return efile->size(0);
|
||||
}
|
||||
|
||||
int Er9xInterface::getSize(GeneralSettings &settings)
|
||||
{
|
||||
uint8_t tmp[2*EESIZE_STOCK];
|
||||
efile->EeFsCreate(tmp, getEEpromSize(), BOARD_STOCK);
|
||||
|
||||
Er9xGeneral er9xGeneral(settings);
|
||||
int sz = efile->writeRlc1(0, FILE_TYP_GENERAL, (uint8_t*)&er9xGeneral, sizeof(Er9xGeneral));
|
||||
if(sz != sizeof(Er9xGeneral)) {
|
||||
return -1;
|
||||
}
|
||||
return efile->size(0);
|
||||
}
|
||||
|
||||
int Er9xInterface::getCapability(const Capability capability)
|
||||
{
|
||||
switch (capability) {
|
||||
case FlightPhases:
|
||||
return 4;
|
||||
case Mixes:
|
||||
return ER9X_MAX_MIXERS;
|
||||
case NumCurves5:
|
||||
return ER9X_MAX_CURVE5;
|
||||
case NumCurves9:
|
||||
return ER9X_MAX_CURVE5;
|
||||
case MixFmTrim:
|
||||
return 1;
|
||||
case PPMExtCtrl:
|
||||
return 1;
|
||||
case ModelTrainerEnable:
|
||||
return 1;
|
||||
case Timer2ThrTrig:
|
||||
return 1;
|
||||
case TrainerSwitch:
|
||||
return 1;
|
||||
case OffsetWeight:
|
||||
return 125;
|
||||
case BandgapMeasure:
|
||||
return 1;
|
||||
case PotScrolling:
|
||||
return 1;
|
||||
case SoundMod:
|
||||
return 1;
|
||||
case SoundPitch:
|
||||
return 1;
|
||||
case Haptic:
|
||||
return 1;
|
||||
case OwnerName:
|
||||
return 10;
|
||||
case Timers:
|
||||
return 1;
|
||||
case Pots:
|
||||
return 3;
|
||||
case Switches:
|
||||
return 7;
|
||||
case SwitchesPositions:
|
||||
return 9;
|
||||
case CustomFunctions:
|
||||
return 0;
|
||||
case CustomSwitches:
|
||||
return 12;
|
||||
case CustomAndSwitches:
|
||||
return 5;
|
||||
case GvarsNum:
|
||||
return 7;
|
||||
case GvarsOfsNum:
|
||||
return 5;
|
||||
case CSFunc:
|
||||
return 13;
|
||||
case Outputs:
|
||||
return 16;
|
||||
case ExtraChannels:
|
||||
return 0;
|
||||
case Simulation:
|
||||
return 1;
|
||||
case gsSwitchMask:
|
||||
return 1;
|
||||
case BLonStickMove:
|
||||
return 1;
|
||||
case Telemetry:
|
||||
return TM_HASTELEMETRY|TM_HASWSHH;
|
||||
case TelemetryUnits:
|
||||
return 1;
|
||||
case TimerTriggerB:
|
||||
return 1;
|
||||
case TelemetryMaxMultiplier:
|
||||
return 2;
|
||||
case MaxVolume:
|
||||
return 7;
|
||||
case SlowScale:
|
||||
return 1;
|
||||
case SlowRange:
|
||||
return 15;
|
||||
case LCDWidth:
|
||||
return 128;
|
||||
case VoicesAsNumbers:
|
||||
case TelemetryInternalAlarm:
|
||||
case HasPPMSim:
|
||||
case HasCrossTrims:
|
||||
case HasStickScroll:
|
||||
case HasAltitudeSel:
|
||||
case HasContrast:
|
||||
case InstantTrimSW:
|
||||
case HasVolume:
|
||||
case HasBlInvert:
|
||||
case ModelVoice:
|
||||
case DiffMixers:
|
||||
case HasNegCurves:
|
||||
case HasFixOffset:
|
||||
case Gvars:
|
||||
case GvarsHaveSources:
|
||||
case GvarsAsSources:
|
||||
case GvarsAsWeight:
|
||||
return 1;
|
||||
case GetThrSwitch:
|
||||
return DSW_THR;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Er9xInterface::isAvailable(Protocol prot, int port)
|
||||
{
|
||||
switch (prot) {
|
||||
case PPM:
|
||||
case DSM2:
|
||||
case PXX_DJT:
|
||||
case PPM16:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SimulatorInterface * Er9xInterface::getSimulator()
|
||||
{
|
||||
return new Er9xSimulator(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Er9xInterface::appendTextElement(QDomDocument * qdoc, QDomElement * pe, QString name, QString value)
|
||||
{
|
||||
QDomElement e = qdoc->createElement(name);
|
||||
QDomText t = qdoc->createTextNode(name);
|
||||
t.setNodeValue(value);
|
||||
e.appendChild(t);
|
||||
pe->appendChild(e);
|
||||
}
|
||||
|
||||
void Er9xInterface::appendNumberElement(QDomDocument * qdoc, QDomElement * pe,QString name, int value, bool forceZeroWrite)
|
||||
{
|
||||
if(value || forceZeroWrite) {
|
||||
QDomElement e = qdoc->createElement(name);
|
||||
QDomText t = qdoc->createTextNode(name);
|
||||
t.setNodeValue(QString("%1").arg(value));
|
||||
e.appendChild(t);
|
||||
pe->appendChild(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Er9xInterface::appendCDATAElement(QDomDocument * qdoc, QDomElement * pe,QString name, const char * data, int size)
|
||||
{
|
||||
QDomElement e = qdoc->createElement(name);
|
||||
QDomCDATASection t = qdoc->createCDATASection(name);
|
||||
t.setData(QByteArray(data, size).toBase64());
|
||||
e.appendChild(t);
|
||||
pe->appendChild(e);
|
||||
}
|
||||
|
||||
QDomElement Er9xInterface::getGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen)
|
||||
{
|
||||
QDomElement gd = qdoc->createElement("GENERAL_DATA");
|
||||
appendNumberElement(qdoc, &gd, "Version", tgen->myVers, true); // have to write value here
|
||||
appendTextElement(qdoc, &gd, "Owner", QString::fromAscii(tgen->ownerName,sizeof(tgen->ownerName)).trimmed());
|
||||
appendCDATAElement(qdoc, &gd, "Data", (const char *)tgen,sizeof(Er9xGeneral));
|
||||
return gd;
|
||||
}
|
||||
|
||||
QDomElement Er9xInterface::getModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum, int mdver)
|
||||
{
|
||||
QDomElement md = qdoc->createElement("MODEL_DATA");
|
||||
md.setAttribute("number", modelNum);
|
||||
appendNumberElement(qdoc, &md, "Version", mdver, true); // have to write value here
|
||||
appendTextElement(qdoc, &md, "Name", QString::fromAscii(tmod->name,sizeof(tmod->name)).trimmed());
|
||||
appendCDATAElement(qdoc, &md, "Data", (const char *)tmod,sizeof(Er9xModelData));
|
||||
return md;
|
||||
}
|
||||
|
||||
bool Er9xInterface::loadGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen)
|
||||
{
|
||||
//look for "GENERAL_DATA" tag
|
||||
QDomElement gde = qdoc->elementsByTagName("GENERAL_DATA").at(0).toElement();
|
||||
|
||||
if(gde.isNull()) // couldn't find
|
||||
return false;
|
||||
|
||||
//load cdata into tgen
|
||||
QDomNode n = gde.elementsByTagName("Data").at(0).firstChild();// get all children in Data
|
||||
while (!n.isNull()) {
|
||||
if (n.isCDATASection()) {
|
||||
QString ds = n.toCDATASection().data();
|
||||
QByteArray ba = QByteArray::fromBase64(ds.toAscii());
|
||||
const char * data = ba.data();
|
||||
memcpy(tgen, data, sizeof(Er9xGeneral));
|
||||
break;
|
||||
}
|
||||
n = n.nextSibling();
|
||||
}
|
||||
//check version?
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Er9xInterface::loadModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum)
|
||||
{
|
||||
//look for MODEL_DATA with modelNum attribute.
|
||||
//if modelNum = -1 then just pick the first one
|
||||
QDomNodeList ndl = qdoc->elementsByTagName("MODEL_DATA");
|
||||
|
||||
//cycle through nodes to find correct model number
|
||||
QDomNode k = ndl.at(0);
|
||||
if(modelNum>=0) {
|
||||
while(!k.isNull()) {
|
||||
int a = k.toElement().attribute("number").toInt();
|
||||
if(a==modelNum)
|
||||
break;
|
||||
k = k.nextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
if(k.isNull()) // couldn't find
|
||||
return false;
|
||||
|
||||
|
||||
//load cdata into tgen
|
||||
QDomNode n = k.toElement().elementsByTagName("Data").at(0).firstChild();// get all children in Data
|
||||
while (!n.isNull()) {
|
||||
if (n.isCDATASection()) {
|
||||
QString ds = n.toCDATASection().data();
|
||||
QByteArray ba = QByteArray::fromBase64(ds.toAscii());
|
||||
const char * data = ba.data();
|
||||
memcpy(tmod, data, sizeof(Er9xModelData));
|
||||
break;
|
||||
}
|
||||
n = n.nextSibling();
|
||||
}
|
||||
//check version?
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
#ifndef er9x_interface_h
|
||||
#define er9x_interface_h
|
||||
#include <QtXml>
|
||||
#include "eeprominterface.h"
|
||||
#include "er9xeeprom.h"
|
||||
class EFile;
|
||||
|
||||
class Er9xInterface : public EEPROMInterface
|
||||
{
|
||||
public:
|
||||
|
||||
Er9xInterface();
|
||||
|
||||
virtual ~Er9xInterface();
|
||||
|
||||
virtual const char * getName();
|
||||
|
||||
virtual const int getEEpromSize();
|
||||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t * eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t * eeprom, int esize, int index);
|
||||
|
||||
virtual bool loadxml(RadioData &radioData, QDomDocument &doc);
|
||||
|
||||
virtual int save(uint8_t * eeprom, RadioData & radioData, uint32_t variant=0, uint8_t version=0);
|
||||
|
||||
virtual int getSize(ModelData &);
|
||||
|
||||
virtual int getSize(GeneralSettings &settings);
|
||||
|
||||
virtual int getCapability(const Capability);
|
||||
|
||||
virtual int isAvailable(Protocol proto, int port=0);
|
||||
|
||||
virtual SimulatorInterface * getSimulator();
|
||||
|
||||
protected:
|
||||
|
||||
EFile *efile;
|
||||
|
||||
private:
|
||||
void appendTextElement(QDomDocument * qdoc, QDomElement * pe, QString name, QString value);
|
||||
|
||||
void appendNumberElement(QDomDocument * qdoc, QDomElement * pe,QString name, int value, bool forceZeroWrite = false);
|
||||
|
||||
void appendCDATAElement(QDomDocument * qdoc, QDomElement * pe,QString name, const char * data, int size);
|
||||
|
||||
QDomElement getGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen); //parse out data to XML format
|
||||
|
||||
QDomElement getModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum, int mdver); //parse out data to XML format
|
||||
|
||||
bool loadGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen); // get data from XML
|
||||
|
||||
bool loadModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum = -1); // get data from XML
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "firmwares/er9x/er9xsimulator.h"
|
||||
#include "firmwares/er9x/er9xinterface.h"
|
||||
|
||||
#define SIMU
|
||||
#define SIMU_EXCEPTIONS
|
||||
#define FRSKY
|
||||
#define PHASES
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#define NUM_POTS 3
|
||||
#define SWSRC_SW1 DSW_SW1
|
||||
|
||||
#ifndef __GNUC__
|
||||
#include "../winbuild/winbuild.h"
|
||||
#endif
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace Er9x {
|
||||
|
||||
#include "simpgmspace.h"
|
||||
#include "er9x.cpp"
|
||||
#include "stamp.cpp"
|
||||
#include "menus.cpp"
|
||||
#include "pers.cpp"
|
||||
#include "file.cpp"
|
||||
#include "lcd.cpp"
|
||||
#include "drivers.cpp"
|
||||
#include "simpgmspace.cpp"
|
||||
#include "templates.cpp"
|
||||
#include "frsky.cpp"
|
||||
#include "audio.cpp"
|
||||
|
||||
uint8_t pxxFlag = 0;
|
||||
int16_t g_anas[7];
|
||||
|
||||
#define IS_BACKLIGHT_ON() (PORTB & (1<<OUT_B_LIGHT))
|
||||
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
{
|
||||
if (chan == 7)
|
||||
return 1500;
|
||||
else
|
||||
return g_anas[chan];
|
||||
}
|
||||
|
||||
bool hasExtendedTrims()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void setTrim(uint8_t idx, int8_t value)
|
||||
{
|
||||
g_model.trim[idx] = value;
|
||||
}
|
||||
|
||||
void getTrims(int16_t values[4])
|
||||
{
|
||||
for (int i=0; i<4; i++)
|
||||
values[i] = g_model.trim[i];
|
||||
}
|
||||
|
||||
#define GPIO_TRIM_LH_L pind
|
||||
#define GPIO_TRIM_LV_DN pind
|
||||
#define GPIO_TRIM_RV_UP pind
|
||||
#define GPIO_TRIM_RH_L pind
|
||||
#define GPIO_TRIM_LH_R pind
|
||||
#define GPIO_TRIM_LV_UP pind
|
||||
#define GPIO_TRIM_RV_DN pind
|
||||
#define GPIO_TRIM_RH_R pind
|
||||
#define PIN_TRIM_LH_L (1<<INP_D_TRM_LH_DWN)
|
||||
#define PIN_TRIM_LV_DN (1<<INP_D_TRM_LV_DWN)
|
||||
#define PIN_TRIM_RV_UP (1<<INP_D_TRM_RV_UP)
|
||||
#define PIN_TRIM_RH_L (1<<INP_D_TRM_RH_DWN)
|
||||
#define PIN_TRIM_LH_R (1<<INP_D_TRM_LH_UP)
|
||||
#define PIN_TRIM_LV_UP (1<<INP_D_TRM_LV_UP)
|
||||
#define PIN_TRIM_RV_DN (1<<INP_D_TRM_RV_DWN)
|
||||
#define PIN_TRIM_RH_R (1<<INP_D_TRM_RH_UP)
|
||||
|
||||
#define TRIM_CASE(key, pin, mask) \
|
||||
case key: \
|
||||
if (state) pin |= mask; else pin &= ~mask;\
|
||||
break;
|
||||
|
||||
void simuSetTrim(uint8_t trim, bool state)
|
||||
{
|
||||
switch (trim) {
|
||||
TRIM_CASE(0, GPIO_TRIM_LH_L, PIN_TRIM_LH_L)
|
||||
TRIM_CASE(1, GPIO_TRIM_LH_R, PIN_TRIM_LH_R)
|
||||
TRIM_CASE(2, GPIO_TRIM_LV_DN, PIN_TRIM_LV_DN)
|
||||
TRIM_CASE(3, GPIO_TRIM_LV_UP, PIN_TRIM_LV_UP)
|
||||
TRIM_CASE(4, GPIO_TRIM_RV_DN, PIN_TRIM_RV_DN)
|
||||
TRIM_CASE(5, GPIO_TRIM_RV_UP, PIN_TRIM_RV_UP)
|
||||
TRIM_CASE(6, GPIO_TRIM_RH_L, PIN_TRIM_RH_L)
|
||||
TRIM_CASE(7, GPIO_TRIM_RH_R, PIN_TRIM_RH_R)
|
||||
}
|
||||
}
|
||||
|
||||
#define SWITCH_CASE(swtch, pin, mask) \
|
||||
case swtch: \
|
||||
if (state) pin &= ~(mask); else pin |= (mask); \
|
||||
break;
|
||||
#define SWITCH_3_CASE(swtch, pin1, pin2, mask1, mask2) \
|
||||
case swtch: \
|
||||
if (state >= 0) pin1 &= ~(mask1); else pin1 |= (mask1); \
|
||||
if (state <= 0) pin2 &= ~(mask2); else pin2 |= (mask2); \
|
||||
break;
|
||||
|
||||
void simuSetSwitch(uint8_t swtch, int8_t state)
|
||||
{
|
||||
switch (swtch) {
|
||||
SWITCH_CASE(0, pinc, 1<<INP_C_ThrCt)
|
||||
SWITCH_CASE(4, pinc, 1<<INP_C_AileDR)
|
||||
SWITCH_3_CASE(3, ping, pine, (1<<INP_G_ID1), (1<<INP_E_ID2))
|
||||
SWITCH_CASE(1, ping, 1<<INP_G_RuddDR)
|
||||
SWITCH_CASE(2, pine, 1<<INP_E_ElevDR)
|
||||
SWITCH_CASE(5, pine, 1<<INP_E_Gear)
|
||||
SWITCH_CASE(6, pine, 1<<INP_E_Trainer)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define KEY_CASE(key, pin, mask) \
|
||||
case key: \
|
||||
if (state) pin |= mask; else pin &= ~mask;\
|
||||
break;
|
||||
|
||||
void simuSetKey(uint8_t key, bool state)
|
||||
{
|
||||
switch (key) {
|
||||
KEY_CASE(KEY_MENU, pinb, (1<<INP_B_KEY_MEN))
|
||||
KEY_CASE(KEY_EXIT, pinb, (1<<INP_B_KEY_EXT))
|
||||
KEY_CASE(KEY_RIGHT, pinb, (1<<INP_B_KEY_RGT))
|
||||
KEY_CASE(KEY_LEFT, pinb, (1<<INP_B_KEY_LFT))
|
||||
KEY_CASE(KEY_UP, pinb, (1<<INP_B_KEY_UP))
|
||||
KEY_CASE(KEY_DOWN, pinb, (1<<INP_B_KEY_DWN))
|
||||
}
|
||||
}
|
||||
|
||||
#define IS_BACKLIGHT_ON() (PORTB & (1<<OUT_B_LIGHT))
|
||||
|
||||
}
|
||||
|
||||
using namespace Er9x;
|
||||
|
||||
Er9xSimulator::Er9xSimulator(Er9xInterface * er9xInterface):
|
||||
er9xInterface(er9xInterface)
|
||||
{
|
||||
}
|
||||
|
||||
bool Er9xSimulator::timer10ms()
|
||||
{
|
||||
AUDIO_DRIVER(); // the tone generator
|
||||
AUDIO_HEARTBEAT(); // the queue processing
|
||||
#define TIMER10MS_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
uint8_t * Er9xSimulator::getLcd()
|
||||
{
|
||||
#define GETLCD_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
bool Er9xSimulator::lcdChanged(bool & lightEnable)
|
||||
{
|
||||
#define LCDCHANGED_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
void Er9xSimulator::start(RadioData &radioData, bool tests)
|
||||
{
|
||||
er9xInterface->save(&eeprom[0], radioData);
|
||||
StartMainThread(tests);
|
||||
}
|
||||
|
||||
void Er9xSimulator::stop()
|
||||
{
|
||||
StopMainThread();
|
||||
}
|
||||
|
||||
void Er9xSimulator::getValues(TxOutputs &outputs)
|
||||
{
|
||||
#define GETVALUES_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
outputs.beep = audio.busy();
|
||||
}
|
||||
|
||||
void Er9xSimulator::setValues(TxInputs &inputs)
|
||||
{
|
||||
#define SETVALUES_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
void Er9xSimulator::setTrim(unsigned int idx, int value)
|
||||
{
|
||||
Er9x::setTrim(idx, value);
|
||||
}
|
||||
|
||||
void Er9xSimulator::getTrims(Trims & trims)
|
||||
{
|
||||
trims.extended = false;
|
||||
Er9x::getTrims(trims.values);
|
||||
}
|
||||
|
||||
const char * Er9xSimulator::getError()
|
||||
{
|
||||
#define GETERROR_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author - Bertrand Songis <bsongis@gmail.com>
|
||||
*
|
||||
* Based on th9x -> http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef er9x_simulator_h
|
||||
#define er9x_simulator_h
|
||||
|
||||
#include "simulatorinterface.h"
|
||||
|
||||
class RadioData;
|
||||
class Er9xInterface;
|
||||
|
||||
class Er9xSimulator : public SimulatorInterface {
|
||||
|
||||
public:
|
||||
|
||||
Er9xSimulator(Er9xInterface *);
|
||||
|
||||
virtual void start(RadioData & radioData, bool tests);
|
||||
|
||||
virtual void stop();
|
||||
|
||||
virtual bool timer10ms();
|
||||
|
||||
virtual uint8_t * getLcd();
|
||||
|
||||
virtual bool lcdChanged(bool & lightEnable);
|
||||
|
||||
virtual void setValues(TxInputs &inputs);
|
||||
|
||||
virtual void getValues(TxOutputs &outputs);
|
||||
|
||||
virtual void setTrim(unsigned int idx, int value);
|
||||
|
||||
virtual void getTrims(Trims & trims);
|
||||
|
||||
virtual unsigned int getPhase() { return 0; }
|
||||
|
||||
virtual void wheelEvent(uint8_t steps) { }
|
||||
|
||||
virtual const char * getError();
|
||||
|
||||
protected:
|
||||
|
||||
Er9xInterface * er9xInterface;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user