fix(yaml): Do not limit to static MPM protocol definitions (#4146)

This commit is contained in:
Raphael Coeffic
2023-10-18 19:24:21 +10:00
committed by GitHub
parent 1b789cafb3
commit 6d3aa573d4
3 changed files with 38 additions and 24 deletions
+35 -10
View File
@@ -20,10 +20,11 @@
*/
#include "mpm_settings.h"
#include "opentx.h"
#include "multi_rfprotos.h"
#include "choice.h"
#include "io/multi_protolist.h"
#include "multi_rfprotos.h"
#include "opentx.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
@@ -148,9 +149,31 @@ void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData
}
}
struct MPMSubtypeChoice : public Choice {
MPMSubtypeChoice(Window* parent, std::function<int()> get,
std::function<void(int)> set) :
Choice(parent, rect_t{}, 0, 0, get, set)
{
}
std::string getLabelText() override
{
if (_getValue) {
int val = _getValue();
val -= vmin;
if (val >= 0 && val < (int)values.size()) {
return values[val];
} else {
return std::to_string(val);
}
}
return std::string();
}
};
struct MPMSubtype : public FormWindow::Line
{
Choice* choice;
MPMSubtypeChoice* choice;
MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx);
void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx);
@@ -187,8 +210,9 @@ static void subtype_event_cb(lv_event_t* e)
if (obj) lv_event_send(obj, LV_EVENT_VALUE_CHANGED, nullptr);
}
MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) :
FormWindow::Line(form, layout)
MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout* layout,
uint8_t moduleIdx) :
FormWindow::Line(form, layout)
{
this->moduleIdx = moduleIdx;
this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType;
@@ -198,17 +222,18 @@ MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleI
new StaticText(this, rect_t{}, STR_RF_PROTOCOL, 0, COLOR_THEME_PRIMARY1);
auto md = &g_model.moduleData[moduleIdx];
choice = new Choice(
this, rect_t{}, 0, 0, [=]() { return md->subType; },
choice = new MPMSubtypeChoice(
this, [=]() { return md->subType; },
[=](int16_t newValue) {
md->subType = newValue;
if(!DSM2autoUpdated) // reset MPM options only if user triggered
if (!DSM2autoUpdated) // reset MPM options only if user triggered
resetMultiProtocolsOptions(moduleIdx);
DSM2autoUpdated = false;
DSM2autoUpdated = false;
SET_DIRTY();
});
lv_obj_add_event_cb(choice->getLvObj(), subtype_event_cb, LV_EVENT_VALUE_CHANGED, lvobj);
lv_obj_add_event_cb(choice->getLvObj(), subtype_event_cb,
LV_EVENT_VALUE_CHANGED, lvobj);
}
void MPMSubtype::update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx)
+1 -1
View File
@@ -183,7 +183,7 @@ std::string MultiRfProtocols::getProtoLabel(unsigned int proto) const
return protoList[idx].label;
}
}
return std::string();
return std::to_string(proto);
}
std::string MultiRfProtocols::getLastProtoLabel() const
@@ -1994,19 +1994,8 @@ static void r_modSubtype(void* user, uint8_t* data, uint32_t bitoffs,
// convert to ETX format and write to vars
if (type > 0) {
type -= 1; // change to internal 0 based representation
if(type > MODULE_SUBTYPE_MULTI_LAST) {
TRACE("Multi protocol: %d exceeds supported protocols. Module set to: OFF", type);
md->type = MODULE_TYPE_NONE;
} else {
if(subtype > getMultiProtocolDefinition(type)->maxSubtype) {
TRACE("Multi protocol sub-type %d exceeds number of supported sub-types. Module set to: OFF", subtype);
md->type = MODULE_TYPE_NONE;
} else {
md->multi.rfProtocol = type;
md->subType = subtype;
}
}
md->multi.rfProtocol = type;
md->subType = subtype;
}
#endif
} else if (md->type == MODULE_TYPE_DSM2) {