fix: MPM protocol options missing for some protocols (#3504)

* fixes #2713

changes:
- use getMultiOptionTitle() instead of rfproto->getOptionStr() as getMultiOptionTitle() takes updated MPM status in account

* code cleanup: removed obsolete functions

* fix #3046

* fixed my complete misunderstanding of how the chosen protocol is updated in Multi DSM auto mode

* removed obsolete check

* update subType list only on rf protocol change

added some comments

* reconsidered implementation utilizing  LV_EVENT_REFRESH to avoid sporadic loss of update

* editorial change

* fix problem where a successful MPM DSM2 auto bind would reset the receiver ID

* reset DSM2autoUpdated just in case
This commit is contained in:
Michael
2023-05-23 10:05:12 +10:00
committed by GitHub
parent 5327c890f2
commit 8893db2726
3 changed files with 39 additions and 26 deletions
+39 -9
View File
@@ -45,7 +45,7 @@ struct MPMProtoOption : public FormGroup::Line
DynamicNumber<uint16_t>* 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) {
-14
View File
@@ -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;
-3
View File
@@ -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; }