1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 05:15:18 +03:00

[all] Issue #592 - Sticky switches: more code rewritten, more flash

saved on 9x stock. Logical Switches Delay and Duration modified on
Taranis and Sky9x
This commit is contained in:
Bertrand Songis 2014-02-03 23:20:49 +01:00
parent c2b18553ab
commit a48d76504a
14 changed files with 429 additions and 432 deletions

View file

@ -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);

View file

@ -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

View file

@ -383,7 +383,6 @@ void eeLoadModel(uint8_t id)
resumePulses();
}
activeSwitches = 0;
activeFnSwitches = 0;
activeFunctions = 0;
memclear(lastFunctionTime, sizeof(lastFunctionTime));

View file

@ -948,7 +948,6 @@ void eeLoadModel(uint8_t id)
resumePulses();
}
activeSwitches = 0;
activeFnSwitches = 0;
activeFunctions = 0;
memclear(lastFunctionTime, sizeof(lastFunctionTime));

View file

@ -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,82 +4732,73 @@ 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) {
else {
j = 4; // skip other fields
if (attr && m_posHorz > 0) {
REPEAT_LAST_CURSOR_MOVE();
}
}
break;
case 2:
if (sd->swtch) {
{
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:
{
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 (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);
#else
break;
#endif
}
#endif
#if defined(HAPTIC)
else if (CFN_FUNC(sd) == FUNC_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 (CFN_FUNC(sd) == FUNC_PLAY_TRACK || CFN_FUNC(sd) == FUNC_BACKGND_MUSIC) {
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 = (CFN_FUNC(sd) == FUNC_PLAY_TRACK ? MODEL_CUSTOM_FUNC_2ND_COLUMN + FW + FW*strlen(TR_PLAY_TRACK) : MODEL_CUSTOM_FUNC_3RD_COLUMN);
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);
@ -4826,20 +4818,20 @@ void menuModelCustomFunctions(uint8_t event)
}
break;
}
else if (CFN_FUNC(sd) == FUNC_PLAY_VALUE) {
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)
else if (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 (CFN_FUNC(sd) == FUNC_PLAY_TRACK) {
else if (func == FUNC_PLAY_TRACK) {
#if defined(GVARS)
if (attr && event==EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
@ -4857,19 +4849,19 @@ void menuModelCustomFunctions(uint8_t event)
lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed+PROMPT_CUSTOM_BASE, attr|LEFT);
#endif
}
else if (CFN_FUNC(sd) == FUNC_PLAY_BOTH) {
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 (CFN_FUNC(sd) == FUNC_PLAY_VALUE) {
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 (CFN_FUNC(sd) == FUNC_LOGS) {
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');
@ -4879,21 +4871,12 @@ void menuModelCustomFunctions(uint8_t event)
}
}
#endif
else if (CFN_FUNC(sd) == FUNC_RESET) {
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);
}
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
) {
else if (func == FUNC_ADJUST_GVAR) {
switch (CFN_GVAR_MODE(sd)) {
case FUNC_ADJUST_GVAR_CONSTANT:
val_displayed = (int8_t)CFN_PARAM(sd);
@ -4924,35 +4907,22 @@ void menuModelCustomFunctions(uint8_t event)
}
}
#endif
else {
if (attr) m_posHorz = (CURSOR_MOVED_LEFT(event) ? 1 : 3);
break;
else if (attr) {
REPEAT_LAST_CURSOR_MOVE();
}
if (active) {
CFN_PARAM(sd) = CHECK_INCDEC_PARAM(event, val_displayed, val_min, val_max);
}
}
else if (attr) {
REPEAT_LAST_CURSOR_MOVE();
}
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
#endif
#if defined(CPUARM)
// TODO #define
|| CFN_FUNC(sd) == FUNC_VOLUME
#endif
)) {
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);

View file

@ -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

View file

@ -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

View file

@ -295,7 +295,7 @@ void displayTopBar()
x -= 12;
}
if (isFunctionActive(FUNC_LOGS)) {
if (isFunctionActive(FUNCTION_LOGS)) {
LCD_NOTIF_ICON(x, ICON_LOGS);
x -= 12;
}

View file

@ -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;

View file

@ -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;

View file

@ -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 value;
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;
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 {

View file

@ -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,44 +3061,54 @@ 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; i<NUM_CHNOUT; i++)
for (uint8_t i=0; i<NUM_CHNOUT; i++) {
safetyCh[i] = -128; // not defined
}
#if defined(GVARS)
for (uint8_t i=0; i<4; i++)
for (uint8_t i=0; i<NUM_STICKS; i++)
trimGvar[i] = -1;
#endif
#if !defined(PCBSTD)
uint8_t mSwitchDurationIncremented = 0;
#endif
for (uint8_t i=0; i<NUM_CFN; i++) {
CustomFnData *sd = &g_model.funcSw[i];
int8_t swtch = sd->swtch;
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 (CFN_ACTIVE(sd)) {
if (CFN_FUNC(sd) < FUNC_TRAINER) {
safetyCh[CFN_CH_NUMBER(sd)] = CFN_PARAM(sd);
if (HAS_ENABLE_PARAM(CFN_FUNC(sd))) {
active &= CFN_ACTIVE(sd);
}
if (!(activeFunctions & function_mask)) {
if (CFN_FUNC(sd) == FUNC_INSTANT_TRIM) {
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;
}
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
@ -3105,13 +3116,9 @@ void evalFunctions()
)
instantTrim();
}
}
}
else if (CFN_FUNC(sd) <= FUNC_INSTANT_TRIM || CFN_FUNC(sd) == FUNC_RESET) {
active = false;
}
break;
if (CFN_FUNC(sd) == FUNC_RESET) {
case FUNC_RESET:
switch (CFN_PARAM(sd)) {
case FUNC_RESET_TIMER1:
case FUNC_RESET_TIMER2:
@ -3134,101 +3141,10 @@ void evalFunctions()
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);
}
break;
#endif
#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;
}
else {
active = false;
}
requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048;
break;
}
#endif
if (active) {
newActiveFnSwitches |= switch_mask;
newActiveFunctions |= function_mask;
#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<ROTARY_ENCODERS; i++)
for (uint8_t i=0; i<ROTARY_ENCODERS; i++) {
rePreviousValues[i] = (g_rotenc[i] / ROTARY_ENCODER_GRANULARITY);
}
#endif
#if defined(CPUARM)

View file

@ -1323,17 +1323,32 @@ extern int24_t act [MAX_MIXERS];
#if defined(CPUARM)
#define MASK_CFN_TYPE uint32_t // current max = 32 function switches
#define MASK_FUNC_TYPE uint32_t // current max = 32 functions
#elif defined(CPUM64)
#define MASK_CFN_TYPE uint16_t // current max = 16 function switches
#define MASK_FUNC_TYPE uint16_t // current max = 16 functions
#define MASK_FUNC_TYPE uint8_t // current max = 8 functions
#else
#define MASK_CFN_TYPE uint32_t // current max = 32 function switches
#define MASK_FUNC_TYPE uint16_t // current max = 16 functions
#define MASK_FUNC_TYPE uint8_t // current max = 8 functions
#endif
extern MASK_CFN_TYPE activeSwitches;
extern MASK_CFN_TYPE activeFnSwitches;
enum FunctionsActive {
FUNCTION_TRAINER,
FUNCTION_INSTANT_TRIM = FUNCTION_TRAINER+4,
FUNCTION_VARIO,
FUNCTION_BACKLIGHT,
#if defined(SDCARD)
FUNCTION_LOGS,
#endif
#if defined(CPUARM)
FUNCTION_BACKGND_MUSIC,
FUNCTION_BACKGND_MUSIC_PAUSE,
#endif
};
extern MASK_FUNC_TYPE activeFunctions;
extern MASK_CFN_TYPE activeFnSwitches;
extern tmr10ms_t lastFunctionTime[NUM_CFN];
#if defined(CPUARM)
@ -1342,7 +1357,7 @@ extern bool evalFunctionsFirstTime;
inline bool isFunctionActive(uint8_t func)
{
return activeFunctions & ((MASK_FUNC_TYPE)1 << (func-FUNC_TRAINER));
return activeFunctions & ((uint8_t)1 << func);
}
#if defined(ROTARY_ENCODERS)

View file

@ -175,9 +175,7 @@
#define TR_SOUND "Beep\0 "
#endif
#if defined(PCBTARANIS)
#define TR_HAPTIC
#elif defined(HAPTIC)
#if defined(HAPTIC)
#define TR_HAPTIC "Haptic\0 "
#else
#define TR_HAPTIC "[Haptic]\0 "
@ -197,7 +195,6 @@
#define TR_PLAY_VALUE "[Play Val]"
#endif
#define TR_CFN_VOLUME "Volume\0 "
#define TR_CFN_BG_MUSIC "BgMusic\0 ""BgMusic ||"
#if defined(SDCARD)
@ -206,10 +203,10 @@
#define TR_SDCLOGS "[SD Logs]\0"
#endif
#ifdef GVARS
#define TR_CFN_ADJUST_GVAR "Adjust \0 "
#if defined(GVARS)
#define TR_ADJUST_GVAR "Adjust \0 "
#else
#define TR_CFN_ADJUST_GVAR
#define TR_ADJUST_GVAR "[AdjustGV]"
#endif
#ifdef DEBUG
@ -219,11 +216,11 @@
#endif
#if defined(CPUARM)
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim" TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_CFN_VOLUME "Backlight\0" TR_CFN_BG_MUSIC TR_CFN_ADJUST_GVAR TR_CFN_TEST
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim""Reset\0 " TR_ADJUST_GVAR "Volume\0 " TR_SOUND TR_PLAY_TRACK TR_PLAY_VALUE TR_CFN_BG_MUSIC TR_VVARIO TR_HAPTIC TR_SDCLOGS "Backlight\0" TR_CFN_TEST
#elif defined(PCBGRUVIN9X)
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim" TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_BOTH TR_PLAY_VALUE TR_SDCLOGS "Backlight\0" TR_CFN_ADJUST_GVAR TR_CFN_TEST
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim""Reset\0 " TR_ADJUST_GVAR TR_SOUND TR_PLAY_TRACK TR_PLAY_BOTH TR_PLAY_VALUE TR_VVARIO TR_HAPTIC TR_SDCLOGS "Backlight\0" TR_CFN_TEST
#else
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim" TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_BOTH TR_PLAY_VALUE "Backlight\0" TR_CFN_ADJUST_GVAR TR_CFN_TEST
#define TR_VFSWFUNC "Safety\0 ""Trainer\0 ""Inst. Trim""Reset\0 " TR_ADJUST_GVAR TR_SOUND TR_PLAY_TRACK TR_PLAY_BOTH TR_PLAY_VALUE TR_VVARIO TR_HAPTIC "Backlight\0" TR_CFN_TEST
#endif
#define LEN_VFSWRESET TR("\004", "\011")