1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 14:25:11 +03:00

[all] Issue #592 - Sticky switches on all boards. Saves 62bytes on

stock!
This commit is contained in:
Bertrand Songis 2014-02-03 14:05:05 +01:00
parent 9730f8d190
commit e48c27d30a
6 changed files with 16 additions and 156 deletions

View file

@ -4476,7 +4476,7 @@ void menuModelCustomSwitches(uint8_t event)
int8_t v1_min=0, v1_max=MIXSRC_LAST_TELEM, v2_min=0, v2_max=MIXSRC_LAST_TELEM; int8_t v1_min=0, v1_max=MIXSRC_LAST_TELEM, v2_min=0, v2_max=MIXSRC_LAST_TELEM;
#endif #endif
if (cstate == CS_VBOOL || IS_VSTICKY(cstate)) { if (cstate == CS_VBOOL || cstate == CS_VSTICKY) {
putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1); putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1);
putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2); putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2);
v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1; v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1;

View file

@ -1053,31 +1053,6 @@ void putsSwitches(xcoord_t x, uint8_t y, int8_t idx, LcdFlags att)
} }
#endif #endif
#if !defined(PCBSTD)
else if (idx >= SWSRC_TRAINER_SHORT) {
idx -= SWSRC_TRAINER_SHORT;
char suffix = (idx & 1) ? CHR_LONG : CHR_SHORT;
#if ROTARY_ENCODERS > 0
if (idx >= 2) {
idx -= 2;
lcd_putsiAtt(x, y, STR_VRENCODERS, idx/2, att);
}
else
#endif
{
lcd_putsiAtt(x, y, STR_VSWITCHES, SWSRC_TRAINER-1, att);
}
return lcd_putcAtt(lcdLastPos, y, suffix, att);
}
#endif
if (idx > SWSRC_ON) {
idx -= SWSRC_ON;
if (idx != SWSRC_ON && (~att & STRCONDENSED)) {
lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att);
return lcd_putcAtt(lcdLastPos, y, CHR_TOGGLE, att);
}
}
lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att); lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att);
} }

View file

@ -740,6 +740,12 @@ enum Functions {
FUNC_MAX FUNC_MAX
}; };
#if defined(CPUARM)
#define IS_PLAY_BOTH_FUNC(sd) (0)
#else
#define IS_PLAY_BOTH_FUNC(sd) (CFN_FUNC(sd) == FUNC_PLAY_BOTH)
#endif
#if defined(GVARS) #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_FUNCTION(sd) (CFN_FUNC(sd) >= FUNC_ADJUST_GV1 && CFN_FUNC(sd) <= FUNC_ADJUST_GVLAST)
#else #else
@ -1198,26 +1204,12 @@ enum SwitchSources {
#endif #endif
SWSRC_ON, SWSRC_ON,
SWSRC_FIRST_MOMENT_SWITCH,
SWSRC_LAST_MOMENT_SWITCH = SWSRC_FIRST_MOMENT_SWITCH+SWSRC_LAST_CSW,
#if !defined(PCBSTD)
SWSRC_TRAINER_SHORT,
SWSRC_TRAINER_LONG,
#endif
#if ROTARY_ENCODERS > 0
SWSRC_FIRST_ROTENC_SWITCH,
SWSRC_LAST_ROTENC_SWITCH = SWSRC_FIRST_ROTENC_SWITCH+(2*ROTARY_ENCODERS)-1,
#endif
SWSRC_COUNT,
SWSRC_FIRST = -SWSRC_LAST_MOMENT_SWITCH,
SWSRC_LAST = SWSRC_COUNT-1,
SWSRC_OFF = -SWSRC_ON, SWSRC_OFF = -SWSRC_ON,
SWSRC_TRAINER = SWSRC_SW1-1, SWSRC_TRAINER = SWSRC_SW1-1,
SWSRC_FIRST = SWSRC_OFF,
SWSRC_LAST = SWSRC_ON
}; };
enum MixSources { enum MixSources {

View file

@ -448,13 +448,7 @@ CustomSwData *cswAddress(uint8_t idx)
uint8_t cswFamily(uint8_t func) uint8_t cswFamily(uint8_t func)
{ {
return (func<CS_AND ? CS_VOFS : (func<CS_EQUAL ? CS_VBOOL : (func<CS_DIFFEGREATER ? CS_VCOMP : (func<CS_TIMER ? CS_VDIFF : return (func<CS_AND ? CS_VOFS : (func<CS_EQUAL ? CS_VBOOL : (func<CS_DIFFEGREATER ? CS_VCOMP : (func<CS_TIMER ? CS_VDIFF : func+CS_VTIMER-CS_TIMER))));
#if defined(CPUARM)
(func<CS_STICKY ? CS_VTIMER : CS_VSTICKY)
#else
CS_VTIMER
#endif
))));
} }
int16_t cswTimerValue(int8_t val) int16_t cswTimerValue(int8_t val)
@ -1431,11 +1425,9 @@ bool getSwitch(int8_t swtch)
else if (s == CS_VTIMER) { else if (s == CS_VTIMER) {
result = (csLastValue[cs_idx] <= 0); result = (csLastValue[cs_idx] <= 0);
} }
#if defined(CPUARM)
else if (s == CS_VSTICKY) { else if (s == CS_VSTICKY) {
result = (csLastValue[cs_idx] & (1<<0)); result = (csLastValue[cs_idx] & (1<<0));
} }
#endif
else { else {
getvalue_t x = getValue(cs->v1); getvalue_t x = getValue(cs->v1);
getvalue_t y; getvalue_t y;
@ -3093,100 +3085,11 @@ void evalFunctions()
if (swtch) { if (swtch) {
MASK_FUNC_TYPE function_mask = (CFN_FUNC(sd) >= FUNC_TRAINER ? ((MASK_FUNC_TYPE)1 << (CFN_FUNC(sd)-FUNC_TRAINER)) : 0); 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); MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i);
uint8_t momentary = 0;
#if !defined(PCBSTD)
#define MOMENTARY_START_TEST() ( (momentary && !(activeSwitches & switch_mask) && active) || \
(short_long==1 && !active && mSwitchDuration[mswitch]>0 && mSwitchDuration[mswitch]<CFN_PRESSLONG_DURATION) || \
(short_long==2 && active && mSwitchDuration[mswitch]==CFN_PRESSLONG_DURATION) )
uint8_t short_long = 0;
uint8_t mswitch = 0;
if (swtch == SWSRC_TRAINER_LONG) {
short_long = 2;
swtch = SWSRC_TRAINER;
mswitch = 0;
}
else if (swtch == SWSRC_TRAINER_SHORT) {
short_long = 1;
swtch = SWSRC_TRAINER;
mswitch = 0;
}
else
#else
#define short_long 0
#define MOMENTARY_START_TEST() (!(activeSwitches & switch_mask) && active)
#endif
if (swtch > NUM_SWITCH+1) {
momentary = 1;
swtch -= NUM_SWITCH+1;
}
if (swtch < -NUM_SWITCH-1) {
momentary = 1;
swtch += NUM_SWITCH+1;
}
bool active = getSwitch(swtch); bool active = getSwitch(swtch);
if (active) newActiveSwitches |= switch_mask; if (active) newActiveSwitches |= switch_mask;
if (momentary || short_long) {
#if !defined(PCBSTD) if (active || IS_PLAY_BOTH_FUNC(sd)) {
bool swState = active;
#endif
if (MOMENTARY_START_TEST()) {
if (short_long) {
active = false;
momentary = true;
}
else {
active = !(activeFnSwitches & switch_mask);
#if !defined(CPUARM)
if (CFN_FUNC(sd) == FUNC_PLAY_BOTH && !active) {
momentary = true;
}
else
#endif
{
momentary = false;
}
}
}
else if (swtch == SWSRC_ON) {
active = false;
momentary = false;
}
else {
active = (activeFnSwitches & switch_mask);
momentary = false;
}
#if !defined(PCBSTD)
if (short_long && !(mSwitchDurationIncremented & (1<<mswitch))) {
mSwitchDurationIncremented |= (1<<mswitch);
if (swState) {
if (mSwitchDuration[mswitch] < 255)
mSwitchDuration[mswitch]++;
}
else {
mSwitchDuration[mswitch] = 0;
}
}
#endif
}
#if !defined(CPUARM)
else if (CFN_FUNC(sd) == FUNC_PLAY_BOTH) {
momentary = true;
}
#endif
if (active || momentary) {
if (CFN_ACTIVE(sd)) { if (CFN_ACTIVE(sd)) {
if (CFN_FUNC(sd) < FUNC_TRAINER) { if (CFN_FUNC(sd) < FUNC_TRAINER) {
@ -4052,7 +3955,6 @@ void doMixerCalculations()
*lastValue -= 1; *lastValue -= 1;
} }
} }
#if defined(CPUARM)
else if (cs->func == CS_STICKY) { else if (cs->func == CS_STICKY) {
uint16_t & lastValue = (uint16_t &)csLastValue[i]; uint16_t & lastValue = (uint16_t &)csLastValue[i];
bool before = (lastValue & (1<<15)); bool before = (lastValue & (1<<15));
@ -4075,7 +3977,6 @@ void doMixerCalculations()
} }
} }
} }
#endif
} }
if (s_cnt_1s >= 10) { // 1sec if (s_cnt_1s >= 10) { // 1sec

View file

@ -639,9 +639,7 @@ enum CswFunctions {
CS_DIFFEGREATER, CS_DIFFEGREATER,
CS_ADIFFEGREATER, CS_ADIFFEGREATER,
CS_TIMER, CS_TIMER,
#if defined(CPUARM)
CS_STICKY, CS_STICKY,
#endif
CS_COUNT, CS_COUNT,
CS_MAXF = CS_COUNT-1 CS_MAXF = CS_COUNT-1
}; };
@ -656,12 +654,6 @@ enum CswFunctions {
uint8_t cswFamily(uint8_t func); uint8_t cswFamily(uint8_t func);
int16_t cswTimerValue(int8_t val); int16_t cswTimerValue(int8_t val);
#if defined(CPUARM)
#define IS_VSTICKY(val) ((val) == CS_VSTICKY)
#else
#define IS_VSTICKY(val) (0)
#endif
#define NUM_CYC 3 #define NUM_CYC 3
#define NUM_CAL_PPM 4 #define NUM_CAL_PPM 4
#define NUM_PPM 8 #define NUM_PPM 8

View file

@ -150,12 +150,12 @@
#define LEN_VMIXTRIMS "\003" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "OFF""ON\0""Rud""Ele""Thr""Ail" #define TR_VMIXTRIMS "OFF""ON\0""Rud""Ele""Thr""Ail"
#if defined(CPUARM) #if defined(PCBTARANIS)
#define TR_CSWTIMER "Timer" #define TR_CSWTIMER "Timer"
#define TR_CSWSTICKY "Stcky" #define TR_CSWSTICKY "Stcky"
#else #else
#define TR_CSWTIMER "TIM\0" #define TR_CSWTIMER "Tim\0 "
#define TR_CSWSTICKY #define TR_CSWSTICKY "Stky\0"
#endif #endif
#define LEN_VCSWFUNC "\005" #define LEN_VCSWFUNC "\005"