Skip to content

Commit c0b458c

Browse files
fix: display numeric proto/sub-type if unknown
1 parent af53713 commit c0b458c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

radio/src/gui/colorlcd/mpm_settings.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "mpm_settings.h"
23+
#include "choice.h"
2324
#include "opentx.h"
2425

2526
#include "multi_rfprotos.h"
@@ -148,9 +149,31 @@ void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData
148149
}
149150
}
150151

152+
struct MPMSubtypeChoice : public Choice {
153+
MPMSubtypeChoice(Window* parent, std::function<int()> get,
154+
std::function<void(int)> set) :
155+
Choice(parent, rect_t{}, 0, 0, get, set)
156+
{
157+
}
158+
159+
std::string getLabelText() override
160+
{
161+
if (_getValue) {
162+
int val = _getValue();
163+
val -= vmin;
164+
if (val >= 0 && val < (int)values.size()) {
165+
return values[val];
166+
} else {
167+
return std::to_string(val);
168+
}
169+
}
170+
return std::string();
171+
}
172+
};
173+
151174
struct MPMSubtype : public FormWindow::Line
152175
{
153-
Choice* choice;
176+
MPMSubtypeChoice* choice;
154177

155178
MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx);
156179
void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx);
@@ -198,11 +221,11 @@ MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleI
198221
new StaticText(this, rect_t{}, STR_RF_PROTOCOL, 0, COLOR_THEME_PRIMARY1);
199222

200223
auto md = &g_model.moduleData[moduleIdx];
201-
choice = new Choice(
202-
this, rect_t{}, 0, 0, [=]() { return md->subType; },
224+
choice = new MPMSubtypeChoice(
225+
this, [=]() { return md->subType; },
203226
[=](int16_t newValue) {
204227
md->subType = newValue;
205-
if(!DSM2autoUpdated) // reset MPM options only if user triggered
228+
if(!DSM2autoUpdated) // reset MPM options only if user triggered
206229
resetMultiProtocolsOptions(moduleIdx);
207230
DSM2autoUpdated = false;
208231
SET_DIRTY();

radio/src/io/multi_protolist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ std::string MultiRfProtocols::getProtoLabel(unsigned int proto) const
183183
return protoList[idx].label;
184184
}
185185
}
186-
return std::string();
186+
return std::to_string(proto);
187187
}
188188

189189
std::string MultiRfProtocols::getLastProtoLabel() const

0 commit comments

Comments
 (0)