1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

[Taranis] Issue #592 - Sticky switches

This commit is contained in:
Bertrand Songis 2014-02-03 11:19:17 +01:00
parent 7c81920431
commit 9730f8d190
4 changed files with 73 additions and 23 deletions

View file

@ -4184,10 +4184,10 @@ enum CustomSwitchFields {
#if LCD_W >= 212
#define CSW_1ST_COLUMN (4*FW-3)
#define CSW_2ND_COLUMN (8*FW+1)
#define CSW_3RD_COLUMN (14*FW)
#define CSW_4TH_COLUMN (21*FW+1)
#define CSW_5TH_COLUMN (26*FW+1)
#define CSW_2ND_COLUMN (8*FW+2+FW/2)
#define CSW_3RD_COLUMN (14*FW+1+FW/2)
#define CSW_4TH_COLUMN (22*FW)
#define CSW_5TH_COLUMN (26*FW+3)
#define CSW_6TH_COLUMN (31*FW+1)
#else
#define CSW_1ST_COLUMN (4*FW-3)
@ -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;
#endif
if (cstate == CS_VBOOL) {
if (cstate == CS_VBOOL || IS_VSTICKY(cstate)) {
putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1);
putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2);
v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1;
@ -4585,7 +4585,6 @@ void menuModelCustomSwitches(uint8_t event)
if (cstate==CS_VOFS && cs->v1!=0 && event==EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
getvalue_t x = getValue(cs->v1);
TRACE("AUTO x=%d", x);
if (cs->v1 < MIXSRC_GVAR1)
cs->v2 = calcRESXto100(x);
else if (cs->v1 - MIXSRC_FIRST_TELEM + 1 == TELEM_ALT)

View file

@ -448,7 +448,13 @@ CustomSwData *cswAddress(uint8_t idx)
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 : CS_VTIMER))));
return (func<CS_AND ? CS_VOFS : (func<CS_EQUAL ? CS_VBOOL : (func<CS_DIFFEGREATER ? CS_VCOMP : (func<CS_TIMER ? CS_VDIFF :
#if defined(CPUARM)
(func<CS_STICKY ? CS_VTIMER : CS_VSTICKY)
#else
CS_VTIMER
#endif
))));
}
int16_t cswTimerValue(int8_t val)
@ -1343,7 +1349,6 @@ void getSwitchesPosition()
CHECK_2POS(SW_SH);
switchesPos = newPos;
#if defined(PCBTARANIS)
for (int i=0; i<NUM_XPOTS; i++) {
if (g_eeGeneral.potsType & (1 << i)) {
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT1+i];
@ -1361,7 +1366,6 @@ void getSwitchesPosition()
}
}
}
#endif
}
#define SWITCH_POSITION(sw) (switchesPos & (1<<(sw)))
#define POT_POSITION(sw) ((potsPos[(sw)/POTS_POS_COUNT] & 0x0f) == ((sw) % POTS_POS_COUNT))
@ -1425,8 +1429,13 @@ bool getSwitch(int8_t swtch)
}
}
else if (s == CS_VTIMER) {
result = csLastValue[cs_idx] <= 0;
result = (csLastValue[cs_idx] <= 0);
}
#if defined(CPUARM)
else if (s == CS_VSTICKY) {
result = (csLastValue[cs_idx] & (1<<0));
}
#endif
else {
getvalue_t x = getValue(cs->v1);
getvalue_t y;
@ -3460,8 +3469,6 @@ void perOut(uint8_t mode, uint8_t tick10ms)
do {
// TRACE("[pass %d]", pass);
bitfield_channels_t passDirtyChannels = 0;
for (uint8_t i=0; i<MAX_MIXERS; i++) {
@ -4045,6 +4052,30 @@ void doMixerCalculations()
*lastValue -= 1;
}
}
#if defined(CPUARM)
else if (cs->func == CS_STICKY) {
uint16_t & lastValue = (uint16_t &)csLastValue[i];
bool before = (lastValue & (1<<15));
if (lastValue & (1<<0)) {
bool now = getSwitch(cs->v2);
if (now != before) {
lastValue ^= (1<<15);
if (!before) {
lastValue &= ~(1<<0);
}
}
}
else {
bool now = getSwitch(cs->v1);
if (before != now) {
lastValue ^= (1<<15);
if (!before) {
lastValue |= (1<<0);
}
}
}
}
#endif
}
if (s_cnt_1s >= 10) { // 1sec

View file

@ -639,7 +639,11 @@ enum CswFunctions {
CS_DIFFEGREATER,
CS_ADIFFEGREATER,
CS_TIMER,
CS_MAXF = CS_TIMER
#if defined(CPUARM)
CS_STICKY,
#endif
CS_COUNT,
CS_MAXF = CS_COUNT-1
};
#define CS_VOFS 0
@ -647,9 +651,17 @@ enum CswFunctions {
#define CS_VCOMP 2
#define CS_VDIFF 3
#define CS_VTIMER 4
#define CS_VSTICKY 5
uint8_t cswFamily(uint8_t func);
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_CAL_PPM 4
#define NUM_PPM 8

View file

@ -150,8 +150,16 @@
#define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "OFF""ON\0""Rud""Ele""Thr""Ail"
#if defined(CPUARM)
#define TR_CSWTIMER "Timer"
#define TR_CSWSTICKY "Stcky"
#else
#define TR_CSWTIMER "TIM\0"
#define TR_CSWSTICKY
#endif
#define LEN_VCSWFUNC "\005"
#define TR_VCSWFUNC "---\0 ""a{x\0 ""a>x\0 ""a<x\0 ""|a|>x""|a|<x""AND\0 ""OR\0 ""XOR\0 ""a=b\0 ""a>b\0 ""a<b\0 ""d}x\0 ""|d|}x""TIM\0"
#define TR_VCSWFUNC "---\0 ""a{x\0 ""a>x\0 ""a<x\0 ""|a|>x""|a|<x""AND\0 ""OR\0 ""XOR\0 ""a=b\0 ""a>b\0 ""a<b\0 ""d}x\0 ""|d|}x" TR_CSWTIMER TR_CSWSTICKY
#define LEN_VFSWFUNC "\012"