#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::t_Th9xTrainerMix(TrainerMix &c9x) { memset(this, 0, sizeof(t_Th9xTrainerMix)); srcChn = c9x.src; swtch = th9xFromSwitch(c9x.swtch); studWeight = (8 * c9x.weight) / 25; mode = c9x.mode; } 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::t_Th9xTrainerData(TrainerData &c9x) { memset(this, 0, sizeof(t_Th9xTrainerData)); for (int i=0; i= CS_FN_VPOS && c9x.func <= CS_FN_ANEG) || c9x.func >= CS_FN_EQUAL) { val1 = fromSource(RawSource(c9x.val1)); } if (c9x.func >= CS_FN_EQUAL) { val2 = fromSource(RawSource(c9x.val2)); } if (c9x.func >= CS_FN_AND && c9x.func <= CS_FN_XOR) { val1 = th9xFromSwitch(RawSwitch(c9x.val1)); val2 = th9xFromSwitch(RawSwitch(c9x.val2)); } if (opCmp>TH9X_MAX_CSFUNC ) { EEPROMWarnings += ::QObject::tr("th9x does not support Custom Switch function %1").arg(getFuncName(opCmp)) + "\n"; opCmp=0; val1=0; val2=0; } } 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::t_Th9xModelData(ModelData &c9x) { memset(this, 0, sizeof(t_Th9xModelData)); if (c9x.used) { setEEPROMString(name, c9x.name, sizeof(name)); mdVers = MDVERS; if (c9x.timers[0].mode == TMRMODE_ABS) tmrMode = 1; if (c9x.timers[0].mode == TMRMODE_THs) tmrMode = 2; if (c9x.timers[0].mode == TMRMODE_THp) tmrMode = 3; else tmrMode = 0; // TODO tmrDir = c9x.timers[0].dir; tmrVal = c9x.timers[0].val; //protocol = c9x.protocol; /* 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