Skip to content

Commit

Permalink
fix(yaml): Do not limit to static MPM protocol definitions (#4146)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeerick committed Oct 18, 2023
1 parent f4bbbb7 commit b395611
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
45 changes: 35 additions & 10 deletions radio/src/gui/colorlcd/mpm_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 FormGroup::Line
{
Choice* choice;
MPMSubtypeChoice* choice;

MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx);
void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx);
Expand Down Expand Up @@ -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(FormGroup* form, FlexGridLayout *layout, uint8_t moduleIdx) :
FormGroup::Line(form, layout)
MPMSubtype::MPMSubtype(FormGroup* form, FlexGridLayout* layout,
uint8_t moduleIdx) :
FormGroup::Line(form, layout)
{
this->moduleIdx = moduleIdx;
this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType;
Expand All @@ -198,17 +222,18 @@ MPMSubtype::MPMSubtype(FormGroup* form, FlexGridLayout *layout, uint8_t moduleId
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)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/io/multi_protolist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,19 +1889,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) {
Expand Down

0 comments on commit b395611

Please sign in to comment.