Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 FormWindow::Line
{
Choice* choice;
MPMSubtypeChoice* choice;

MPMSubtype(FormWindow* 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(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;
Expand All @@ -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)
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 @@ -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) {
Expand Down