diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index b8c302f44..d36706293 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -419,6 +419,7 @@ set(SRC stamp.cpp timers.cpp trainer.cpp + model_init.cpp ) if(GUI) diff --git a/radio/src/model_init.cpp b/radio/src/model_init.cpp new file mode 100644 index 000000000..af1e04366 --- /dev/null +++ b/radio/src/model_init.cpp @@ -0,0 +1,144 @@ +/* + * 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 "opentx.h" + +void clearInputs() +{ + memset(g_model.expoData, 0, sizeof(g_model.expoData)); +} + +void defaultInputs() +{ + for (int i=0; isrcRaw = MIXSRC_Rud - 1 + stick_index; + expo->curve.type = CURVE_REF_EXPO; + expo->chn = i; + expo->weight = 100; + expo->mode = 3; // TODO constant + for (int c = 0; c < 3; c++) { + g_model.inputNames[i][c] = STR_VSRCRAW[2 + 4 * stick_index + c]; + } +#if LEN_INPUT_NAME > 3 + g_model.inputNames[i][3] = '\0'; +#endif + } + storageDirty(EE_MODEL); +} + +void clearMixers() +{ + memset(g_model.mixData, 0, sizeof(g_model.mixData)); +} + +void defaultMixers() +{ + for (int i=0; idestCh = i; + mix->weight = 100; + mix->srcRaw = i+1; + } + storageDirty(EE_MODEL); +} + +void defaultModelRegistrationID() +{ + memcpy(g_model.modelRegistrationID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID); +} + +void defaultGVars() +{ +#if defined(FLIGHT_MODES) && defined(GVARS) + for (int fmIdx = 1; fmIdx < MAX_FLIGHT_MODES; fmIdx++) { + for (int gvarIdx = 0; gvarIdx < MAX_GVARS; gvarIdx++) { + g_model.flightModeData[fmIdx].gvars[gvarIdx] = GVAR_MAX + 1; + } + } +#endif +} + +void setVendorSpecificModelDefaults() +{ +#if defined(FRSKY_RELEASE) + g_model.moduleData[INTERNAL_MODULE].type = IS_PXX2_INTERNAL_ENABLED() ? MODULE_TYPE_ISRM_PXX2 : MODULE_TYPE_XJT_PXX1; + g_model.moduleData[INTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(INTERNAL_MODULE); + #if defined(EEPROM) + g_model.header.modelId[INTERNAL_MODULE] = findNextUnusedModelId(id, INTERNAL_MODULE); + modelHeaders[id].modelId[INTERNAL_MODULE] = g_model.header.modelId[INTERNAL_MODULE]; + #endif +#endif + + // TODO: we should probably have some default trainer mode + // per radio, depending on what is supported + // +#if defined(PCBXLITE) + g_model.trainerData.mode = TRAINER_MODE_MASTER_BLUETOOTH; +#endif + +#if defined(RADIOMASTER_RTF_RELEASE) + // Those settings are for headless radio + g_model.trainerData.mode = TRAINER_MODE_SLAVE; + g_model.moduleData[INTERNAL_MODULE].type = MODULE_TYPE_MULTIMODULE; + g_model.moduleData[INTERNAL_MODULE].setMultiProtocol(MODULE_SUBTYPE_MULTI_FRSKY); + g_model.moduleData[INTERNAL_MODULE].subType = MM_RF_FRSKY_SUBTYPE_D8; + g_model.moduleData[INTERNAL_MODULE].failsafeMode = FAILSAFE_NOPULSES; +#endif +} + +void applyDefaultTemplate() +{ + defaultInputs(); + defaultMixers(); + defaultGVars(); + + defaultModelRegistrationID(); + +#if defined(COLORLCD) + //TODO: not sure yet we need it here + loadDefaultLayout(); + + // enable switch warnings + for (int i = 0; i < NUM_SWITCHES; i++) { + g_model.switchWarningState |= (1 << (3*i)); + } +#endif + + // TODO: what about switch warnings in non-color LCD radios? + + setVendorSpecificModelDefaults(); +} + + +void modelDefault(uint8_t id) +{ + memset(&g_model, 0, sizeof(g_model)); + applyDefaultTemplate(); + strAppendUnsigned(strAppend(g_model.header.name, STR_MODEL), id + 1, 2); + +#if defined(LUA) && defined(PCBTARANIS) // Horus uses menuModelWizard() for wizard + if (isFileAvailable(WIZARD_PATH "/" WIZARD_NAME)) { + f_chdir(WIZARD_PATH); + luaExec(WIZARD_NAME); + } +#endif +} diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index f85d77480..4ad05a801 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -364,133 +364,6 @@ uint16_t evalChkSum() return sum; } -void clearInputs() -{ - memset(g_model.expoData, 0, sizeof(g_model.expoData)); -} - -void defaultInputs() -{ - for (int i=0; isrcRaw = MIXSRC_Rud - 1 + stick_index; - expo->curve.type = CURVE_REF_EXPO; - expo->chn = i; - expo->weight = 100; - expo->mode = 3; // TODO constant - for (int c = 0; c < 3; c++) { - g_model.inputNames[i][c] = STR_VSRCRAW[2 + 4 * stick_index + c]; - } -#if LEN_INPUT_NAME > 3 - g_model.inputNames[i][3] = '\0'; -#endif - } - storageDirty(EE_MODEL); -} - -void clearMixers() -{ - memset(g_model.mixData, 0, sizeof(g_model.mixData)); -} - -void defaultMixers() -{ - for (int i=0; idestCh = i; - mix->weight = 100; - mix->srcRaw = i+1; - } - storageDirty(EE_MODEL); -} - -void defaultModelRegistrationID() -{ - memcpy(g_model.modelRegistrationID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID); -} - -void defaultGVars() -{ -#if defined(FLIGHT_MODES) && defined(GVARS) - for (int fmIdx = 1; fmIdx < MAX_FLIGHT_MODES; fmIdx++) { - for (int gvarIdx = 0; gvarIdx < MAX_GVARS; gvarIdx++) { - g_model.flightModeData[fmIdx].gvars[gvarIdx] = GVAR_MAX + 1; - } - } -#endif -} - -// TODO: -// - this needs to go away and be banned out of the main -// - vendors should provide their own defaults in their own builds, -// - and disclose them by their own means (GPL compliance) -// -void setVendorSpecificModelDefaults() -{ -#if defined(FRSKY_RELEASE) - g_model.moduleData[INTERNAL_MODULE].type = IS_PXX2_INTERNAL_ENABLED() ? MODULE_TYPE_ISRM_PXX2 : MODULE_TYPE_XJT_PXX1; - g_model.moduleData[INTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(INTERNAL_MODULE); - #if defined(EEPROM) - g_model.header.modelId[INTERNAL_MODULE] = findNextUnusedModelId(id, INTERNAL_MODULE); - modelHeaders[id].modelId[INTERNAL_MODULE] = g_model.header.modelId[INTERNAL_MODULE]; - #endif -#endif - - // TODO: we should probably have some default trainer mode - // per radio, depending on what is supported - // -#if defined(PCBXLITE) - g_model.trainerData.mode = TRAINER_MODE_MASTER_BLUETOOTH; -#endif - -#if defined(RADIOMASTER_RTF_RELEASE) - // Those settings are for headless radio - g_model.trainerData.mode = TRAINER_MODE_SLAVE; - g_model.moduleData[INTERNAL_MODULE].type = MODULE_TYPE_MULTIMODULE; - g_model.moduleData[INTERNAL_MODULE].setMultiProtocol(MODULE_SUBTYPE_MULTI_FRSKY); - g_model.moduleData[INTERNAL_MODULE].subType = MM_RF_FRSKY_SUBTYPE_D8; - g_model.moduleData[INTERNAL_MODULE].failsafeMode = FAILSAFE_NOPULSES; -#endif -} - -void applyDefaultTemplate() -{ - defaultInputs(); - defaultMixers(); - defaultGVars(); - - defaultModelRegistrationID(); - -#if defined(COLORLCD) - //TODO: not sure yet we need it here - loadDefaultLayout(); - - // enable switch warnings - for (int i = 0; i < NUM_SWITCHES; i++) { - g_model.switchWarningState |= (1 << (3*i)); - } -#endif - - // TODO: what about switch warnings in non-color LCD radios? - - setVendorSpecificModelDefaults(); -} - - -void modelDefault(uint8_t id) -{ - memset(&g_model, 0, sizeof(g_model)); - applyDefaultTemplate(); - strAppendUnsigned(strAppend(g_model.header.name, STR_MODEL), id + 1, 2); - -#if defined(LUA) && defined(PCBTARANIS) // Horus uses menuModelWizard() for wizard - if (isFileAvailable(WIZARD_PATH "/" WIZARD_NAME)) { - f_chdir(WIZARD_PATH); - luaExec(WIZARD_NAME); - } -#endif -} bool isInputRecursive(int index) {