fix(yaml): Do not limit to static MPM protocol definitions (#4146)
This commit is contained in:
@@ -20,10 +20,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mpm_settings.h"
|
#include "mpm_settings.h"
|
||||||
#include "opentx.h"
|
|
||||||
|
|
||||||
#include "multi_rfprotos.h"
|
#include "choice.h"
|
||||||
#include "io/multi_protolist.h"
|
#include "io/multi_protolist.h"
|
||||||
|
#include "multi_rfprotos.h"
|
||||||
|
#include "opentx.h"
|
||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#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
|
struct MPMSubtype : public FormWindow::Line
|
||||||
{
|
{
|
||||||
Choice* choice;
|
MPMSubtypeChoice* choice;
|
||||||
|
|
||||||
MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx);
|
MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx);
|
||||||
void update(const MultiRfProtocols::RfProto* rfProto, 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);
|
if (obj) lv_event_send(obj, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx) :
|
MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout* layout,
|
||||||
FormWindow::Line(form, layout)
|
uint8_t moduleIdx) :
|
||||||
|
FormWindow::Line(form, layout)
|
||||||
{
|
{
|
||||||
this->moduleIdx = moduleIdx;
|
this->moduleIdx = moduleIdx;
|
||||||
this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType;
|
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);
|
new StaticText(this, rect_t{}, STR_RF_PROTOCOL, 0, COLOR_THEME_PRIMARY1);
|
||||||
|
|
||||||
auto md = &g_model.moduleData[moduleIdx];
|
auto md = &g_model.moduleData[moduleIdx];
|
||||||
choice = new Choice(
|
choice = new MPMSubtypeChoice(
|
||||||
this, rect_t{}, 0, 0, [=]() { return md->subType; },
|
this, [=]() { return md->subType; },
|
||||||
[=](int16_t newValue) {
|
[=](int16_t newValue) {
|
||||||
md->subType = newValue;
|
md->subType = newValue;
|
||||||
if(!DSM2autoUpdated) // reset MPM options only if user triggered
|
if (!DSM2autoUpdated) // reset MPM options only if user triggered
|
||||||
resetMultiProtocolsOptions(moduleIdx);
|
resetMultiProtocolsOptions(moduleIdx);
|
||||||
DSM2autoUpdated = false;
|
DSM2autoUpdated = false;
|
||||||
SET_DIRTY();
|
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)
|
void MPMSubtype::update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx)
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ std::string MultiRfProtocols::getProtoLabel(unsigned int proto) const
|
|||||||
return protoList[idx].label;
|
return protoList[idx].label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::string();
|
return std::to_string(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MultiRfProtocols::getLastProtoLabel() const
|
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
|
// convert to ETX format and write to vars
|
||||||
if (type > 0) {
|
if (type > 0) {
|
||||||
type -= 1; // change to internal 0 based representation
|
type -= 1; // change to internal 0 based representation
|
||||||
|
md->multi.rfProtocol = type;
|
||||||
if(type > MODULE_SUBTYPE_MULTI_LAST) {
|
md->subType = subtype;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (md->type == MODULE_TYPE_DSM2) {
|
} else if (md->type == MODULE_TYPE_DSM2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user