Skip to content

Commit

Permalink
fix b&w UI
Browse files Browse the repository at this point in the history
cleanup magic numbers
  • Loading branch information
mha1 committed Nov 8, 2024
1 parent 198596a commit 686d070
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ enum ModuleIndex {
SPORT_MODULE = MAX_MODULES
};

enum ArmingMode {
ARMING_MODE_FIRST = 0,
ARMING_MODE_CH5 = ARMING_MODE_FIRST,
ARMING_MODE_SWITCH = 1,
ARMING_MODE_LAST = ARMING_MODE_SWITCH,
};

enum TrainerMode {
TRAINER_MODE_OFF,
TRAINER_MODE_MASTER_TRAINER_JACK,
Expand Down
8 changes: 5 additions & 3 deletions radio/src/gui/128x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static uint8_t VIEWOPT_ROW(uint8_t value) { return expandState.viewOpt ? value :
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#endif
#define IF_MODULE_ARMED(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) (isModuleCrossfire(module) && g_model.moduleData[module].crsf.crsfArmingMode ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((isModuleCrossfire(module) && (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 Expand Up @@ -1434,7 +1434,8 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_ARMING_MODE:
#endif
g_model.moduleData[moduleIdx].crsf.crsfArmingMode =
editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_ARMING_MODE, STR_CRSF_ARMING_MODES, g_model.moduleData[moduleIdx].crsf.crsfArmingMode, 0, 1, attr, event, INDENT_WIDTH);
editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_ARMING_MODE, STR_CRSF_ARMING_MODES,
g_model.moduleData[moduleIdx].crsf.crsfArmingMode, ARMING_MODE_FIRST, ARMING_MODE_LAST, attr, event, INDENT_WIDTH);
break;

#if defined(HARDWARE_INTERNAL_MODULE)
Expand All @@ -1445,7 +1446,8 @@ void menuModelSetup(event_t event)
#endif
lcdDrawTextIndented(y, STR_SWITCH);
drawSwitch(MODEL_SETUP_2ND_COLUMN, y, g_model.moduleData[moduleIdx].crsf.crsfArmingTrigger, attr);
CHECK_INCDEC_MODELSWITCH(event, g_model.moduleData[moduleIdx].crsf.crsfArmingTrigger, SWSRC_FIRST, SWSRC_LAST, isSwitchAvailableForArming);
if(attr)
CHECK_INCDEC_SWITCH(event, g_model.moduleData[moduleIdx].crsf.crsfArmingTrigger, SWSRC_FIRST, SWSRC_LAST, EE_MODEL, isSwitchAvailableForArming);
break;
#endif

Expand Down
8 changes: 5 additions & 3 deletions radio/src/gui/212x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ inline uint8_t EXTERNAL_MODULE_TYPE_ROW()
#define IF_MODULE_BAUDRATE_ADJUST(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#endif
#define IF_MODULE_ARMED(module, xxx) (isModuleCrossfire(module) ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) (isModuleCrossfire(module) && g_model.moduleData[module].crsf.crsfArmingMode ? (uint8_t)(xxx) : HIDDEN_ROW)
#define IF_MODULE_ARMED_TRIGGER(module, xxx) ((isModuleCrossfire(module) && (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 Expand Up @@ -1279,13 +1279,15 @@ void menuModelSetup(event_t event)
#if defined(CROSSFIRE)
case ITEM_MODEL_SETUP_ARMING_MODE:
g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingMode =
editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_ARMING_MODE, STR_CRSF_ARMING_MODES, g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingMode, 0, 1, attr, event, INDENT_WIDTH);
editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_ARMING_MODE, STR_CRSF_ARMING_MODES,
g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingMode, ARMING_MODE_FIRST, ARMING_MODE_LAST, attr, event, INDENT_WIDTH);
break;

case ITEM_MODEL_SETUP_EXTERNAL_MODULE_ARMING_TRIGGER:
lcdDrawTextIndented(y, STR_SWITCH);
drawSwitch(MODEL_SETUP_2ND_COLUMN, y, g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingTrigger, attr);
CHECK_INCDEC_MODELSWITCH(event, g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingTrigger, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableForArming);
if(attr)
CHECK_INCDEC_SWITCH(event, g_model.moduleData[EXTERNAL_MODULE].crsf.crsfArmingTrigger, SWSRC_FIRST, SWSRC_LAST, EE_MODEL, isSwitchAvailableForArming);
break;
#endif

Expand Down
7 changes: 4 additions & 3 deletions radio/src/pulses/crossfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ uint8_t createCrossfireChannelsFrame(uint8_t moduleIdx, uint8_t * frame, int16_t
ModuleData *md = &g_model.moduleData[moduleIdx];

uint8_t armingMode = md->crsf.crsfArmingMode; // 0 = Channel mode, 1 = Switch mode
uint8_t lenAdjust = (armingMode == ARMING_MODE_SWITCH) ? 1 : 0;

uint8_t * buf = frame;
*buf++ = MODULE_ADDRESS;
*buf++ = 24 + armingMode ; // 1(ID) + 22(channel data) + (+1 extra byte if Switch mode) + 1(CRC)
*buf++ = 24 + lenAdjust; // 1(ID) + 22(channel data) + (+1 extra byte if Switch mode) + 1(CRC)
uint8_t * crc_start = buf;
*buf++ = CHANNELS_ID;
uint32_t bits = 0;
Expand All @@ -122,13 +123,13 @@ uint8_t createCrossfireChannelsFrame(uint8_t moduleIdx, uint8_t * frame, int16_t
}
}

if (armingMode) {
if (armingMode == ARMING_MODE_SWITCH) {
swsrc_t sw = md->crsf.crsfArmingTrigger;

*buf++ = (sw != SWSRC_NONE) && getSwitch(sw, 0); // commanded armed status in Switch mode
}

*buf++ = crc8(crc_start, 23 + armingMode);
*buf++ = crc8(crc_start, 23 + lenAdjust);
return buf - frame;
}

Expand Down

0 comments on commit 686d070

Please sign in to comment.