diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index 84405d957..8d462166e 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -167,6 +167,7 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett setUpdateMask(IMUE_FlightModes | IMUE_LogicalSwitches | IMUE_TeleSensors | IMUE_FunctionSwitches); // Descending switch direction: NOT (!) switches + addItems(SWITCH_TYPE_TRAINER, -1); addItems(SWITCH_TYPE_ACT, -1); addItems(SWITCH_TYPE_SENSOR, -firmware->getCapability(Sensors)); addItems(SWITCH_TYPE_TELEMETRY, -1); @@ -190,6 +191,7 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett addItems(SWITCH_TYPE_ON, 1); addItems(SWITCH_TYPE_ONE, 1); addItems(SWITCH_TYPE_ACT, 1); + addItems(SWITCH_TYPE_TRAINER, 1); } void RawSwitchItemModel::setDynamicItemData(QStandardItem * item, const RawSwitch & rsw) const diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 5e9a94bc8..f605699ea 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -166,7 +166,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) int sw_type = getCurrentFirmware()->getRawSwitchTypesIndex(sw_str_tmp.c_str()); if (sw_type >= 0) { rhs.type = (RawSwitchType)sw_type; - if (rhs.type == SWITCH_TYPE_TELEMETRY || rhs.type == SWITCH_TYPE_ACT || rhs.type == SWITCH_TYPE_ONE) + if (rhs.type == SWITCH_TYPE_TELEMETRY || rhs.type == SWITCH_TYPE_TRAINER || rhs.type == SWITCH_TYPE_ACT || rhs.type == SWITCH_TYPE_ONE) // these types use index = 1 rhs.index = 1; else diff --git a/companion/src/firmwares/rawswitch.cpp b/companion/src/firmwares/rawswitch.cpp index efeb7adfb..60a93bc5b 100644 --- a/companion/src/firmwares/rawswitch.cpp +++ b/companion/src/firmwares/rawswitch.cpp @@ -149,6 +149,9 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen case SWITCH_TYPE_TELEMETRY: return tr("Telemetry"); + case SWITCH_TYPE_TRAINER: + return tr("Trn"); + default: return CPN_STR_UNKNOWN_ITEM; } @@ -280,6 +283,7 @@ StringTagMappingTable RawSwitch::getRawSwitchTypesLookupTable() {std::to_string(SWITCH_TYPE_TELEMETRY), "TELEMETRY_STREAMING"}, {std::to_string(SWITCH_TYPE_SENSOR), "Tnn"}, {std::to_string(SWITCH_TYPE_ACT), "RADIO_ACTIVITY"}, + {std::to_string(SWITCH_TYPE_TRAINER), "TRAINER_CONNECTED"}, }); return tbl; diff --git a/companion/src/firmwares/rawswitch.h b/companion/src/firmwares/rawswitch.h index 35dbdc5c6..2054eb7ed 100644 --- a/companion/src/firmwares/rawswitch.h +++ b/companion/src/firmwares/rawswitch.h @@ -47,6 +47,7 @@ enum RawSwitchType { SWITCH_TYPE_TELEMETRY, SWITCH_TYPE_SENSOR, SWITCH_TYPE_ACT, + SWITCH_TYPE_TRAINER, MAX_SWITCH_TYPE }; diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h index b1e5a87c1..a157fd354 100644 --- a/radio/src/dataconstants.h +++ b/radio/src/dataconstants.h @@ -441,6 +441,8 @@ enum SwitchSources { SWSRC_RADIO_ACTIVITY, + SWSRC_TRAINER_CONNECTED, + #if defined(DEBUG_LATENCY) SWSRC_LATENCY_TOGGLE, #endif diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index c72dcd555..8806f9f6b 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -47,13 +47,14 @@ class SwitchChoiceMenuToolbar : public MenuToolbar #if defined(DEBUG_LATENCY) auto lastSource = SWSRC_LATENCY_TOGGLE; #else - auto lastSource = SWSRC_RADIO_ACTIVITY; + auto lastSource = SWSRC_TRAINER_CONNECTED; #endif addButton( STR_CHAR_FUNCTION, SWSRC_ON, lastSource, [=](int16_t index) { index = abs(index); return index == 0 || index == SWSRC_ON || index == SWSRC_ONE || + index == SWSRC_TRAINER_CONNECTED || (index >= SWSRC_TELEMETRY_STREAMING && index <= lastSource && !(index >= SWSRC_FIRST_SENSOR && index <= SWSRC_LAST_SENSOR)); }, diff --git a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp index e7c102029..138cb98c0 100644 --- a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 2ee536b65..30613dbe8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -161,6 +161,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_t20.cpp b/radio/src/storage/yaml/yaml_datastructs_t20.cpp index 4d6470457..662a2cd54 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t20.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t20.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index 2012ca45e..dbbdfeaa8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 1a73037ad..6efe02a6d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -169,6 +169,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 1a73037ad..6efe02a6d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -169,6 +169,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index e84c66f48..e243e0dbb 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 40521c460..9ad6123a9 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 2341c5f00..c239c8a60 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -159,6 +159,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index ffdfbb68c..aacfa68dd 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -161,6 +161,7 @@ const struct YamlIdStr enum_SwitchSources[] = { { SWSRC_ONE, "ONE" }, { SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" }, { SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" }, + { SWSRC_TRAINER_CONNECTED, "TRAINER_CONNECTED" }, { SWSRC_OFF, "OFF" }, { 0, NULL } }; diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index 01eaa4e90..2e5cb1952 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -511,6 +511,8 @@ char *getSwitchPositionName(char *dest, swsrc_t idx) strcpy(s, "Tele"); } else if (idx == SWSRC_RADIO_ACTIVITY) { strcpy(s, "Act"); + } else if (idx == SWSRC_TRAINER_CONNECTED) { + strcpy(s, "Trn"); } #if defined(DEBUG_LATENCY) else if (idx == SWSRC_LATENCY_TOGGLE) { diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 162e0758c..40ba379c9 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -603,6 +603,9 @@ bool getSwitch(swsrc_t swtch, uint8_t flags) else if (cs_idx == SWSRC_RADIO_ACTIVITY) { result = (inactivity.counter < 2); } + else if (cs_idx == SWSRC_TRAINER_CONNECTED) { + result = isTrainerConnected(); + } else if (cs_idx >= SWSRC_FIRST_SENSOR) { result = !telemetryItems[cs_idx-SWSRC_FIRST_SENSOR].isOld(); } diff --git a/radio/src/trainer.cpp b/radio/src/trainer.cpp index 109efbdfe..57cea89cb 100644 --- a/radio/src/trainer.cpp +++ b/radio/src/trainer.cpp @@ -35,6 +35,11 @@ enum { }; uint8_t trainerStatus = TRAINER_NOT_CONNECTED; +bool isTrainerConnected() +{ + return trainerStatus == TRAINER_CONNECTED || trainerStatus == TRAINER_RECONNECTED; +} + void checkTrainerSignalWarning() { enum { diff --git a/radio/src/trainer.h b/radio/src/trainer.h index 22cd73153..ddb2da9d2 100644 --- a/radio/src/trainer.h +++ b/radio/src/trainer.h @@ -37,6 +37,7 @@ void checkTrainerSignalWarning(); void checkTrainerSettings(); void stopTrainer(); void forceResetTrainerSettings(); +bool isTrainerConnected(); // Needs to be inlined to avoid slow function calls in ISR routines inline void captureTrainerPulses(uint16_t capture)