Rotary encoder refactoring

This commit is contained in:
Bertrand Songis
2019-04-30 14:55:21 +02:00
parent 4f6828aa1c
commit c28210e3e4
60 changed files with 363 additions and 652 deletions
+3 -35
View File
@@ -36,7 +36,6 @@ enum MenuModelFlightModeItems {
ITEM_MODEL_FLIGHT_MODE_NAME,
ITEM_MODEL_FLIGHT_MODE_SWITCH,
ITEM_MODEL_FLIGHT_MODE_TRIMS,
IF_ROTARY_ENCODERS(ITEM_MODEL_FLIGHT_MODE_ROTARY_ENCODERS)
ITEM_MODEL_FLIGHT_MODE_FADE_IN,
ITEM_MODEL_FLIGHT_MODE_FADE_OUT,
#if defined(GVARS)
@@ -72,7 +71,7 @@ void menuModelFlightModeOne(event_t event)
#define VERTICAL_SHIFT (ITEM_MODEL_FLIGHT_MODE_FADE_IN-ITEM_MODEL_FLIGHT_MODE_SWITCH)
static const uint8_t mstate_tab_fm1[] = {0, 0, 0, (uint8_t)-1, 1, 1, 1, 1, 1};
#endif
static const uint8_t mstate_tab_others[] = {0, 0, 3, IF_ROTARY_ENCODERS(NUM_ROTARY_ENCODERS-1) 0, 0, (uint8_t)-1, 2, 2, 2, 2, 2};
static const uint8_t mstate_tab_others[] = {0, 0, 3, 0, 0, (uint8_t)-1, 2, 2, 2, 2, 2};
check(event, 0, NULL, 0, (s_currIdx == 0) ? mstate_tab_fm1 : mstate_tab_others, DIM(mstate_tab_others)-1, ITEM_MODEL_FLIGHT_MODE_MAX - HEADER_LINE - (s_currIdx==0 ? (ITEM_MODEL_FLIGHT_MODE_FADE_IN-ITEM_MODEL_FLIGHT_MODE_SWITCH-1) : 0));
@@ -80,7 +79,7 @@ void menuModelFlightModeOne(event_t event)
#define PHASE_ONE_FIRST_LINE (1+1*FH)
#else
SUBMENU(STR_MENUFLIGHTMODE, 3 + (s_currIdx==0 ? 0 : 2 + (bool)NUM_ROTARY_ENCODERS), {0, 0, 3, IF_ROTARY_ENCODERS(NUM_ROTARY_ENCODERS-1) 0/*, 0*/});
SUBMENU(STR_MENUFLIGHTMODE, 3 + (s_currIdx==0 ? 0 : 2), {0, 0, 3, 0/*, 0*/});
#define PHASE_ONE_FIRST_LINE (1+1*FH)
#endif
@@ -121,24 +120,6 @@ void menuModelFlightModeOne(event_t event)
}
break;
#if ROTARY_ENCODERS > 0
case ITEM_MODEL_FLIGHT_MODE_ROTARY_ENCODERS:
lcdDrawTextAlignedLeft(y, STR_ROTARY_ENCODER);
for (uint8_t t=0; t<NUM_ROTARY_ENCODERS; t++) {
putsRotaryEncoderMode(MIXES_2ND_COLUMN+(t*FW), y, s_currIdx, t, menuHorizontalPosition==t ? attr : 0);
if (attr && menuHorizontalPosition == t && editMode > 0) {
int16_t v = flightModeAddress(s_currIdx)->rotaryEncoders[t];
if (v < ROTARY_ENCODER_MAX) v = ROTARY_ENCODER_MAX;
v = checkIncDec(event, v, ROTARY_ENCODER_MAX, ROTARY_ENCODER_MAX+MAX_FLIGHT_MODES-1, EE_MODEL);
if (checkIncDec_Ret) {
if (v == ROTARY_ENCODER_MAX) v = 0;
flightModeAddress(s_currIdx)->rotaryEncoders[t] = v;
}
}
}
break;
#endif
case ITEM_MODEL_FLIGHT_MODE_FADE_IN:
fm->fadeIn = EDIT_DELAY(0, y, event, attr, STR_FADEIN, fm->fadeIn);
break;
@@ -191,19 +172,7 @@ void menuModelFlightModeOne(event_t event)
}
}
#if defined(ROTARY_ENCODERS)
#if ROTARY_ENCODERS > 2
#define NAME_OFS (-4-12)
#define SWITCH_OFS (-FW/2-2-13)
#define TRIMS_OFS (-FW/2-4-15)
#define ROTARY_ENC_OFS (0)
#else
#define NAME_OFS (-4)
#define SWITCH_OFS (-FW/2-2)
#define TRIMS_OFS (-FW/2-4)
#define ROTARY_ENC_OFS (2)
#endif
#elif defined(PCBTARANIS)
#if defined(PCBTARANIS)
#define NAME_POS 20
#define SWITCH_POS 59
#define TRIMS_POS 79
@@ -220,7 +189,6 @@ void menuModelFlightModesAll(event_t event)
int8_t sub = menuVerticalPosition - HEADER_LINE;
switch (event) {
CASE_EVT_ROTARY_BREAK
case EVT_KEY_FIRST(KEY_ENTER):
if (sub == MAX_FLIGHT_MODES) {
s_editMode = 0;