From 9730f8d190a432c625ad342cce50771353b59bcf Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 3 Feb 2014 11:19:17 +0100 Subject: [PATCH] [Taranis] Issue #592 - Sticky switches --- radio/src/gui/menu_model.cpp | 29 ++++++++++++------------ radio/src/opentx.cpp | 43 +++++++++++++++++++++++++++++++----- radio/src/opentx.h | 14 +++++++++++- radio/src/translations/en.h | 10 ++++++++- 4 files changed, 73 insertions(+), 23 deletions(-) diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 55f61707f..a335c535b 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -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) @@ -4442,15 +4442,15 @@ void menuModelCustomSwitches(uint8_t event) #endif #if defined(PCBTARANIS) - if (sub>=0 && horz<0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) { - killEvents(event); - CustomSwData * cs = cswAddress(sub); - if (cs->func) MENU_ADD_ITEM(STR_COPY); - if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) - MENU_ADD_ITEM(STR_PASTE); - if (cs->func || cs->v1 || cs->v2 || cs->delay || cs->duration || cs->andsw) MENU_ADD_ITEM(STR_DELETE); - menuHandler = onCustomSwitchesMenu; - } + if (sub>=0 && horz<0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) { + killEvents(event); + CustomSwData * cs = cswAddress(sub); + if (cs->func) MENU_ADD_ITEM(STR_COPY); + if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) + MENU_ADD_ITEM(STR_PASTE); + if (cs->func || cs->v1 || cs->v2 || cs->delay || cs->duration || cs->andsw) MENU_ADD_ITEM(STR_DELETE); + menuHandler = onCustomSwitchesMenu; + } #endif for (uint8_t i=0; iv1, 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) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 5a33763be..67a9e16c0 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -448,7 +448,13 @@ CustomSwData *cswAddress(uint8_t idx) uint8_t cswFamily(uint8_t func) { - return (funcv1); 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; ifunc == 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 diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 981d360bd..6b704b30b 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -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 diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 3fd7c07f2..6e228f79b 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -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 ""ax""|a|b\0 ""ax\0 ""ax""|a|b\0 ""a