chore(bw): refactor and cleanup of code (#6481)

This commit is contained in:
philmoz
2025-10-18 15:08:44 +10:00
committed by GitHub
parent 9cd42ee9bd
commit e904da89e7
76 changed files with 1523 additions and 2792 deletions
+24 -22
View File
@@ -39,14 +39,28 @@ enum MenuModelHeliItems {
#define MODEL_HELI_2ND_COLUMN (14*FW)
#endif
static int numberField(const char* name, coord_t y, int val, int min, LcdFlags attr, event_t event)
{
return editNumberField(name, INDENT_WIDTH, MODEL_HELI_2ND_COLUMN, y, val, min, 100, attr, event);
}
static uint8_t sourceField(const char* name, coord_t y, uint8_t val, LcdFlags attr, event_t event)
{
lcdDrawTextAlignedLeft(y, name);
drawSource(MODEL_HELI_2ND_COLUMN, y, val, attr);
if (attr) CHECK_INCDEC_MODELSOURCE(event, val, 0, MIXSRC_LAST_CH);
return val;
}
void menuModelHeli(event_t event)
{
SIMPLE_MENU(STR_MENUHELISETUP, menuTabModel, MENU_MODEL_HELI, HEADER_LINE+ITEM_HELI_MAX);
uint8_t sub = menuVerticalPosition - HEADER_LINE;
coord_t y = MENU_HEADER_HEIGHT + 1;
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH;
uint8_t k = i + menuVerticalOffset;
LcdFlags blink = (s_editMode > 0 ? BLINK|INVERS : INVERS);
LcdFlags attr = (sub == k ? blink : 0);
@@ -57,46 +71,34 @@ void menuModelHeli(event_t event)
break;
case ITEM_HELI_SWASHRING:
lcdDrawTextAlignedLeft(y, STR_SWASHRING);
lcdDrawNumber(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.value, LEFT|attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.swashR.value, 100);
g_model.swashR.value = numberField(STR_SWASHRING, y, g_model.swashR.value, 0, attr, event);
break;
case ITEM_HELI_ELE:
lcdDrawTextAlignedLeft(y, STR_ELEVATOR);
drawSource(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.elevatorSource, attr);
if (attr) CHECK_INCDEC_MODELSOURCE(event, g_model.swashR.elevatorSource, 0, MIXSRC_LAST_CH);
g_model.swashR.elevatorSource = sourceField(STR_ELEVATOR, y, g_model.swashR.elevatorSource, attr, event);
break;
case ITEM_HELI_ELE_WEIGHT:
lcdDrawTextIndented(y, STR_WEIGHT);
lcdDrawNumber(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.elevatorWeight, LEFT|attr);
if (attr) CHECK_INCDEC_MODELVAR(event, g_model.swashR.elevatorWeight, -100, 100);
g_model.swashR.elevatorWeight = numberField(STR_WEIGHT, y, g_model.swashR.elevatorWeight, -100, attr, event);
break;
case ITEM_HELI_AIL:
lcdDrawTextAlignedLeft(y, STR_AILERON);
drawSource(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.aileronSource, attr);
if (attr) CHECK_INCDEC_MODELSOURCE(event, g_model.swashR.aileronSource, 0, MIXSRC_LAST_CH);
g_model.swashR.aileronSource = sourceField(STR_AILERON, y, g_model.swashR.aileronSource, attr, event);
break;
case ITEM_HELI_AIL_WEIGHT:
lcdDrawTextIndented(y, STR_WEIGHT);
lcdDrawNumber(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.aileronWeight, LEFT|attr);
if (attr) CHECK_INCDEC_MODELVAR(event, g_model.swashR.aileronWeight, -100, 100);
g_model.swashR.aileronWeight = numberField(STR_WEIGHT, y, g_model.swashR.aileronWeight, -100, attr, event);
break;
case ITEM_HELI_COL:
lcdDrawTextAlignedLeft(y, STR_COLLECTIVE);
drawSource(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.collectiveSource, attr);
if (attr) CHECK_INCDEC_MODELSOURCE(event, g_model.swashR.collectiveSource, 0, MIXSRC_LAST_CH);
g_model.swashR.collectiveSource = sourceField(STR_COLLECTIVE, y, g_model.swashR.collectiveSource, attr, event);
break;
case ITEM_HELI_COL_WEIGHT:
lcdDrawTextIndented(y, STR_WEIGHT);
lcdDrawNumber(MODEL_HELI_2ND_COLUMN, y, g_model.swashR.collectiveWeight, LEFT|attr);
if (attr) CHECK_INCDEC_MODELVAR(event, g_model.swashR.collectiveWeight, -100, 100);
g_model.swashR.collectiveWeight = numberField(STR_WEIGHT, y, g_model.swashR.collectiveWeight, -100, attr, event);
break;
}
y += FH;
}
}