Skip to content

Commit

Permalink
fix: display numeric proto/sub-type if unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic authored and pfeerick committed Oct 18, 2023
1 parent b138535 commit 2f76a02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions radio/src/gui/colorlcd/mpm_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include "mpm_settings.h"
#include "choice.h"
#include "opentx.h"

#include "multi_rfprotos.h"
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 @@ -198,11 +221,11 @@ 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;
SET_DIRTY();
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

0 comments on commit 2f76a02

Please sign in to comment.