diff --git a/radio/src/gui/colorlcd/mpm_settings.cpp b/radio/src/gui/colorlcd/mpm_settings.cpp index 8798fb411..bab214110 100644 --- a/radio/src/gui/colorlcd/mpm_settings.cpp +++ b/radio/src/gui/colorlcd/mpm_settings.cpp @@ -45,7 +45,7 @@ struct MPMProtoOption : public FormGroup::Line DynamicNumber* rssi; MPMProtoOption(FormGroup* form, FlexGridLayout *layout); - void update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md); + void update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md, uint8_t moduleIdx); }; MPMProtoOption::MPMProtoOption(FormGroup* form, FlexGridLayout *layout) : @@ -64,16 +64,16 @@ MPMProtoOption::MPMProtoOption(FormGroup* form, FlexGridLayout *layout) : box, rect_t{}, [] { return (uint16_t)TELEMETRY_RSSI(); }, 0, getRxStatLabels()->label, getRxStatLabels()->unit); } -void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md) +void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md, uint8_t moduleIdx) { - if (!rfProto || !rfProto->getOptionStr()) { + if (!rfProto || !getMultiOptionTitle(moduleIdx)) { lv_obj_add_flag(lvobj, LV_OBJ_FLAG_HIDDEN); return; } lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN); - const char *title = rfProto->getOptionStr(); + const char *title = getMultiOptionTitle(moduleIdx); label->setText(title); lv_obj_add_flag(choice->getLvObj(), LV_OBJ_FLAG_HIDDEN); @@ -151,9 +151,33 @@ struct MPMSubtype : public FormGroup::Line Choice* choice; MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx); - void update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md); + void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx); + void checkEvents(); + + protected: + uint8_t moduleIdx; + uint8_t DSM2lastSubType; + bool DSM2autoUpdated; }; +void MPMSubtype::checkEvents() { + // + // DSM2: successful bind in auto mode changes DSM2 subType + // + ModuleData* md = &g_model.moduleData[this->moduleIdx]; + + if(md->multi.rfProtocol == MODULE_SUBTYPE_MULTI_DSM2) { // do this only for DSM2 + uint8_t subType = md->subType; // fetch DSM2 subType + + if(subType != DSM2lastSubType) { // if DSM2 subType has auto changed + DSM2autoUpdated = true; // indicate this was not user triggered + DSM2lastSubType = subType; // memorize new DSM2 subType + choice->setValue(subType); // set new DSM2 subType + lv_event_send(choice->getLvObj(), LV_EVENT_REFRESH, nullptr); // refresh subType field + } + } +} + static void subtype_event_cb(lv_event_t* e) { if (lv_event_get_param(e)) return; @@ -164,6 +188,10 @@ static void subtype_event_cb(lv_event_t* e) MPMSubtype::MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) : FormGroup::Line(form, layout) { + this->moduleIdx = moduleIdx; + this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType; + this->DSM2autoUpdated = false; + if (layout) layout->resetPos(); new StaticText(this, rect_t{}, STR_RF_PROTOCOL, 0, COLOR_THEME_PRIMARY1); @@ -172,14 +200,16 @@ MPMSubtype::MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleId this, rect_t{}, 0, 0, [=]() { return md->subType; }, [=](int16_t newValue) { md->subType = newValue; - resetMultiProtocolsOptions(moduleIdx); + if(!DSM2autoUpdated) // reset MPM options only if user triggered + resetMultiProtocolsOptions(moduleIdx); + DSM2autoUpdated = false; SET_DIRTY(); }); lv_obj_add_event_cb(choice->getLvObj(), subtype_event_cb, LV_EVENT_VALUE_CHANGED, lvobj); } -void MPMSubtype::update(const MultiRfProtocols::RfProto* rfProto, ModuleData* md) +void MPMSubtype::update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx) { if (!rfProto || rfProto->subProtos.size() == 0) { lv_obj_add_flag(lvobj, LV_OBJ_FLAG_HIDDEN); @@ -322,8 +352,8 @@ void MultimoduleSettings::update() auto mpm_rfprotos = MultiRfProtocols::instance(moduleIdx); auto rfProto = mpm_rfprotos->getProto(md->multi.rfProtocol); - st_line->update(rfProto, md); - opt_line->update(rfProto, md); + st_line->update(rfProto, moduleIdx); + opt_line->update(rfProto, md, moduleIdx); auto multi_proto = md->multi.rfProtocol; if (multi_proto == MODULE_SUBTYPE_MULTI_DSM2) { diff --git a/radio/src/io/multi_protolist.cpp b/radio/src/io/multi_protolist.cpp index e112d0e45..126dfdf22 100644 --- a/radio/src/io/multi_protolist.cpp +++ b/radio/src/io/multi_protolist.cpp @@ -136,20 +136,6 @@ void MultiRfProtocols::RfProto::fillSubProtoList(const char *const *str, int n) } } -uint8_t MultiRfProtocols::RfProto::getOption() const -{ - uint8_t opt = flags >> 4; - if (opt >= getMaxMultiOptions()) { - opt = 1; // Unknown options are defaulted to type 1 (basic option) - } - return opt; -} - -const char* MultiRfProtocols::RfProto::getOptionStr() const -{ - return mm_options_strings::options[getOption()]; -} - MultiRfProtocols* MultiRfProtocols::instance(unsigned int moduleIdx) { if (moduleIdx >= NUM_MODULES) return nullptr; diff --git a/radio/src/io/multi_protolist.h b/radio/src/io/multi_protolist.h index 62855fd94..f431dca6b 100644 --- a/radio/src/io/multi_protolist.h +++ b/radio/src/io/multi_protolist.h @@ -73,9 +73,6 @@ class MultiRfProtocols // fixed length strings concatenated void fillSubProtoList(const char* str, int n, int len); - - uint8_t getOption() const; - const char* getOptionStr() const; bool supportsFailsafe() const { return flags & 0x01; } bool supportsDisableMapping() const { return flags & 0x02; }