Skip to content

Commit

Permalink
fix(nv14): incorrect read/write of module data (#4953)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored May 3, 2024
1 parent 5281b8b commit dd87ecb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
41 changes: 19 additions & 22 deletions radio/src/gui/colorlcd/afhds2a_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ AFHDS2ASettings::AFHDS2ASettings(Window* parent, const FlexGridLayout& g,
[=](uint8_t v) { md->flysky.mode = v; });

#if defined(PCBNV14)
if (getNV14RfFwVersion() >= 0x1000E) {
line = newLine(grid);
static const char* _rf_power[] = {"Default", "High"};
afhds2RFPowerText = new StaticText(line, rect_t{}, STR_MULTI_RFPOWER);
afhds2RFPowerChoice = new Choice(line, rect_t{}, _rf_power, 0, 1,
GET_DEFAULT(md->flysky.rfPower),
[=](int32_t newValue) -> void {
md->flysky.rfPower = newValue;
resetPulsesAFHDS2();
});
}
line = newLine(grid);
static const char* _rf_power[] = {"Default", "High"};
afhds2RFPowerText = new StaticText(line, rect_t{}, STR_MULTI_RFPOWER);
afhds2RFPowerChoice = new Choice(line, rect_t{}, _rf_power, 0, 1,
GET_DEFAULT(md->flysky.rfPower),
[=](int32_t newValue) -> void {
md->flysky.rfPower = newValue;
resetPulsesAFHDS2();
});
#endif

hideAFHDS2Options();
Expand All @@ -104,10 +102,8 @@ void AFHDS2ASettings::hideAFHDS2Options()
afhds2OptionsLabel->hide();
afhds2ProtoOpts->hide();
#if defined(PCBNV14)
if (afhds2RFPowerText != nullptr)
afhds2RFPowerText->hide();
if (afhds2RFPowerChoice != nullptr)
afhds2RFPowerChoice->hide();
afhds2RFPowerText->hide();
afhds2RFPowerChoice->hide();
#endif
}

Expand All @@ -116,23 +112,24 @@ void AFHDS2ASettings::showAFHDS2Options()
afhds2OptionsLabel->show();
afhds2ProtoOpts->show();
#if defined(PCBNV14)
if (afhds2RFPowerText != nullptr)
afhds2RFPowerText->show();
if (afhds2RFPowerChoice != nullptr)
{
afhds2RFPowerChoice->show();
bool showRFPower = (getNV14RfFwVersion() >= 0x1000E);
afhds2RFPowerText->show(showRFPower);
afhds2RFPowerChoice->show(showRFPower);
if (showRFPower && (showRFPower != hasRFPower)) {
hasRFPower = showRFPower;
lv_event_send(afhds2RFPowerChoice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
}
#endif
}

void AFHDS2ASettings::checkEvents() {
void AFHDS2ASettings::checkEvents()
{
Window::checkEvents();
update();
}

void AFHDS2ASettings::update()
{
lastRefresh = get_tmr10ms();
if (isModuleAFHDS2A(moduleIdx)) {
showAFHDS2Options();
} else {
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/afhds2a_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class AFHDS2ASettings : public Window, public ModuleOptions
uint8_t moduleIdx;
ModuleData* md;
FlexGridLayout grid;
tmr10ms_t lastRefresh = 0;

Window* afhds2OptionsLabel = nullptr;
Window* afhds2ProtoOpts = nullptr;
#if defined(PCBNV14)
bool hasRFPower = false;
Window* afhds2RFPowerText = nullptr;
Window* afhds2RFPowerChoice = nullptr;
#endif
Expand Down
6 changes: 6 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,11 +2063,13 @@ static void r_modSubtype(void* user, uint8_t* data, uint32_t bitoffs,
md->subType = yaml_parse_enum(enum_ISRM_Subtypes, val, val_len);
} else if (isModuleTypeR9MNonAccess(md->type)) {
md->subType = yaml_parse_enum(enum_R9M_Subtypes, val, val_len);
#if defined(AFHDS3)
} else if (md->type == MODULE_TYPE_FLYSKY_AFHDS2A) {
// Flysky sub-types have been converted into separate module types
auto sub_type = yaml_parse_enum(enum_FLYSKY_Subtypes, val, val_len);
if (sub_type == FLYSKY_SUBTYPE_AFHDS3)
md->type = MODULE_TYPE_FLYSKY_AFHDS3;
#endif
} else if (md->type == MODULE_TYPE_MULTIMODULE) {
#if defined(MULTIMODULE)
// Read type/subType by the book (see MPM documentation)
Expand Down Expand Up @@ -2128,6 +2130,10 @@ static bool w_modSubtype(void* user, uint8_t* data, uint32_t bitoffs,
str = yaml_output_enum(md->subType, enum_DSM2_Subtypes);
} else if (md->type == MODULE_TYPE_PPM) {
str = yaml_output_enum(md->subType, enum_PPM_Subtypes);
} else if (md->type == MODULE_TYPE_FLYSKY_AFHDS2A) {
str = yaml_output_enum(FLYSKY_SUBTYPE_AFHDS2A, enum_FLYSKY_Subtypes);
} else if (md->type == MODULE_TYPE_FLYSKY_AFHDS3) {
str = yaml_output_enum(FLYSKY_SUBTYPE_AFHDS3, enum_FLYSKY_Subtypes);
} else {
str = yaml_unsigned2str(val);
}
Expand Down

0 comments on commit dd87ecb

Please sign in to comment.