diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index dc16ff64a..5d2fb1be9 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -571,7 +571,7 @@ void AudioQueue::wakeup() } // mix the background context - if (!isFunctionActive(FUNC_BACKGND_MUSIC_PAUSE)) { + if (!isFunctionActive(FUNCTION_BACKGND_MUSIC_PAUSE)) { result = mixAudioContext(backgroundContext, buffer, g_eeGeneral.varioVolume, g_eeGeneral.backgroundVolume, fade); if (result > 0) { size = max(size, result); diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index b78db9acb..f06e02e09 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -435,7 +435,7 @@ void ConvertModel_215_to_216(ModelData &model) for (uint8_t i=0; i<32; i++) { g_model.funcSw[i] = oldModel.funcSw[i]; CustomFnData *sd = &g_model.funcSw[i]; - if (CFN_FUNC(sd) == FUNC_PLAY_VALUE || CFN_FUNC(sd) == FUNC_VOLUME || (IS_ADJUST_GV_FUNCTION(sd) && CFN_GVAR_MODE(sd) == FUNC_ADJUST_GVAR_SOURCE)) { + if (CFN_FUNC(sd) == FUNC_PLAY_VALUE || CFN_FUNC(sd) == FUNC_VOLUME || (IS_ADJUST_GV_FUNC(CFN_FUNC(sd)) && CFN_GVAR_MODE(sd) == FUNC_ADJUST_GVAR_SOURCE)) { #if defined(PCBTARANIS) CFN_PARAM(sd) += 1 + MAX_INPUTS + MAX_SCRIPTS*MAX_SCRIPT_OUTPUTS; #endif diff --git a/radio/src/eeprom_raw.cpp b/radio/src/eeprom_raw.cpp index 5439e89a9..718fe3558 100644 --- a/radio/src/eeprom_raw.cpp +++ b/radio/src/eeprom_raw.cpp @@ -383,7 +383,6 @@ void eeLoadModel(uint8_t id) resumePulses(); } - activeSwitches = 0; activeFnSwitches = 0; activeFunctions = 0; memclear(lastFunctionTime, sizeof(lastFunctionTime)); diff --git a/radio/src/eeprom_rlc.cpp b/radio/src/eeprom_rlc.cpp index a56834186..f6f62502e 100644 --- a/radio/src/eeprom_rlc.cpp +++ b/radio/src/eeprom_rlc.cpp @@ -948,7 +948,6 @@ void eeLoadModel(uint8_t id) resumePulses(); } - activeSwitches = 0; activeFnSwitches = 0; activeFunctions = 0; memclear(lastFunctionTime, sizeof(lastFunctionTime)); diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 3fbf74e30..a6e64c67d 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -4687,7 +4687,7 @@ void onCustomFunctionsMenu(const char *result) void menuModelCustomFunctions(uint8_t event) { - MENU(STR_MENUCUSTOMFUNC, menuTabModel, e_CustomFunctions, NUM_CFN+1, {0, NAVIGATION_LINE_BY_LINE|3/*repeated*/}); + MENU(STR_MENUCUSTOMFUNC, menuTabModel, e_CustomFunctions, NUM_CFN+1, {0, NAVIGATION_LINE_BY_LINE|4/*repeated*/}); uint8_t y; uint8_t k = 0; @@ -4720,7 +4720,8 @@ void menuModelCustomFunctions(uint8_t event) #endif CustomFnData *sd = &g_model.funcSw[k]; - for (uint8_t j=0; j<4; j++) { + uint8_t func = CFN_FUNC(sd); + for (uint8_t j=0; j<5; j++) { uint8_t attr = ((sub==k && m_posHorz==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); uint8_t active = (attr && (s_editMode>0 || p1valdiff)); switch (j) { @@ -4731,228 +4732,197 @@ void menuModelCustomFunctions(uint8_t event) case 1: if (sd->swtch) { - uint8_t func_displayed; - if (CFN_FUNC(sd) < FUNC_TRAINER) { - func_displayed = 0; - putsChn(MODEL_CUSTOM_FUNC_2ND_COLUMN+6*FW, y, CFN_CH_NUMBER(sd)+1, attr); - } - else if (CFN_FUNC(sd) <= FUNC_TRAINER + NUM_STICKS) { - func_displayed = 1; - if (CFN_FUNC(sd) != FUNC_TRAINER) - putsMixerSource(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, MIXSRC_Rud+CFN_FUNC(sd)-FUNC_TRAINER-1, attr); - } -#if defined(DEBUG) - else if (CFN_FUNC(sd) == FUNC_TEST) { -#if defined(GVARS) - func_displayed = FUNC_TEST - FUNC_TRAINER - NUM_STICKS - MAX_GVARS + 2; -#else - func_displayed = FUNC_TEST - FUNC_TRAINER - NUM_STICKS + 1; -#endif - } -#endif -#if defined(GVARS) - else if (CFN_FUNC(sd) >= FUNC_ADJUST_GV1) { - func_displayed = FUNC_ADJUST_GV1 - FUNC_TRAINER - NUM_STICKS + 1; - putsStrIdx(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, STR_GV, CFN_FUNC(sd)-FUNC_ADJUST_GV1+1, attr); - } -#endif - else { - func_displayed = 2 + CFN_FUNC(sd) - FUNC_TRAINER - NUM_STICKS - 1; - } - lcd_putsiAtt(MODEL_CUSTOM_FUNC_2ND_COLUMN, y, STR_VFSWFUNC, func_displayed, attr); + lcd_putsiAtt(MODEL_CUSTOM_FUNC_2ND_COLUMN, y, STR_VFSWFUNC, func, attr); if (active) { -#if defined(CPUARM) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_FUNC(sd), FUNC_MAX-1); -#else - if (CFN_FUNC(sd) < FUNC_TRAINER) { - CHECK_INCDEC_MODELVAR_ZERO(event, sd->internal.func_safety.func, 16); - } - else { - CHECK_INCDEC_MODELVAR_ZERO(event, CFN_FUNC(sd), FUNC_MAX-1); - if (CFN_FUNC(sd) < FUNC_TRAINER) - sd->internal.func_safety.func = 15; - } -#endif if (checkIncDec_Ret) CFN_RESET(sd); } } - else if (attr) { - REPEAT_LAST_CURSOR_MOVE(); + else { + j = 4; // skip other fields + if (attr && m_posHorz > 0) { + REPEAT_LAST_CURSOR_MOVE(); + } } break; case 2: - if (sd->swtch) { - INCDEC_DECLARE_VARS(); - int16_t val_displayed = CFN_PARAM(sd); - int8_t val_min = 0; - uint8_t val_max = 255; - if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { -#if defined(AUDIO) - val_max = AU_FRSKY_LAST-AU_FRSKY_FIRST-1; - lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_FUNCSOUNDS, val_displayed, attr); -#else - break; -#endif - } -#if defined(HAPTIC) - else if (CFN_FUNC(sd) == FUNC_HAPTIC) { - val_max = 3; - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); - } -#endif -#if defined(CPUARM) && defined(SDCARD) - else if (CFN_FUNC(sd) == FUNC_PLAY_TRACK || CFN_FUNC(sd) == FUNC_BACKGND_MUSIC) { -#if LCD_W >= 212 - xcoord_t x = MODEL_CUSTOM_FUNC_3RD_COLUMN; -#else - xcoord_t x = (CFN_FUNC(sd) == FUNC_PLAY_TRACK ? MODEL_CUSTOM_FUNC_2ND_COLUMN + FW + FW*strlen(TR_PLAY_TRACK) : MODEL_CUSTOM_FUNC_3RD_COLUMN); -#endif - if (ZEXIST(sd->param.name)) - lcd_putsnAtt(x, y, sd->param.name, sizeof(sd->param.name), attr); - else - lcd_putsiAtt(x, y, STR_VCSWFUNC, 0, attr); - if (active && event==EVT_KEY_BREAK(KEY_ENTER)) { - s_editMode = 0; - char directory[] = SOUNDS_PATH; - strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - if (listSdFiles(directory, SOUNDS_EXT, sizeof(sd->param.name), sd->param.name)) { - menuHandler = onCustomFunctionsFileSelectionMenu; - } - else { - POPUP_WARNING(STR_NO_SOUNDS_ON_SD); - s_menu_flags = 0; - } - } - break; - } - else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - val_max = MIXSRC_FIRST_TELEM + TELEM_DISPLAY_MAX - 1; - putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); - INCDEC_ENABLE_CHECK(isSourceAvailable); - } -#endif -#if defined(CPUARM) - else if (CFN_FUNC(sd) == FUNC_VOLUME) { - val_max = MIXSRC_LAST_CH; - putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); - INCDEC_ENABLE_CHECK(isSourceAvailable); - } -#elif defined(VOICE) - else if (CFN_FUNC(sd) == FUNC_PLAY_TRACK) { -#if defined(GVARS) - if (attr && event==EVT_KEY_LONG(KEY_ENTER)) { - killEvents(event); - s_editMode = !s_editMode; - active = true; - val_displayed = (val_displayed > 250 ? 0 : 251); - } - if (val_displayed > 250) { - putsStrIdx(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_GV, val_displayed-250, attr); - } - else { - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed+PROMPT_CUSTOM_BASE, attr|LEFT); - } -#else - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed+PROMPT_CUSTOM_BASE, attr|LEFT); -#endif - } - else if (CFN_FUNC(sd) == FUNC_PLAY_BOTH) { - lcd_putcAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+3*FWNUM, y, '|', attr); - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+3*FWNUM, y, val_displayed+PROMPT_CUSTOM_BASE, attr); - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+2+3*FWNUM, y, (val_displayed+PROMPT_CUSTOM_BASE+1)%10, attr|LEFT); - } - else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - val_max = MIXSRC_FIRST_TELEM + TELEM_DISPLAY_MAX - 1; - putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); - INCDEC_ENABLE_CHECK(isSourceAvailable); - } -#endif -#if defined(SDCARD) - else if (CFN_FUNC(sd) == FUNC_LOGS) { - if (val_displayed) { - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|PREC1|LEFT); - lcd_putc(lcdLastPos, y, 's'); - } - else { - lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_MMMINV, 0, attr); - } - } -#endif - else if (CFN_FUNC(sd) == FUNC_RESET) { - val_max = FUNC_RESET_PARAM_LAST; - lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_VFSWRESET, CFN_PARAM(sd), attr); - } - else if (CFN_FUNC(sd) < FUNC_TRAINER) { - val_displayed = (int8_t)CFN_PARAM(sd); - val_min = -125; val_max = 125; - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); - } -#if defined(GVARS) - else if (CFN_FUNC(sd) >= FUNC_ADJUST_GV1 -#if defined(DEBUG) - && CFN_FUNC(sd) <= FUNC_ADJUST_GVLAST -#endif - ) { - switch (CFN_GVAR_MODE(sd)) { - case FUNC_ADJUST_GVAR_CONSTANT: - val_displayed = (int8_t)CFN_PARAM(sd); - val_min = -125; val_max = 125; - lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); - break; - case FUNC_ADJUST_GVAR_SOURCE: - val_max = MIXSRC_LAST_CH; - putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); - INCDEC_ENABLE_CHECK(isSourceAvailable); - break; - case FUNC_ADJUST_GVAR_GVAR: - val_max = MAX_GVARS-1; - putsStrIdx(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_GV, val_displayed+1, attr); - break; - default: // FUNC_ADJUST_GVAR_INC - val_max = 1; - lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, PSTR("\002-1+1"), val_displayed, attr); - break; - } - - if (attr && event==EVT_KEY_LONG(KEY_ENTER)) { - killEvents(event); - s_editMode = !s_editMode; - active = true; - CFN_GVAR_MODE(sd) += 1; - val_displayed = 0; - } - } -#endif - else { - if (attr) m_posHorz = (CURSOR_MOVED_LEFT(event) ? 1 : 3); - break; - } - - if (active) { - CFN_PARAM(sd) = CHECK_INCDEC_PARAM(event, val_displayed, val_min, val_max); - } + { + int8_t maxParam = NUM_CHNOUT-1; + if (func == FUNC_SAFETY_CHANNEL) { + putsChn(MODEL_CUSTOM_FUNC_2ND_COLUMN+6*FW, y, CFN_CH_NUMBER(sd)+1, attr); } + else if (func == FUNC_TRAINER) { + maxParam = 4; + putsMixerSource(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, MIXSRC_Rud+CFN_CH_NUMBER(sd)-1, attr); + } +#if defined(GVARS) + else if (func == FUNC_ADJUST_GVAR) { + maxParam = MAX_GVARS-1; + putsStrIdx(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, STR_GV, CFN_CH_NUMBER(sd)+1, attr); + } +#endif else if (attr) { REPEAT_LAST_CURSOR_MOVE(); } + if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_CH_NUMBER(sd), maxParam); break; + } case 3: - if (sd->swtch && (CFN_FUNC(sd) <= FUNC_INSTANT_TRIM || CFN_FUNC(sd) == FUNC_RESET -#if defined(GVARS) - // TODO #define - || CFN_FUNC(sd) >= FUNC_ADJUST_GV1 + { + INCDEC_DECLARE_VARS(); + int16_t val_displayed = CFN_PARAM(sd); + int8_t val_min = 0; + uint8_t val_max = 255; + if (func == FUNC_SAFETY_CHANNEL) { + val_displayed = (int8_t)CFN_PARAM(sd); + val_min = -125; val_max = 125; + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); + } +#if defined(AUDIO) + else if (func == FUNC_PLAY_SOUND) { + val_max = AU_FRSKY_LAST-AU_FRSKY_FIRST-1; + lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_FUNCSOUNDS, val_displayed, attr); + break; + } +#endif +#if defined(HAPTIC) + else if (func == FUNC_HAPTIC) { + val_max = 3; + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); + } +#endif +#if defined(CPUARM) && defined(SDCARD) + else if (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC) { +#if LCD_W >= 212 + xcoord_t x = MODEL_CUSTOM_FUNC_3RD_COLUMN; +#else + xcoord_t x = (func == FUNC_PLAY_TRACK ? MODEL_CUSTOM_FUNC_2ND_COLUMN + FW + FW*strlen(TR_PLAY_TRACK) : MODEL_CUSTOM_FUNC_3RD_COLUMN); +#endif + if (ZEXIST(sd->param.name)) + lcd_putsnAtt(x, y, sd->param.name, sizeof(sd->param.name), attr); + else + lcd_putsiAtt(x, y, STR_VCSWFUNC, 0, attr); + if (active && event==EVT_KEY_BREAK(KEY_ENTER)) { + s_editMode = 0; + char directory[] = SOUNDS_PATH; + strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + if (listSdFiles(directory, SOUNDS_EXT, sizeof(sd->param.name), sd->param.name)) { + menuHandler = onCustomFunctionsFileSelectionMenu; + } + else { + POPUP_WARNING(STR_NO_SOUNDS_ON_SD); + s_menu_flags = 0; + } + } + break; + } + else if (func == FUNC_PLAY_VALUE) { + val_max = MIXSRC_FIRST_TELEM + TELEM_DISPLAY_MAX - 1; + putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); + INCDEC_ENABLE_CHECK(isSourceAvailable); + } #endif #if defined(CPUARM) - // TODO #define - || CFN_FUNC(sd) == FUNC_VOLUME + else if (func == FUNC_VOLUME) { + val_max = MIXSRC_LAST_CH; + putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); + INCDEC_ENABLE_CHECK(isSourceAvailable); + } +#elif defined(VOICE) + else if (func == FUNC_PLAY_TRACK) { +#if defined(GVARS) + if (attr && event==EVT_KEY_LONG(KEY_ENTER)) { + killEvents(event); + s_editMode = !s_editMode; + active = true; + val_displayed = (val_displayed > 250 ? 0 : 251); + } + if (val_displayed > 250) { + putsStrIdx(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_GV, val_displayed-250, attr); + } + else { + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed+PROMPT_CUSTOM_BASE, attr|LEFT); + } +#else + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed+PROMPT_CUSTOM_BASE, attr|LEFT); #endif - )) { + } + else if (func == FUNC_PLAY_BOTH) { + lcd_putcAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+3*FWNUM, y, '|', attr); + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+3*FWNUM, y, val_displayed+PROMPT_CUSTOM_BASE, attr); + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN+2+3*FWNUM, y, (val_displayed+PROMPT_CUSTOM_BASE+1)%10, attr|LEFT); + } + else if (func == FUNC_PLAY_VALUE) { + val_max = MIXSRC_FIRST_TELEM + TELEM_DISPLAY_MAX - 1; + putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); + INCDEC_ENABLE_CHECK(isSourceAvailable); + } +#endif +#if defined(SDCARD) + else if (func == FUNC_LOGS) { + if (val_displayed) { + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|PREC1|LEFT); + lcd_putc(lcdLastPos, y, 's'); + } + else { + lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_MMMINV, 0, attr); + } + } +#endif + else if (func == FUNC_RESET) { + val_max = FUNC_RESET_PARAM_LAST; + lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_VFSWRESET, CFN_PARAM(sd), attr); + } +#if defined(GVARS) + else if (func == FUNC_ADJUST_GVAR) { + switch (CFN_GVAR_MODE(sd)) { + case FUNC_ADJUST_GVAR_CONSTANT: + val_displayed = (int8_t)CFN_PARAM(sd); + val_min = -125; val_max = 125; + lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT); + break; + case FUNC_ADJUST_GVAR_SOURCE: + val_max = MIXSRC_LAST_CH; + putsMixerSource(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr); + INCDEC_ENABLE_CHECK(isSourceAvailable); + break; + case FUNC_ADJUST_GVAR_GVAR: + val_max = MAX_GVARS-1; + putsStrIdx(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, STR_GV, val_displayed+1, attr); + break; + default: // FUNC_ADJUST_GVAR_INC + val_max = 1; + lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, PSTR("\002-1+1"), val_displayed, attr); + break; + } + + if (attr && event==EVT_KEY_LONG(KEY_ENTER)) { + killEvents(event); + s_editMode = !s_editMode; + active = true; + CFN_GVAR_MODE(sd) += 1; + val_displayed = 0; + } + } +#endif + else if (attr) { + REPEAT_LAST_CURSOR_MOVE(); + } + + if (active) { + CFN_PARAM(sd) = CHECK_INCDEC_PARAM(event, val_displayed, val_min, val_max); + } + break; + } + + case 4: + if (func <= FUNC_INSTANT_TRIM || func == FUNC_RESET || IS_ADJUST_GV_FUNC(func) || IS_VOLUME_FUNC(func)) { menu_lcd_onoff(MODEL_CUSTOM_FUNC_4TH_COLUMN_ONOFF, y, CFN_ACTIVE(sd), attr); if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_ACTIVE(sd), 1); } - else if (sd->swtch && HAS_REPEAT_PARAM(sd)) { + else if (HAS_REPEAT_PARAM(sd)) { if (CFN_PLAY_REPEAT(sd) == 0) { #if LCD_W >= 212 lcd_putsAtt(MODEL_CUSTOM_FUNC_4TH_COLUMN+2, y, "1x", attr); diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 9277f05b3..69916bc19 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1046,6 +1046,16 @@ int16_t gvarMenuItem(uint8_t x, uint8_t y, int16_t value, int16_t min, int16_t m } #endif +void repeatLastCursorMove(uint8_t event) +{ + if (CURSOR_MOVED_LEFT(event) || CURSOR_MOVED_RIGHT(event)) { + putEvent(event); + } + else { + m_posHorz = 0; + } +} + #if LCD_W >= 212 #define MENU_X 30 #define MENU_Y 16 diff --git a/radio/src/gui/menus.h b/radio/src/gui/menus.h index 872af4fa3..15080b7f2 100644 --- a/radio/src/gui/menus.h +++ b/radio/src/gui/menus.h @@ -400,7 +400,8 @@ void pushMenuTextView(const char *filename); #define REPEAT_LAST_CURSOR_MOVE() { if (EVT_KEY_MASK(event) >= 0x0e) putEvent(event); else m_posHorz = 0; } #define MOVE_CURSOR_FROM_HERE() if (m_posHorz > 0) REPEAT_LAST_CURSOR_MOVE() #else - #define REPEAT_LAST_CURSOR_MOVE() m_posHorz = 0; + void repeatLastCursorMove(uint8_t event); + #define REPEAT_LAST_CURSOR_MOVE() repeatLastCursorMove(event) #define MOVE_CURSOR_FROM_HERE() REPEAT_LAST_CURSOR_MOVE() #endif diff --git a/radio/src/gui/view_main.cpp b/radio/src/gui/view_main.cpp index 93c6e0dfa..d618414ec 100644 --- a/radio/src/gui/view_main.cpp +++ b/radio/src/gui/view_main.cpp @@ -295,7 +295,7 @@ void displayTopBar() x -= 12; } - if (isFunctionActive(FUNC_LOGS)) { + if (isFunctionActive(FUNCTION_LOGS)) { LCD_NOTIF_ICON(x, ICON_LOGS); x -= 12; } diff --git a/radio/src/logs.cpp b/radio/src/logs.cpp index 58c47eacc..41cf29b8d 100644 --- a/radio/src/logs.cpp +++ b/radio/src/logs.cpp @@ -175,7 +175,7 @@ void writeLogs() { static const pm_char * error_displayed = NULL; - if (isFunctionActive(FUNC_LOGS) && logDelay > 0) { + if (isFunctionActive(FUNCTION_LOGS) && logDelay > 0) { tmr10ms_t tmr10ms = get_tmr10ms(); if (lastLogTime == 0 || (tmr10ms_t)(tmr10ms - lastLogTime) >= (tmr10ms_t)logDelay*10) { lastLogTime = tmr10ms; diff --git a/radio/src/maths.cpp b/radio/src/maths.cpp index 6cee8d2d7..346a7dba7 100644 --- a/radio/src/maths.cpp +++ b/radio/src/maths.cpp @@ -120,7 +120,7 @@ void varioWakeup() static tmr10ms_t s_varioTmr; tmr10ms_t tmr10ms = get_tmr10ms(); - if (isFunctionActive(FUNC_VARIO)) { + if (isFunctionActive(FUNCTION_VARIO)) { #if defined(AUDIO) cli(); int16_t verticalSpeed = frskyData.hub.varioSpeed; diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index ba75d686b..0aae1e8c5 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -693,63 +693,54 @@ PACK(typedef struct t_CustomSwData { // Custom Switches data #endif enum Functions { -#if defined(CPUARM) - FUNC_SAFETY_CH1, - FUNC_SAFETY_CH16=FUNC_SAFETY_CH1+15, -#else - FUNC_SAFETY_GROUP1, - FUNC_SAFETY_GROUP2, - FUNC_SAFETY_GROUP3, - FUNC_SAFETY_GROUP4, -#endif + // first the functions which need a checkbox + FUNC_SAFETY_CHANNEL, FUNC_TRAINER, - FUNC_TRAINER_RUD, - FUNC_TRAINER_ELE, - FUNC_TRAINER_THR, - FUNC_TRAINER_AIL, FUNC_INSTANT_TRIM, - FUNC_PLAY_SOUND, -#if !defined(PCBTARANIS) - FUNC_HAPTIC, -#endif FUNC_RESET, - FUNC_VARIO, + FUNC_ADJUST_GVAR, +#if defined(CPUARM) + FUNC_VOLUME, +#endif + + // then the other functions + FUNC_FIRST_WITHOUT_ENABLE, + FUNC_PLAY_SOUND = FUNC_FIRST_WITHOUT_ENABLE, FUNC_PLAY_TRACK, #if !defined(CPUARM) FUNC_PLAY_BOTH, #endif FUNC_PLAY_VALUE, -#if !defined(PCBSTD) - FUNC_LOGS, -#endif -#if defined(CPUARM) - FUNC_VOLUME, -#endif - FUNC_BACKLIGHT, #if defined(CPUARM) FUNC_BACKGND_MUSIC, FUNC_BACKGND_MUSIC_PAUSE, #endif -#if defined(GVARS) - FUNC_ADJUST_GV1, - FUNC_ADJUST_GVLAST = (FUNC_ADJUST_GV1 + (MAX_GVARS-1)), + FUNC_VARIO, + FUNC_HAPTIC, +#if !defined(PCBSTD) + FUNC_LOGS, #endif + FUNC_BACKLIGHT, #if defined(DEBUG) FUNC_TEST, // should remain the last before MAX as not added in companion9x #endif FUNC_MAX }; +#define HAS_ENABLE_PARAM(func) (func < FUNC_FIRST_WITHOUT_ENABLE) + #if defined(CPUARM) - #define IS_PLAY_BOTH_FUNC(sd) (0) + #define IS_PLAY_BOTH_FUNC(func) (0) + #define IS_VOLUME_FUNC(func) (func == FUNC_VOLUME) #else - #define IS_PLAY_BOTH_FUNC(sd) (CFN_FUNC(sd) == FUNC_PLAY_BOTH) + #define IS_PLAY_BOTH_FUNC(func) (func == FUNC_PLAY_BOTH) + #define IS_VOLUME_FUNC(func) (0) #endif #if defined(GVARS) - #define IS_ADJUST_GV_FUNCTION(sd) (CFN_FUNC(sd) >= FUNC_ADJUST_GV1 && CFN_FUNC(sd) <= FUNC_ADJUST_GVLAST) + #define IS_ADJUST_GV_FUNC(func) (func == FUNC_ADJUST_GVAR) #else - #define IS_ADJUST_GV_FUNCTION(sd) (0) + #define IS_ADJUST_GV_FUNC(func) (0) #endif #if defined(VOICE) @@ -814,34 +805,20 @@ PACK(typedef struct t_CustomFnData { // Function Switches data #define CFN_RESET(p) (p->active = 0, memset(&(p)->param, 0, sizeof((p)->param))) #else PACK(typedef struct t_CustomFnData { - int8_t swtch; // input - union { - struct { - uint8_t param:3; - uint8_t func:5; - } func_param; - - struct { - uint8_t active:1; - uint8_t param:2; - uint8_t func:5; - } func_param_enable; - - struct { - uint8_t active:1; - uint8_t func:7; - } func_safety; - } internal; - uint8_t param; + uint8_t value; + uint8_t func:5; + uint8_t active:1; + int16_t swtch:6; + uint8_t param:4; }) CustomFnData; -#define CFN_FUNC(p) ((p)->internal.func_param.func) -#define CFN_ACTIVE(p) ((p)->internal.func_param_enable.active) -#define CFN_CH_NUMBER(p) ((p)->internal.func_safety.func) -#define CFN_PLAY_REPEAT(p) ((p)->internal.func_param.param) +#define CFN_FUNC(p) ((p)->func) +#define CFN_ACTIVE(p) ((p)->active) +#define CFN_CH_NUMBER(p) ((p)->param) +#define CFN_PLAY_REPEAT(p) ((p)->param) #define CFN_PLAY_REPEAT_MUL 10 -#define CFN_GVAR_MODE(p) ((p)->internal.func_param_enable.param) -#define CFN_PARAM(p) ((p)->param) -#define CFN_RESET(p) ((p)->internal.func_param_enable.active = 0, CFN_PARAM(p) = 0) +#define CFN_GVAR_MODE(p) ((p)->param) +#define CFN_PARAM(p) ((p)->value) +#define CFN_RESET(p) ((p)->active = 0, CFN_PARAM(p) = 0) #endif enum TelemetryUnit { diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 27dd80868..f8a4eb4f5 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1531,15 +1531,17 @@ bool getSwitch(int8_t swtch) cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*50); } } + if (cs->duration) { - if (result && !cswStates[cs_idx]) + if (result && !cswStates[cs_idx]) { cswDurations[cs_idx] = get_tmr10ms() + (cs->duration*50); + } cswStates[cs_idx] = result; + result = false; if (cswDurations[cs_idx] > get_tmr10ms()) { result = true; - if (cs->delay) cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*50); } } #endif @@ -2031,7 +2033,7 @@ void checkBacklight() backlightOn(); } - bool backlightOn = (g_eeGeneral.backlightMode == e_backlight_mode_on || lightOffCounter || isFunctionActive(FUNC_BACKLIGHT)); + bool backlightOn = (g_eeGeneral.backlightMode == e_backlight_mode_on || lightOffCounter || isFunctionActive(FUNCTION_BACKLIGHT)); if (flashCounter) backlightOn = !backlightOn; if (backlightOn) BACKLIGHT_ON(); @@ -2841,7 +2843,7 @@ void evalInputs(uint8_t mode) } if (ch < NUM_STICKS) { //only do this for sticks - if (mode <= e_perout_mode_inactive_phase && (isFunctionActive(FUNC_TRAINER) || isFunctionActive(FUNC_TRAINER_RUD+ch))) { + if (mode <= e_perout_mode_inactive_phase && isFunctionActive(FUNCTION_TRAINER+ch)) { // trainer mode TrainerMix* td = &g_eeGeneral.trainer.mix[ch]; if (td->mode) { @@ -2899,7 +2901,6 @@ void testFunc() #endif MASK_FUNC_TYPE activeFunctions = 0; -MASK_CFN_TYPE activeSwitches = 0; MASK_CFN_TYPE activeFnSwitches = 0; tmr10ms_t lastFunctionTime[NUM_CFN] = { 0 }; @@ -3060,175 +3061,90 @@ bool evalFunctionsFirstTime = true; void evalFunctions() { MASK_FUNC_TYPE newActiveFunctions = 0; - MASK_CFN_TYPE newActiveSwitches = 0; MASK_CFN_TYPE newActiveFnSwitches = 0; #if defined(ROTARY_ENCODERS) && defined(GVARS) static rotenc_t rePreviousValues[ROTARY_ENCODERS]; #endif - for (uint8_t i=0; iswtch; if (swtch) { - MASK_FUNC_TYPE function_mask = (CFN_FUNC(sd) >= FUNC_TRAINER ? ((MASK_FUNC_TYPE)1 << (CFN_FUNC(sd)-FUNC_TRAINER)) : 0); MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i); bool active = getSwitch(swtch); - if (active) newActiveSwitches |= switch_mask; - if (active || IS_PLAY_BOTH_FUNC(sd)) { + if (HAS_ENABLE_PARAM(CFN_FUNC(sd))) { + active &= CFN_ACTIVE(sd); + } - if (CFN_ACTIVE(sd)) { - if (CFN_FUNC(sd) < FUNC_TRAINER) { + if (active || IS_PLAY_BOTH_FUNC(CFN_FUNC(sd))) { + + switch(CFN_FUNC(sd)) { + + case FUNC_SAFETY_CHANNEL: safetyCh[CFN_CH_NUMBER(sd)] = CFN_PARAM(sd); + break; + + case FUNC_TRAINER: + { + uint8_t mask = 0x0f; + if (CFN_CH_NUMBER(sd) > 0) { + mask = (1<<(CFN_CH_NUMBER(sd)-1)); + } + newActiveFunctions |= mask; + break; } - if (!(activeFunctions & function_mask)) { - if (CFN_FUNC(sd) == FUNC_INSTANT_TRIM) { + case FUNC_INSTANT_TRIM: + if (!isFunctionActive(FUNCTION_INSTANT_TRIM)) { + newActiveFunctions |= (1 << FUNCTION_INSTANT_TRIM); if (g_menuStack[0] == menuMainView #if defined(FRSKY) || g_menuStack[0] == menuTelemetryFrsky #endif - ) + ) instantTrim(); } - } - } - else if (CFN_FUNC(sd) <= FUNC_INSTANT_TRIM || CFN_FUNC(sd) == FUNC_RESET) { - active = false; - } + break; - if (CFN_FUNC(sd) == FUNC_RESET) { - switch (CFN_PARAM(sd)) { - case FUNC_RESET_TIMER1: - case FUNC_RESET_TIMER2: - resetTimer(CFN_PARAM(sd)); - break; - case FUNC_RESET_ALL: - resetAll(); - break; + case FUNC_RESET: + switch (CFN_PARAM(sd)) { + case FUNC_RESET_TIMER1: + case FUNC_RESET_TIMER2: + resetTimer(CFN_PARAM(sd)); + break; + case FUNC_RESET_ALL: + resetAll(); + break; #if defined(FRSKY) - case FUNC_RESET_TELEMETRY: - resetTelemetry(); - break; + case FUNC_RESET_TELEMETRY: + resetTelemetry(); + break; #endif #if ROTARY_ENCODERS > 0 - case FUNC_RESET_ROTENC1: + case FUNC_RESET_ROTENC1: #if ROTARY_ENCODERS > 1 - case FUNC_RESET_ROTENC2: + case FUNC_RESET_ROTENC2: #endif - g_rotenc[CFN_PARAM(sd)-FUNC_RESET_ROTENC1] = 0; - break; + g_rotenc[CFN_PARAM(sd)-FUNC_RESET_ROTENC1] = 0; + break; #endif - } - } - -#if defined(SDCARD) - else if (CFN_FUNC(sd) == FUNC_LOGS) { - logDelay = CFN_PARAM(sd); - } -#endif - -#if defined(HAPTIC) - else if (CFN_FUNC(sd) == FUNC_HAPTIC) { - haptic.event(AU_FRSKY_LAST+CFN_PARAM(sd)); - } -#endif - -#if defined(CPUARM) && defined(SDCARD) - else if (CFN_FUNC(sd) == FUNC_PLAY_SOUND || CFN_FUNC(sd) == FUNC_PLAY_TRACK || CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t repeatParam = CFN_PLAY_REPEAT(sd); - if (evalFunctionsFirstTime && repeatParam == CFN_PLAY_REPEAT_NOSTART) - lastFunctionTime[i] = tmr10ms; - if (!lastFunctionTime[i] || (repeatParam && repeatParam!=CFN_PLAY_REPEAT_NOSTART && (signed)(tmr10ms-lastFunctionTime[i])>=100*repeatParam)) { - if (!IS_PLAYING(i+1)) { - lastFunctionTime[i] = tmr10ms; - if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { - AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(sd)); - } - else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - PLAY_VALUE(CFN_PARAM(sd), i+1); - } - else { - playCustomFunctionFile(sd, i+1); - } } - } - } - else if (CFN_FUNC(sd) == FUNC_BACKGND_MUSIC) { - if (!IS_PLAYING(i+1)) { - playCustomFunctionFile(sd, i+1); - } - } - else if (CFN_FUNC(sd) == FUNC_VOLUME) { - if (CFN_ACTIVE(sd)) { - getvalue_t raw = getValue(CFN_PARAM(sd)); - //only set volume if input changed more than hysteresis - if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) { - requiredSpeakerVolumeRawLast = raw; - } - requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048; - } - else { - active = false; - } - } -#elif defined(VOICE) - else if (CFN_FUNC(sd) == FUNC_PLAY_SOUND || CFN_FUNC(sd) == FUNC_PLAY_TRACK || CFN_FUNC(sd) == FUNC_PLAY_BOTH || CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t repeatParam = CFN_PLAY_REPEAT(sd); - if (!lastFunctionTime[i] || (CFN_FUNC(sd)==FUNC_PLAY_BOTH && active!=(bool)(activeFnSwitches&switch_mask)) || (repeatParam && (signed)(tmr10ms-lastFunctionTime[i])>=1000*repeatParam)) { - lastFunctionTime[i] = tmr10ms; - uint8_t param = CFN_PARAM(sd); - if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { - AUDIO_PLAY(AU_FRSKY_FIRST+param); - } - else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { - PLAY_VALUE(param, i+1); - } - else { -#if defined(GVARS) - if (CFN_FUNC(sd) == FUNC_PLAY_TRACK && param > 250) - param = GVAR_VALUE(param-251, getGVarFlightPhase(s_perout_flight_phase, param-251)); -#endif - PUSH_CUSTOM_PROMPT(active ? param : param+1, i+1); - } - } - } -#else - else if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { - tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t repeatParam = CFN_PLAY_REPEAT(sd); - if (!lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-lastFunctionTime[i])>=1000*repeatParam)) { - lastFunctionTime[i] = tmr10ms; - AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(sd)); - } - } -#endif - -#if defined(DEBUG) - else if (CFN_FUNC(sd) == FUNC_TEST) { - testFunc(); - } -#endif + break; #if defined(GVARS) - else if (CFN_FUNC(sd) >= FUNC_ADJUST_GV1) { - if (CFN_ACTIVE(sd)) { + case FUNC_ADJUST_GVAR: if (CFN_GVAR_MODE(sd) == 0) { SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, CFN_PARAM(sd), s_perout_flight_phase); } @@ -3254,17 +3170,130 @@ void evalFunctions() else { SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, limit((getvalue_t)-1250, getValue(CFN_PARAM(sd)), (getvalue_t)1250) / 10, s_perout_flight_phase); } - } - else { - active = false; - } - } + break; #endif - if (active) { - newActiveFnSwitches |= switch_mask; - newActiveFunctions |= function_mask; +#if defined(CPUARM) && defined(SDCARD) + case FUNC_VOLUME: + { + getvalue_t raw = getValue(CFN_PARAM(sd)); + //only set volume if input changed more than hysteresis + if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) { + requiredSpeakerVolumeRawLast = raw; + } + requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048; + break; + } +#endif + +#if defined(CPUARM) && defined(SDCARD) + case FUNC_PLAY_SOUND: + case FUNC_PLAY_TRACK: + case FUNC_PLAY_VALUE: + { + tmr10ms_t tmr10ms = get_tmr10ms(); + uint8_t repeatParam = CFN_PLAY_REPEAT(sd); + if (evalFunctionsFirstTime && repeatParam == CFN_PLAY_REPEAT_NOSTART) + lastFunctionTime[i] = tmr10ms; + if (!lastFunctionTime[i] || (repeatParam && repeatParam!=CFN_PLAY_REPEAT_NOSTART && (signed)(tmr10ms-lastFunctionTime[i])>=100*repeatParam)) { + if (!IS_PLAYING(i+1)) { + lastFunctionTime[i] = tmr10ms; + if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { + AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(sd)); + } + else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { + PLAY_VALUE(CFN_PARAM(sd), i+1); + } + else { + playCustomFunctionFile(sd, i+1); + } + } + } + break; + } + + case FUNC_BACKGND_MUSIC: + newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC); + if (!IS_PLAYING(i+1)) { + playCustomFunctionFile(sd, i+1); + } + break; + + case FUNC_BACKGND_MUSIC_PAUSE: + newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC_PAUSE); + break; + +#elif defined(VOICE) + case FUNC_PLAY_SOUND: + case FUNC_PLAY_TRACK: + case FUNC_PLAY_BOTH: + case FUNC_PLAY_VALUE: + { + tmr10ms_t tmr10ms = get_tmr10ms(); + uint8_t repeatParam = CFN_PLAY_REPEAT(sd); + if (!lastFunctionTime[i] || (CFN_FUNC(sd)==FUNC_PLAY_BOTH && active!=(bool)(activeFnSwitches&switch_mask)) || (repeatParam && (signed)(tmr10ms-lastFunctionTime[i])>=1000*repeatParam)) { + lastFunctionTime[i] = tmr10ms; + uint8_t param = CFN_PARAM(sd); + if (CFN_FUNC(sd) == FUNC_PLAY_SOUND) { + AUDIO_PLAY(AU_FRSKY_FIRST+param); + } + else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) { + PLAY_VALUE(param, i+1); + } + else { +#if defined(GVARS) + if (CFN_FUNC(sd) == FUNC_PLAY_TRACK && param > 250) + param = GVAR_VALUE(param-251, getGVarFlightPhase(s_perout_flight_phase, param-251)); +#endif + PUSH_CUSTOM_PROMPT(active ? param : param+1, i+1); + } + } + break; + } +#else + case FUNC_PLAY_SOUND: + { + tmr10ms_t tmr10ms = get_tmr10ms(); + uint8_t repeatParam = CFN_PLAY_REPEAT(sd); + if (!lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-lastFunctionTime[i])>=1000*repeatParam)) { + lastFunctionTime[i] = tmr10ms; + AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(sd)); + } + break; + } +#endif + +#if defined(FRSKY) && defined(VARIO) + case FUNC_VARIO: + newActiveFunctions |= (1 << FUNCTION_VARIO); + break; +#endif + +#if defined(HAPTIC) + case FUNC_HAPTIC: + haptic.event(AU_FRSKY_LAST+CFN_PARAM(sd)); + break; +#endif + +#if defined(SDCARD) + case FUNC_LOGS: + newActiveFunctions |= (1 << FUNCTION_LOGS); + logDelay = CFN_PARAM(sd); + break; +#endif + + case FUNC_BACKLIGHT: + newActiveFunctions |= (1 << FUNCTION_BACKLIGHT); + break; + +#if defined(DEBUG) + case FUNC_TEST: + testFunc(); + break; +#endif } + + newActiveFnSwitches |= switch_mask; } else { lastFunctionTime[i] = 0; @@ -3272,7 +3301,7 @@ void evalFunctions() fnSwitchDuration[i] = 0; #endif #if defined(CPUARM) && defined(SDCARD) - if (CFN_FUNC(sd) == FUNC_BACKGND_MUSIC && isFunctionActive(FUNC_BACKGND_MUSIC)) { + if (CFN_FUNC(sd) == FUNC_BACKGND_MUSIC && isFunctionActive(FUNCTION_BACKGND_MUSIC)) { STOP_PLAY(i+1); } #endif @@ -3280,13 +3309,13 @@ void evalFunctions() } } - activeSwitches = newActiveSwitches; activeFnSwitches = newActiveFnSwitches; activeFunctions = newActiveFunctions; #if defined(ROTARY_ENCODERS) && defined(GVARS) - for (uint8_t i=0; i