mirror of
https://github.com/opentx/opentx.git
synced 2025-07-22 15:55:26 +03:00
[all] Issue #592 - Corrections (GVARS)
This commit is contained in:
parent
98eb42a77c
commit
9c82e62cc7
4 changed files with 68 additions and 50 deletions
|
@ -4640,14 +4640,14 @@ void onCustomFunctionsFileSelectionMenu(const char *result)
|
||||||
if (result == STR_UPDATE_LIST) {
|
if (result == STR_UPDATE_LIST) {
|
||||||
char directory[] = SOUNDS_PATH;
|
char directory[] = SOUNDS_PATH;
|
||||||
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||||
if (!listSdFiles(directory, SOUNDS_EXT, sizeof(g_model.funcSw[sub].param), NULL)) {
|
if (!listSdFiles(directory, SOUNDS_EXT, sizeof(g_model.funcSw[sub].play.name), NULL)) {
|
||||||
POPUP_WARNING(STR_NO_SOUNDS_ON_SD);
|
POPUP_WARNING(STR_NO_SOUNDS_ON_SD);
|
||||||
s_menu_flags = 0;
|
s_menu_flags = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// The user choosed a wav file in the list
|
// The user choosed a wav file in the list
|
||||||
memcpy(g_model.funcSw[sub].param.name, result, sizeof(g_model.funcSw[sub].param.name));
|
memcpy(g_model.funcSw[sub].play.name, result, sizeof(g_model.funcSw[sub].play.name));
|
||||||
eeDirty(EE_MODEL);
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4726,12 +4726,12 @@ void menuModelCustomFunctions(uint8_t event)
|
||||||
uint8_t active = (attr && (s_editMode>0 || p1valdiff));
|
uint8_t active = (attr && (s_editMode>0 || p1valdiff));
|
||||||
switch (j) {
|
switch (j) {
|
||||||
case 0:
|
case 0:
|
||||||
putsSwitches(MODEL_CUSTOM_FUNC_1ST_COLUMN, y, sd->swtch, attr | ((activeFnSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
|
putsSwitches(MODEL_CUSTOM_FUNC_1ST_COLUMN, y, CFN_SWITCH(sd), attr | ((activeFnSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
|
||||||
if (active || AUTOSWITCH_ENTER_LONG()) CHECK_INCDEC_MODELSWITCH(event, sd->swtch, SWSRC_FIRST, SWSRC_LAST);
|
if (active || AUTOSWITCH_ENTER_LONG()) CHECK_INCDEC_MODELSWITCH(event, CFN_SWITCH(sd), SWSRC_FIRST, SWSRC_LAST);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if (sd->swtch) {
|
if (CFN_SWITCH(sd)) {
|
||||||
lcd_putsiAtt(MODEL_CUSTOM_FUNC_2ND_COLUMN, y, STR_VFSWFUNC, func, attr);
|
lcd_putsiAtt(MODEL_CUSTOM_FUNC_2ND_COLUMN, y, STR_VFSWFUNC, func, attr);
|
||||||
if (active) {
|
if (active) {
|
||||||
CHECK_INCDEC_MODELVAR_ZERO(event, CFN_FUNC(sd), FUNC_MAX-1);
|
CHECK_INCDEC_MODELVAR_ZERO(event, CFN_FUNC(sd), FUNC_MAX-1);
|
||||||
|
@ -4740,7 +4740,7 @@ void menuModelCustomFunctions(uint8_t event)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j = 4; // skip other fields
|
j = 4; // skip other fields
|
||||||
if (attr && m_posHorz > 0) {
|
if (sub==k && m_posHorz > 0) {
|
||||||
REPEAT_LAST_CURSOR_MOVE();
|
REPEAT_LAST_CURSOR_MOVE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4763,7 +4763,9 @@ void menuModelCustomFunctions(uint8_t event)
|
||||||
#if defined(GVARS)
|
#if defined(GVARS)
|
||||||
else if (func == FUNC_ADJUST_GVAR) {
|
else if (func == FUNC_ADJUST_GVAR) {
|
||||||
maxParam = MAX_GVARS-1;
|
maxParam = MAX_GVARS-1;
|
||||||
putsStrIdx(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, STR_GV, CFN_CH_NUMBER(sd)+1, attr);
|
putsStrIdx(MODEL_CUSTOM_FUNC_2ND_COLUMN+7*FW, y, STR_GV, CFN_GVAR_NUMBER(sd)+1, attr);
|
||||||
|
if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_GVAR_NUMBER(sd), maxParam);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (attr) {
|
else if (attr) {
|
||||||
|
@ -4804,15 +4806,15 @@ void menuModelCustomFunctions(uint8_t event)
|
||||||
#else
|
#else
|
||||||
xcoord_t x = (func == 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
|
#endif
|
||||||
if (ZEXIST(sd->param.name))
|
if (ZEXIST(sd->play.name))
|
||||||
lcd_putsnAtt(x, y, sd->param.name, sizeof(sd->param.name), attr);
|
lcd_putsnAtt(x, y, sd->play.name, sizeof(sd->play.name), attr);
|
||||||
else
|
else
|
||||||
lcd_putsiAtt(x, y, STR_VCSWFUNC, 0, attr);
|
lcd_putsiAtt(x, y, STR_VCSWFUNC, 0, attr);
|
||||||
if (active && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
if (active && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
||||||
s_editMode = 0;
|
s_editMode = 0;
|
||||||
char directory[] = SOUNDS_PATH;
|
char directory[] = SOUNDS_PATH;
|
||||||
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||||
if (listSdFiles(directory, SOUNDS_EXT, sizeof(sd->param.name), sd->param.name)) {
|
if (listSdFiles(directory, SOUNDS_EXT, sizeof(sd->play.name), sd->play.name)) {
|
||||||
menuHandler = onCustomFunctionsFileSelectionMenu;
|
menuHandler = onCustomFunctionsFileSelectionMenu;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4922,7 +4924,7 @@ void menuModelCustomFunctions(uint8_t event)
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if (func <= FUNC_INSTANT_TRIM || func == FUNC_RESET || IS_ADJUST_GV_FUNC(func) || IS_VOLUME_FUNC(func)) {
|
if (HAS_ENABLE_PARAM(func)) {
|
||||||
menu_lcd_onoff(MODEL_CUSTOM_FUNC_4TH_COLUMN_ONOFF, y, CFN_ACTIVE(sd), attr);
|
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);
|
if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_ACTIVE(sd), 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1043,16 +1043,6 @@ void putsSwitches(xcoord_t x, uint8_t y, int8_t idx, LcdFlags att)
|
||||||
lcd_vlineStip(x-2, y, 8, 0x5E/*'!'*/);
|
lcd_vlineStip(x-2, y, 8, 0x5E/*'!'*/);
|
||||||
idx = -idx;
|
idx = -idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ROTARY_ENCODERS > 0
|
|
||||||
else if (idx >= SWSRC_FIRST_ROTENC_SWITCH) {
|
|
||||||
idx -= SWSRC_FIRST_ROTENC_SWITCH;
|
|
||||||
char suffix = (idx & 1) ? CHR_LONG : CHR_SHORT;
|
|
||||||
lcd_putsiAtt(x, y, STR_VRENCODERS, idx/2, att);
|
|
||||||
return lcd_putcAtt(lcdLastPos, y, suffix, att);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att);
|
lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -783,42 +783,68 @@ PACK(typedef struct t_CustomFnData { // Function Switches data
|
||||||
int8_t swtch;
|
int8_t swtch;
|
||||||
uint8_t func;
|
uint8_t func;
|
||||||
PACK(union {
|
PACK(union {
|
||||||
|
struct {
|
||||||
char name[LEN_CFN_NAME];
|
char name[LEN_CFN_NAME];
|
||||||
|
} play;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int16_t val;
|
int16_t val;
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
uint8_t spare1;
|
uint8_t param;
|
||||||
int16_t spare2;
|
int16_t spare2;
|
||||||
} composite;
|
} all;
|
||||||
}) param;
|
|
||||||
|
struct {
|
||||||
|
int32_t val1;
|
||||||
|
int16_t val2;
|
||||||
|
} clear;
|
||||||
|
});
|
||||||
uint8_t active;
|
uint8_t active;
|
||||||
}) CustomFnData;
|
}) CustomFnData;
|
||||||
#define CFN_EMPTY(p) (!(p)->swtch)
|
#define CFN_EMPTY(p) (!(p)->swtch)
|
||||||
|
#define CFN_SWITCH(p) ((p)->swtch)
|
||||||
#define CFN_FUNC(p) ((p)->func)
|
#define CFN_FUNC(p) ((p)->func)
|
||||||
#define CFN_ACTIVE(p) ((p)->active)
|
#define CFN_ACTIVE(p) ((p)->active)
|
||||||
#define CFN_CH_NUMBER(p) ((p)->param.composite.mode)
|
#define CFN_CH_NUMBER(p) ((p)->all.param)
|
||||||
#define CFN_PLAY_REPEAT(p) ((p)->active)
|
#define CFN_PLAY_REPEAT(p) ((p)->active)
|
||||||
#define CFN_PLAY_REPEAT_MUL 1
|
#define CFN_PLAY_REPEAT_MUL 1
|
||||||
#define CFN_PLAY_REPEAT_NOSTART 0x3F
|
#define CFN_PLAY_REPEAT_NOSTART 0x3F
|
||||||
#define CFN_GVAR_MODE(p) ((p)->param.composite.mode)
|
#define CFN_GVAR_NUMBER(p) ((p)->all.param)
|
||||||
#define CFN_PARAM(p) ((p)->param.composite.val)
|
#define CFN_GVAR_MODE(p) ((p)->all.mode)
|
||||||
#define CFN_RESET(p) ((p)->active=0, (p)->param.composite.val=0, (p)->param.composite.mode=0, (p)->param.composite.spare1=0, (p)->param.composite.spare2=0)
|
#define CFN_PARAM(p) ((p)->all.val)
|
||||||
|
#define CFN_RESET(p) ((p)->active=0, (p)->clear.val1=0, (p)->clear.val2=0)
|
||||||
#else
|
#else
|
||||||
PACK(typedef struct t_CustomFnData {
|
PACK(typedef struct t_CustomFnData {
|
||||||
uint8_t value;
|
PACK(union {
|
||||||
uint8_t func:5;
|
struct {
|
||||||
|
int8_t swtch:6;
|
||||||
|
uint16_t func:4;
|
||||||
|
uint8_t mode:2;
|
||||||
|
uint8_t param:3;
|
||||||
uint8_t active:1;
|
uint8_t active:1;
|
||||||
int16_t swtch:6;
|
} gvar;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int8_t swtch:6;
|
||||||
|
uint16_t func:4;
|
||||||
uint8_t param:4;
|
uint8_t param:4;
|
||||||
|
uint8_t spare:1;
|
||||||
|
uint8_t active:1;
|
||||||
|
} all;
|
||||||
|
});
|
||||||
|
|
||||||
|
uint8_t value;
|
||||||
}) CustomFnData;
|
}) CustomFnData;
|
||||||
#define CFN_FUNC(p) ((p)->func)
|
#define CFN_SWITCH(p) ((p)->all.swtch)
|
||||||
#define CFN_ACTIVE(p) ((p)->active)
|
#define CFN_FUNC(p) ((p)->all.func)
|
||||||
#define CFN_CH_NUMBER(p) ((p)->param)
|
#define CFN_ACTIVE(p) ((p)->all.active)
|
||||||
#define CFN_PLAY_REPEAT(p) ((p)->param)
|
#define CFN_CH_NUMBER(p) ((p)->all.param)
|
||||||
|
#define CFN_PLAY_REPEAT(p) ((p)->all.param)
|
||||||
#define CFN_PLAY_REPEAT_MUL 10
|
#define CFN_PLAY_REPEAT_MUL 10
|
||||||
#define CFN_GVAR_MODE(p) ((p)->param)
|
#define CFN_GVAR_NUMBER(p) ((p)->gvar.param)
|
||||||
|
#define CFN_GVAR_MODE(p) ((p)->gvar.mode)
|
||||||
#define CFN_PARAM(p) ((p)->value)
|
#define CFN_PARAM(p) ((p)->value)
|
||||||
#define CFN_RESET(p) ((p)->active = 0, CFN_PARAM(p) = 0)
|
#define CFN_RESET(p) ((p)->all.active = 0, CFN_PARAM(p) = 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum TelemetryUnit {
|
enum TelemetryUnit {
|
||||||
|
|
|
@ -3045,10 +3045,10 @@ uint8_t fnSwitchDuration[NUM_CFN] = { 0 };
|
||||||
|
|
||||||
inline void playCustomFunctionFile(CustomFnData *sd, uint8_t id)
|
inline void playCustomFunctionFile(CustomFnData *sd, uint8_t id)
|
||||||
{
|
{
|
||||||
char filename[sizeof(SOUNDS_PATH)+sizeof(sd->param.name)+sizeof(SOUNDS_EXT)] = SOUNDS_PATH "/";
|
char filename[sizeof(SOUNDS_PATH)+sizeof(sd->play.name)+sizeof(SOUNDS_EXT)] = SOUNDS_PATH "/";
|
||||||
strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||||
strncpy(filename+sizeof(SOUNDS_PATH), sd->param.name, sizeof(sd->param.name));
|
strncpy(filename+sizeof(SOUNDS_PATH), sd->play.name, sizeof(sd->play.name));
|
||||||
filename[sizeof(SOUNDS_PATH)+sizeof(sd->param.name)] = '\0';
|
filename[sizeof(SOUNDS_PATH)+sizeof(sd->play.name)] = '\0';
|
||||||
strcat(filename+sizeof(SOUNDS_PATH), SOUNDS_EXT);
|
strcat(filename+sizeof(SOUNDS_PATH), SOUNDS_EXT);
|
||||||
PLAY_FILE(filename, sd->func==FUNC_BACKGND_MUSIC ? PLAY_BACKGROUND : 0, id);
|
PLAY_FILE(filename, sd->func==FUNC_BACKGND_MUSIC ? PLAY_BACKGROUND : 0, id);
|
||||||
}
|
}
|
||||||
|
@ -3078,7 +3078,7 @@ void evalFunctions()
|
||||||
|
|
||||||
for (uint8_t i=0; i<NUM_CFN; i++) {
|
for (uint8_t i=0; i<NUM_CFN; i++) {
|
||||||
CustomFnData *sd = &g_model.funcSw[i];
|
CustomFnData *sd = &g_model.funcSw[i];
|
||||||
int8_t swtch = sd->swtch;
|
int8_t swtch = CFN_SWITCH(sd);
|
||||||
if (swtch) {
|
if (swtch) {
|
||||||
MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i);
|
MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i);
|
||||||
|
|
||||||
|
@ -3146,29 +3146,29 @@ void evalFunctions()
|
||||||
#if defined(GVARS)
|
#if defined(GVARS)
|
||||||
case FUNC_ADJUST_GVAR:
|
case FUNC_ADJUST_GVAR:
|
||||||
if (CFN_GVAR_MODE(sd) == 0) {
|
if (CFN_GVAR_MODE(sd) == 0) {
|
||||||
SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, CFN_PARAM(sd), s_perout_flight_phase);
|
SET_GVAR(CFN_GVAR_NUMBER(sd), CFN_PARAM(sd), s_perout_flight_phase);
|
||||||
}
|
}
|
||||||
else if (CFN_GVAR_MODE(sd) == 2) {
|
else if (CFN_GVAR_MODE(sd) == 2) {
|
||||||
SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, GVAR_VALUE(CFN_PARAM(sd), s_perout_flight_phase), s_perout_flight_phase);
|
SET_GVAR(CFN_GVAR_NUMBER(sd), GVAR_VALUE(CFN_PARAM(sd), s_perout_flight_phase), s_perout_flight_phase);
|
||||||
}
|
}
|
||||||
else if (CFN_GVAR_MODE(sd) == 3) {
|
else if (CFN_GVAR_MODE(sd) == 3) {
|
||||||
if (!(activeFnSwitches & switch_mask)) {
|
if (!(activeFnSwitches & switch_mask)) {
|
||||||
SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, GVAR_VALUE(CFN_FUNC(sd)-FUNC_ADJUST_GV1, getGVarFlightPhase(s_perout_flight_phase, CFN_FUNC(sd)-FUNC_ADJUST_GV1)) + (CFN_PARAM(sd) ? +1 : -1), s_perout_flight_phase);
|
SET_GVAR(CFN_GVAR_NUMBER(sd), GVAR_VALUE(CFN_GVAR_NUMBER(sd), getGVarFlightPhase(s_perout_flight_phase, CFN_GVAR_NUMBER(sd))) + (CFN_PARAM(sd) ? +1 : -1), s_perout_flight_phase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CFN_PARAM(sd) >= MIXSRC_TrimRud && CFN_PARAM(sd) <= MIXSRC_TrimAil) {
|
else if (CFN_PARAM(sd) >= MIXSRC_TrimRud && CFN_PARAM(sd) <= MIXSRC_TrimAil) {
|
||||||
trimGvar[CFN_PARAM(sd)-MIXSRC_TrimRud] = CFN_FUNC(sd)-FUNC_ADJUST_GV1;
|
trimGvar[CFN_PARAM(sd)-MIXSRC_TrimRud] = CFN_GVAR_NUMBER(sd);
|
||||||
}
|
}
|
||||||
#if defined(ROTARY_ENCODERS)
|
#if defined(ROTARY_ENCODERS)
|
||||||
else if (CFN_PARAM(sd) >= MIXSRC_REa && CFN_PARAM(sd) < MIXSRC_TrimRud) {
|
else if (CFN_PARAM(sd) >= MIXSRC_REa && CFN_PARAM(sd) < MIXSRC_TrimRud) {
|
||||||
int8_t scroll = rePreviousValues[CFN_PARAM(sd)-MIXSRC_REa] - (g_rotenc[CFN_PARAM(sd)-MIXSRC_REa] / ROTARY_ENCODER_GRANULARITY);
|
int8_t scroll = rePreviousValues[CFN_PARAM(sd)-MIXSRC_REa] - (g_rotenc[CFN_PARAM(sd)-MIXSRC_REa] / ROTARY_ENCODER_GRANULARITY);
|
||||||
if (scroll) {
|
if (scroll) {
|
||||||
SET_GVAR(CFN_FUNC(sd)-FUNC_ADJUST_GV1, GVAR_VALUE(CFN_FUNC(sd)-FUNC_ADJUST_GV1, getGVarFlightPhase(s_perout_flight_phase, CFN_FUNC(sd)-FUNC_ADJUST_GV1)) + scroll, s_perout_flight_phase);
|
SET_GVAR(CFN_GVAR_NUMBER(sd), GVAR_VALUE(CFN_GVAR_NUMBER(sd), getGVarFlightPhase(s_perout_flight_phase, CFN_GVAR_NUMBER(sd))) + scroll, s_perout_flight_phase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
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);
|
SET_GVAR(CFN_GVAR_NUMBER(sd), limit((getvalue_t)-1250, getValue(CFN_PARAM(sd)), (getvalue_t)1250) / 10, s_perout_flight_phase);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue