#include #include "helpers.h" #include "th9xeeprom.h" int8_t th9xFromSwitch(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); default: return 0; } } RawSwitch th9xToSwitch(int8_t sw) { if (sw == 0) return RawSwitch(SWITCH_TYPE_NONE); else if (sw <= 9) return RawSwitch(SWITCH_TYPE_SWITCH, sw); else return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9); } t_Th9xTrainerMix::t_Th9xTrainerMix() { memset(this, 0, sizeof(t_Th9xTrainerMix)); } t_Th9xTrainerMix::operator TrainerMix() { TrainerMix c9x; c9x.src = srcChn; c9x.swtch = th9xToSwitch(swtch); c9x.weight = (25 * studWeight) / 8; c9x.mode = mode; return c9x; } t_Th9xTrainerData::t_Th9xTrainerData() { memset(this, 0, sizeof(t_Th9xTrainerData)); } t_Th9xTrainerData::operator TrainerData () { TrainerData c9x; for (int i=0; i 6) { c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; c9x.curve.value = curve - 6; } else if (curve > 0) { c9x.curve.type = CurveReference::CURVE_REF_FUNC; c9x.curve.value = curve; } c9x.mode = mode3; c9x.weight = weight6; c9x.chn = chn; c9x.swtch = th9xToSwitch(drSw); return c9x; } t_Th9xLimitData::t_Th9xLimitData() { memset(this, 0, sizeof(t_Th9xLimitData)); } t_Th9xLimitData::operator LimitData () { LimitData c9x; c9x.min = min-100; c9x.max = max+100; c9x.revert = revert; c9x.offset = offset; return c9x; } t_Th9xMixData::t_Th9xMixData() { memset(this, 0, sizeof(t_Th9xMixData)); } t_Th9xMixData::operator MixData () { MixData c9x; c9x.destCh = destCh; if (srcRaw < 7) c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw); else if (srcRaw < 10) c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); // TODO else if (srcRaw == 10) c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); else if (srcRaw == 11) c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); // TODO CUR else if (srcRaw < 24) c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-12); else /* always true if (srcRaw < 32) */ c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-24); c9x.weight = weight; c9x.swtch = th9xToSwitch(swtch); if (curve > 6) { c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; c9x.curve.value = curve - 6; } else if (curve > 0) { c9x.curve.type = CurveReference::CURVE_REF_FUNC; c9x.curve.value = curve; } c9x.speedUp = speedUp; c9x.speedDown = speedDown; c9x.mltpx = (MltpxValue)mixMode; return c9x; } t_Th9xCustomSwData::operator CustomSwData () { CustomSwData c9x; c9x.func = opCmp; c9x.val1 = val1; c9x.val2 = val2; if ((c9x.func >= CS_FN_VPOS && c9x.func <= CS_FN_ANEG) || c9x.func >= CS_FN_EQUAL) { c9x.val1 = toSource(val1).toValue(); } if (c9x.func >= CS_FN_EQUAL) { c9x.val2 = toSource(val2).toValue(); } if (c9x.func >= CS_FN_AND && c9x.func <= CS_FN_XOR) { c9x.val1 = th9xToSwitch(val1).toValue(); c9x.val2 = th9xToSwitch(val2).toValue(); } return c9x; } int8_t t_Th9xCustomSwData::fromSource(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("th9x 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_3POS) v1 = 9; */ 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 t_Th9xCustomSwData::toSource(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_3POS); } */ 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_Th9xModelData::t_Th9xModelData() { memset(this, 0, sizeof(t_Th9xModelData)); } t_Th9xModelData::operator ModelData () { ModelData c9x; c9x.used = true; getEEPROMString(c9x.name, name, sizeof(name)); switch(tmrMode) { case 1: c9x.timers[0].mode = TMRMODE_ABS; break; case 2: c9x.timers[0].mode = TMRMODE_THs; break; case 3: c9x.timers[0].mode = TMRMODE_THp; break; default: c9x.timers[0].mode = TMRMODE_OFF; break; } // c9x.timers[0].dir = tmrDir; c9x.timers[0].val = tmrVal; /*c9x.protocol = (Protocol)protocol; 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 = FuncTrims2Offsets; if (trimSw) { c9x.funcSw[0].swtch = trimSw; } c9x.beepANACenter = beepANACenter; c9x.pulsePol = pulsePol; c9x.extendedLimits = extendedLimits; c9x.swashRingData.invertELE = swashInvertELE; c9x.swashRingData.invertAIL = swashInvertAIL; c9x.swashRingData.invertCOL = swashInvertCOL; c9x.swashRingData.type = swashType; c9x.swashRingData.collectiveSource = swashCollectiveSource; c9x.swashRingData.value = swashRingValue;*/ for (int i=0; i