Files
edgetx-gx12/radio/src/model_init.cpp
T
MichaelandGitHub 04359757c4 fix: Update built-in Multi-protocol module protocol lists, single source for firmware and cpn (#3435)
* - Concentrated Multi protocol definitions into a consistent single source. Actually two .h files, one for the protocol list and names, the other for subtypes and capababilites, see comments in .h files as to why

- updated available protocols reflecting 1.3.3.20 (15+ protocols)
- fixed Companion always showing f/s and channel map options in model setup disregarding the protocol capability

* Following @pfeerick's review: changed heaeders and typos

fixed Ubuntu runtime error on assert
fixed change of Multi protocol not triggering writing yaml file

* corrected copy/paste error

* fixed FrSky index juggling

* Updated Multiprotocol database to current MPM project status (ref. MPM Multiprotos.ino)

- changed protocol name FX816 to FX
- added Flysky AFHDS2A options PPM and PPWM SBUS 16ch subtypes "PWM,SB16" and  "PPM,SB16
- added V761 option to select TOPRC
- added FX options "816" and "620"
- added FRSKYR9 option "-- 8ch"

* MPM protocol scan excludes some protocols which are not meant to be selected. For Companion and Simualtor (and for radios if there is no MPM connected) this was handled in different places with outdated information. Harmonized and centralized the handling of non-selectabale protocols into the single source for all companion, Simulator and all gui types.

* More cleanup:

- changed some MPM protocol names to the ones the MPM delivers with MPM protocol scan to harmonize names between CPN/Simulator/radio
- added XN2927DUMP and MOULDKG to the list of excluded MPM protocols just like the MPM does with MPM protocol scan
- added new option value limits and moved definitions to single source
- adapted CPN and radio to use common definitions of option values for all GUI types
- moved distributed MPM (as far as possible) to one coherent place under a single #if defined (MULTIMODULE)
- fixed option value not reset at change of protocol
- some editorial stuff

Note: There is still some work to be done on CPN GUI option values. DSM2 servo rates are hard coded, BAYANG telemetry options are only shown by index and not by text as in radio code, AFHDS2A servo update rate is shown as index too which is to no use for users.

I'll try to fix all this in the next session, but request to get rid of BAYANG telemetry options translations. It is much easier to define a common string list by using untranslated.h

* rebase due to fr.h

* resolve merge conflict with main fr.h

* more cleanup:

- deleted multiple definition of MM_RF_CUSTOM_SELECTED in favor of single source define
- bw radios: change to only allow defined protocols rather than a fixed 127 protocols

* Changes:

- magic sentinel number 0xfe as define
- add 10 NN protocol entries for future use of new MPM protocols not yet defined in ETX (still recommend timely ETX maintenance update if MPM releases new firmware)

* Changes by @elecpower:

- align field labels to radio
- change servo update frequency from combo box to spin box with edit only via up/down arrows to stop invalid values being entered via keyboard. Remove frequency list used to populate combo box as only used by Companion.
- add validation to module yaml decode checking for unsupported multi protocols and/or multi protocol sub types and if unsupported set module to OFF just to be safe.

* Changes:

- radio: added validation to module yaml decode checking for unsupported multi protocols and/or multi protocol sub types and if unsupported set module to OFF just to be safe.

* CPN: use sentinel define

* cpn: Sort multi protocols list (courtesy @elecpower)

* fixes #3480

changes:
- moved FrSky subtype defines to MultiProtoDefs.h
- updated bind_button_driver.cpp

* missed replacing one instance of setMultiProtocol()

* changes:

- editorial change
- added multi option to OMP protocol (ref #2713)

* rather go for STR_MULTI_RFTUNE because MPM manual talks about RF tune

* made XN297_DUMP selectable (available with MPM debug fw only)

* corrected merge mistakes
2023-05-22 20:07:29 +10:00

165 lines
4.4 KiB
C++

/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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 setDefaultInputs()
{
for (int i=0; i<NUM_STICKS; i++) {
uint8_t stick_index = channelOrder(i+1);
ExpoData *expo = expoAddress(i);
expo->srcRaw = MIXSRC_Rud - 1 + stick_index;
expo->curve.type = CURVE_REF_EXPO;
expo->chn = i;
expo->weight = 100;
expo->mode = 3; // TODO constant
strncpy(g_model.inputNames[i],
STR_VSRCRAW[stick_index] + sizeof(STR_CHAR_STICK) - 1,
LEN_INPUT_NAME);
}
storageDirty(EE_MODEL);
}
void clearMixes()
{
memset(g_model.mixData, 0, sizeof(g_model.mixData));
}
void setDefaultMixes()
{
for (int i=0; i<NUM_STICKS; i++) {
MixData * mix = mixAddress(i);
mix->destCh = i;
mix->weight = 100;
mix->srcRaw = i+1;
}
storageDirty(EE_MODEL);
}
void setDefaultModelRegistrationID()
{
memcpy(g_model.modelRegistrationID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID);
}
void setDefaultGVars()
{
#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 setDefaultRSSIValues()
{
// Set to legacy FrSky values until
// a better solution is found (module specific?)
//
g_model.rfAlarms.warning = 45;
g_model.rfAlarms.critical = 42;
}
void setVendorSpecificModelDefaults(uint8_t id)
{
#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].multi.rfProtocol = MODULE_SUBTYPE_MULTI_FRSKY;
g_model.moduleData[INTERNAL_MODULE].subType = MULTI_FRSKYD_SUBTYPE_D8;
g_model.moduleData[INTERNAL_MODULE].failsafeMode = FAILSAFE_NOPULSES;
#endif
}
void applyDefaultTemplate()
{
setDefaultInputs();
setDefaultMixes();
setDefaultGVars();
setDefaultRSSIValues();
setDefaultModelRegistrationID();
#if defined(FUNCTION_SWITCHES)
g_model.functionSwitchConfig = DEFAULT_FS_CONFIG;
g_model.functionSwitchGroup = DEFAULT_FS_GROUPS;
g_model.functionSwitchStartConfig = DEFAULT_FS_STARTUP_CONFIG;
g_model.functionSwitchLogicalState = 0;
#endif
#if defined(COLORLCD)
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?
}
void setModelDefaults(uint8_t id)
{
memset(&g_model, 0, sizeof(g_model));
applyDefaultTemplate();
setVendorSpecificModelDefaults(id);
#if !defined(STORAGE_MODELSLIST)
// EEPROM model indexes starting with 0
id++;
#endif
strAppendUnsigned(strAppend(g_model.header.name, STR_MODEL), id, 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
}