/* * Copyright (C) OpenTX * * Based on code named * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * 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 "modeldata.h" #include "eeprominterface.h" #include "generalsettings.h" #include "macros.h" #include "radiodataconversionstate.h" #include "helpers.h" /* * TimerData */ void TimerData::convert(RadioDataConversionState & cstate) { cstate.setComponent(tr("TMR"), 1); cstate.setSubComp(tr("Timer %1").arg(cstate.subCompIdx + 1)); mode.convert(cstate); } /* * ModelData */ ModelData::ModelData() { clear(); } ModelData::ModelData(const ModelData & src) { *this = src; } ModelData & ModelData::operator = (const ModelData & src) { memcpy(reinterpret_cast(this), &src, sizeof(ModelData)); return *this; } ExpoData * ModelData::insertInput(const int idx) { memmove(&expoData[idx+1], &expoData[idx], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); expoData[idx].clear(); return &expoData[idx]; } bool ModelData::isInputValid(const unsigned int idx) const { for (int i=0; imode == 0) break; if (expo->chn == idx) return true; } return false; } bool ModelData::hasExpos(uint8_t inputIdx) const { for (int i=0; i ModelData::expos(int input) const { QVector result; for (int i=0; ichn==input && ed->mode!=0) { result << ed; } } return result; } QVector ModelData::mixes(int channel) const { QVector result; for (int i=0; idestCh == channel+1) { result << md; } } return result; } void ModelData::removeInput(const int idx, bool clearName) { unsigned int chn = expoData[idx].chn; memmove(&expoData[idx], &expoData[idx+1], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); expoData[CPN_MAX_EXPOS-1].clear(); //also remove input name if removing last line for this input if (clearName && !expos(chn).size()) inputNames[chn][0] = 0; } void ModelData::clearInputs() { for (int i=0; igetCapability(VirtualInputs)) { for (int i=0; i(this), 0, sizeof(ModelData)); modelIndex = -1; // an invalid index, this is managed by the TreeView data model moduleData[0].protocol = PULSES_OFF; moduleData[1].protocol = PULSES_OFF; moduleData[0].channelsCount = 8; moduleData[1].channelsStart = 0; moduleData[1].channelsCount = 8; moduleData[0].ppm.delay = 300; moduleData[1].ppm.delay = 300; moduleData[2].ppm.delay = 300; //Trainer PPM for (int i=0; ichn = i; expo->mode = INPUT_MODE_BOTH; expo->srcRaw = settings.getDefaultSource(i); expo->weight = 100; strncpy(inputNames[i], Helpers::removeAccents(expo->srcRaw.toString(this)).toLatin1().constData(), sizeof(inputNames[i])-1); } } } void ModelData::setDefaultMixes(const GeneralSettings & settings) { Board::Type board = getCurrentBoard(); if (IS_ARM(board)) { setDefaultInputs(settings); } for (int i=0; idestCh = i+1; mix->weight = 100; if (IS_ARM(board)) { mix->srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, i); } else { mix->srcRaw = RawSource(SOURCE_TYPE_STICK, i); } } } void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settings) { clear(); used = true; sprintf(name, "MODEL%02d", id+1); for (int i=0; i 1024; } int ModelData::getGVarFieldValue(int phaseIdx, int gvarIdx) { int idx = flightModeData[phaseIdx].gvars[gvarIdx]; for (int i=0; idx>GVAR_MAX_VALUE && i= phaseIdx) nextPhase += 1; phaseIdx = nextPhase; idx = flightModeData[phaseIdx].gvars[gvarIdx]; } return idx; } void ModelData::setTrimValue(int phaseIdx, int trimIdx, int value) { for (uint8_t i=0; i 500) trim = 500; break; } } } void ModelData::removeGlobalVar(int & var) { if (var >= 126 && var <= 130) var = flightModeData[0].gvars[var-126]; else if (var <= -126 && var >= -130) var = - flightModeData[0].gvars[-126-var]; } ModelData ModelData::removeGlobalVars() { ModelData result = *this; for (int i=0; i 0; } else { return true; } } float ModelData::getGVarFieldValuePrec(int phaseIdx, int gvarIdx) { return getGVarFieldValue(phaseIdx, gvarIdx) * gvarData[gvarIdx].multiplierGet(); } void ModelData::convert(RadioDataConversionState & cstate) { // Here we can add explicit conversions when moving from one board to another QString origin = QString(name); if (origin.isEmpty()) origin = QString::number(cstate.modelIdx+1); cstate.setOrigin(tr("Model: ") % origin); cstate.setComponent("SET", 0); if (thrTraceSrc && (int)thrTraceSrc < cstate.fromBoard.getCapability(Board::Pots) + cstate.fromBoard.getCapability(Board::Sliders)) { cstate.setSubComp(tr("Throttle Source")); thrTraceSrc = RawSource(SOURCE_TYPE_STICK, (int)thrTraceSrc + 3).convert(cstate).index - 3; } for (int i=0; i