Skip to content

Commit

Permalink
cleanup - review comments (@CapnBry)
Browse files Browse the repository at this point in the history
  • Loading branch information
mha1 committed Nov 9, 2024
1 parent 2897abd commit 99ccab6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions radio/src/gui/128x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ static uint8_t VIEWOPT_ROW(uint8_t value) { return expandState.viewOpt ? value :
#else
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#endif
#define IF_MODULE_ARMED(module, xxx) (crossfireModuleStatus[module].isELRSV4 ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((crossfireModuleStatus[module].isELRSV4 && g_model.moduleData[module].crsf.crsfArmingMode) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED(module, xxx) (CRSF_ELRS_MIN_VER(module, 4, 0) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((CRSF_ELRS_MIN_VER(module, 4, 0) && g_model.moduleData[module].crsf.crsfArmingMode) ? (uint8_t)(xxx) : HIDDEN_ROW)
#else
#define IF_MODULE_SYNCED(module, xxx)
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx)
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/212x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ inline uint8_t EXTERNAL_MODULE_TYPE_ROW()
#else
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#endif
#define IF_MODULE_ARMED(module, xxx) (crossfireModuleStatus[module].isELRSV4 ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((crossfireModuleStatus[module].isELRSV4 && g_model.moduleData[module].crsf.crsfArmingMode) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED(module, xxx) (CRSF_ELRS_MIN_VER(module, 4, 0) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((CRSF_ELRS_MIN_VER(module, 4, 0) && g_model.moduleData[module].crsf.crsfArmingMode) ? (uint8_t)(xxx) : HIDDEN_ROW)
#else
#define IF_MODULE_SYNCED(module, xxx)
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx)
Expand Down
28 changes: 14 additions & 14 deletions radio/src/gui/colorlcd/module/crossfire_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

CrossfireSettings::CrossfireSettings(Window* parent, const FlexGridLayout& g,
uint8_t moduleIdx) :
Window(parent, rect_t{}), md(&g_model.moduleData[moduleIdx])
Window(parent, rect_t{}), md(&g_model.moduleData[moduleIdx]), moduleIdx(moduleIdx)
{
FlexGridLayout grid(g);
setFlexLayout();
Expand Down Expand Up @@ -67,33 +67,33 @@ CrossfireSettings::CrossfireSettings(Window* parent, const FlexGridLayout& g,
return std::string(msg);
});

this->moduleIdx = moduleIdx;
moduleIdx = moduleIdx;

auto armingLine = newLine(grid);
text = new StaticText(armingLine, rect_t{}, STR_ARMING_MODE);
lblArmMode = new StaticText(armingLine, rect_t{}, STR_ARMING_MODE);
auto box = new Window(armingLine, rect_t{});
box->padAll(PAD_TINY);
box->setFlexLayout(LV_FLEX_FLOW_ROW, PAD_SMALL);
choice = new Choice(box, rect_t{}, STR_CRSF_ARMING_MODES, 0, 1, GET_SET_DEFAULT(md->crsf.crsfArmingMode));
switchChoice = new SwitchChoice(box, rect_t{}, SWSRC_FIRST, SWSRC_LAST, GET_SET_DEFAULT(md->crsf.crsfArmingTrigger));
switchChoice->setAvailableHandler([=](int sw) { return isSwitchAvailableForArming(sw); });
choArmMode = new Choice(box, rect_t{}, STR_CRSF_ARMING_MODES, 0, 1, GET_SET_DEFAULT(md->crsf.crsfArmingMode));
choArmSwitch = new SwitchChoice(box, rect_t{}, SWSRC_FIRST, SWSRC_LAST, GET_SET_DEFAULT(md->crsf.crsfArmingTrigger));
choArmSwitch->setAvailableHandler([=](int sw) { return isSwitchAvailableForArming(sw); });

update();
}

void CrossfireSettings::update() {
if(crossfireModuleStatus[this->moduleIdx].isELRSV4) {
text->show();
choice->show();
if(CRSF_ELRS_MIN_VER(moduleIdx, 4, 0)) {
lblArmMode->show();
choArmMode->show();

if(md->crsf.crsfArmingMode == ARMING_MODE_SWITCH)
switchChoice->show();
choArmSwitch->show();
else
switchChoice->hide();
choArmSwitch->hide();
} else {
text->hide();
choice->hide();
switchChoice->hide();
lblArmMode->hide();
choArmMode->hide();
choArmSwitch->hide();
}
}

Expand Down
7 changes: 3 additions & 4 deletions radio/src/gui/colorlcd/module/crossfire_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ struct ModuleData;
class CrossfireSettings : public Window, public ModuleOptions
{
ModuleData* md;
StaticText *text;
Choice *choice;
SwitchChoice *switchChoice;
StaticText *lblArmMode;
Choice *choArmMode;
SwitchChoice *choArmSwitch;
uint8_t moduleIdx;
bool isELRSV4;

void checkEvents() override;
void update() override;
Expand Down
3 changes: 1 addition & 2 deletions radio/src/telemetry/crossfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ void processCrossfireTelemetryFrame(uint8_t module, uint8_t* rxBuffer,
crossfireModuleStatus[module].major = rxBuffer[14 + nameSize];
crossfireModuleStatus[module].minor = rxBuffer[15 + nameSize];
crossfireModuleStatus[module].revision = rxBuffer[16 + nameSize];
crossfireModuleStatus[module].isELRSV4 = crossfireModuleStatus[module].isELRS && crossfireModuleStatus[module].major >= 4;

if(!crossfireModuleStatus[module].isELRSV4) {
if(!CRSF_ELRS_MIN_VER(module, 4, 0) && g_model.moduleData[module].crsf.crsfArmingMode != ARMING_MODE_CH5) {
g_model.moduleData[module].crsf.crsfArmingMode = ARMING_MODE_CH5;
g_model.moduleData[module].crsf.crsfArmingTrigger = SWSRC_NONE;

Expand Down
6 changes: 5 additions & 1 deletion radio/src/telemetry/crossfire.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ struct CrossfireModuleStatus
char name[CRSF_NAME_MAXSIZE];
bool queryCompleted;
bool isELRS;
bool isELRSV4;
};

extern CrossfireModuleStatus crossfireModuleStatus[2];
Expand Down Expand Up @@ -157,6 +156,11 @@ const uint8_t CROSSFIRE_FRAME_PERIODS[] = {
% DIM(CROSSFIRE_BAUDRATES)
#endif

#define CRSF_ELRS_MIN_VER(moduleIdx, maj, min) \
(crossfireModuleStatus[moduleIdx].isELRS \
&& crossfireModuleStatus[moduleIdx].major >= maj \
&& crossfireModuleStatus[moduleIdx].minor >= min)

#if defined(HARDWARE_INTERNAL_MODULE)
#define INT_CROSSFIRE_BR_IDX CROSSFIRE_STORE_TO_INDEX(g_eeGeneral.internalModuleBaudrate)
#define INT_CROSSFIRE_BAUDRATE CROSSFIRE_BAUDRATES[INT_CROSSFIRE_BR_IDX]
Expand Down

0 comments on commit 99ccab6

Please sign in to comment.