diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index 25dda97cb..d79e5158e 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -222,7 +222,7 @@ PACK(typedef struct { int16_t curves[16]; int8_t points[NUM_POINTS]; - LogicalSwitchData_v215 customSw[NUM_LOGICAL_SWITCH]; + LogicalSwitchData_v215 logicalSw[NUM_LOGICAL_SWITCH]; CustomFnData_v215 funcSw[32]; SwashRingData swashR; PhaseData_v215 phaseData[MAX_FLIGHT_MODES]; @@ -658,16 +658,16 @@ void ConvertModel_215_to_216(ModelData &model) g_model.points[i] = oldModel.points[i]; } for (uint8_t i=0; i<32; i++) { - LogicalSwitchData & sw = g_model.customSw[i]; - sw.func = oldModel.customSw[i].func; + LogicalSwitchData & sw = g_model.logicalSw[i]; + sw.func = oldModel.logicalSw[i].func; if (sw.func >= LS_FUNC_VEQUAL) sw.func += 1; if (sw.func >= LS_FUNC_RANGE) sw.func += 1; if (sw.func >= LS_FUNC_STAY) sw.func += 1; - sw.v1 = oldModel.customSw[i].v1; - sw.v2 = oldModel.customSw[i].v2; - sw.delay = oldModel.customSw[i].delay * 5; - sw.duration = oldModel.customSw[i].duration * 5; - sw.andsw = ConvertSwitch_215_to_216(oldModel.customSw[i].andsw); + sw.v1 = oldModel.logicalSw[i].v1; + sw.v2 = oldModel.logicalSw[i].v2; + sw.delay = oldModel.logicalSw[i].delay * 5; + sw.duration = oldModel.logicalSw[i].duration * 5; + sw.andsw = ConvertSwitch_215_to_216(oldModel.logicalSw[i].andsw); uint8_t cstate = cswFamily(sw.func); if (cstate == LS_FAMILY_BOOL) { sw.v1 = ConvertSwitch_215_to_216(sw.v1); diff --git a/radio/src/gtests.cpp b/radio/src/gtests.cpp index 0516ff27c..7a0b4132f 100644 --- a/radio/src/gtests.cpp +++ b/radio/src/gtests.cpp @@ -307,8 +307,8 @@ TEST(getSwitch, circularCSW) { MODEL_RESET(); MIXER_RESET(); - g_model.customSw[0] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_OR }; - g_model.customSw[1] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_AND }; + g_model.logicalSw[0] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_OR }; + g_model.logicalSw[1] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_AND }; EXPECT_EQ(getSwitch(SWSRC_SW1), false); EXPECT_EQ(getSwitch(-SWSRC_SW1), true); EXPECT_EQ(getSwitch(SWSRC_SW2), false); @@ -327,8 +327,8 @@ TEST(getSwitch, recursiveSW) MODEL_RESET(); MIXER_RESET(); - g_model.customSw[0] = { SWSRC_RUD, -SWSRC_SW2, LS_FUNC_OR }; - g_model.customSw[1] = { SWSRC_ELE, -SWSRC_SW1, LS_FUNC_OR }; + g_model.logicalSw[0] = { SWSRC_RUD, -SWSRC_SW2, LS_FUNC_OR }; + g_model.logicalSw[1] = { SWSRC_ELE, -SWSRC_SW1, LS_FUNC_OR }; EXPECT_EQ(getSwitch(SWSRC_SW1), false); EXPECT_EQ(getSwitch(SWSRC_SW2), true); diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 1b3d6e1f3..6c6696363 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -4269,7 +4269,7 @@ void menuModelLogicalSwitchOne(uint8_t event) { TITLE(STR_MENULOGICALSWITCH); - LogicalSwitchData * cs = cswAddress(s_currIdx); + LogicalSwitchData * cs = lswAddress(s_currIdx); uint8_t sw = SWSRC_SW1+s_currIdx; putsSwitches(14*FW, 0, sw, (getSwitch(sw) ? BOLD : 0)); @@ -4343,12 +4343,12 @@ void menuModelLogicalSwitchOne(uint8_t event) } else if (cstate == LS_FAMILY_STAY) { lcd_putc(CSWONE_2ND_COLUMN-4, y, '['); - lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cswTimerValue(cs->v2), LEFT|PREC1|(m_posHorz==0 ? attr : 0)); + lcd_outdezAtt(CSWONE_2ND_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1|(m_posHorz==0 ? attr : 0)); lcd_putc(lcdLastPos, y, ':'); if (cs->v3 == 0) lcd_putsAtt(lcdLastPos+3, y, "--", (m_posHorz==1 ? attr : 0)); else - lcd_outdezAtt(lcdLastPos+3, y, cswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(m_posHorz==1 ? attr : 0)); + lcd_outdezAtt(lcdLastPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(m_posHorz==1 ? attr : 0)); lcd_putc(lcdLastPos, y, ']'); if (s_editMode <= 0) continue; if (attr && m_posHorz==1) { @@ -4365,7 +4365,7 @@ void menuModelLogicalSwitchOne(uint8_t event) else { #if defined(FRSKY) if (v1_val >= MIXSRC_FIRST_TELEM) { - putsTelemetryChannel(CSWONE_2ND_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertCswTelemValue(cs), attr|LEFT); + putsTelemetryChannel(CSWONE_2ND_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), attr|LEFT); v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1); v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1); INCDEC_SET_FLAG(INCDEC_REP10 | NO_INCDEC_MARKS); @@ -4436,7 +4436,7 @@ void menuModelLogicalSwitches(uint8_t event) for (uint8_t i=0; iv1, 0); lcd_putc(CSW_3RD_COLUMN-4, y, '['); - lcd_outdezAtt(CSW_3RD_COLUMN, y, cswTimerValue(cs->v2), LEFT|PREC1); + lcd_outdezAtt(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1); lcd_putc(lcdLastPos, y, ':'); if (cs->v3 == 0) lcd_puts(lcdLastPos+3, y, "--"); else - lcd_outdezAtt(lcdLastPos+3, y, cswTimerValue(cs->v2+cs->v3), LEFT|PREC1); + lcd_outdezAtt(lcdLastPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1); lcd_putc(lcdLastPos-1, y, ']'); } else if (cstate == LS_FAMILY_TIMER) { @@ -4477,7 +4477,7 @@ void menuModelLogicalSwitches(uint8_t event) uint8_t v1 = cs->v1; putsMixerSource(CSW_2ND_COLUMN, y, v1, 0); if (v1 >= MIXSRC_FIRST_TELEM) { - putsTelemetryChannel(CSW_3RD_COLUMN, y, v1 - MIXSRC_FIRST_TELEM, convertCswTelemValue(cs), LEFT); + putsTelemetryChannel(CSW_3RD_COLUMN, y, v1 - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT); } else { lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, LEFT); @@ -4512,7 +4512,7 @@ Clipboard clipboard; void onLogicalSwitchesMenu(const char *result) { int8_t sub = m_posVert-1; - LogicalSwitchData * cs = cswAddress(sub); + LogicalSwitchData * cs = lswAddress(sub); if (result == STR_COPY) { clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; @@ -4549,7 +4549,7 @@ void menuModelLogicalSwitches(uint8_t event) #if defined(PCBTARANIS) if (sub>=0 && horz<0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) { killEvents(event); - LogicalSwitchData * cs = cswAddress(sub); + LogicalSwitchData * cs = lswAddress(sub); if (cs->func) MENU_ADD_ITEM(STR_COPY); if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) @@ -4566,7 +4566,7 @@ void menuModelLogicalSwitches(uint8_t event) uint8_t attr = (sub==k ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); uint8_t attr1 = (horz==1 ? attr : 0); uint8_t attr2 = (horz==2 ? attr : 0); - LogicalSwitchData * cs = cswAddress(k); + LogicalSwitchData * cs = lswAddress(k); // CSW name uint8_t sw = SWSRC_SW1+k; @@ -4597,12 +4597,12 @@ void menuModelLogicalSwitches(uint8_t event) else if (cstate == LS_FAMILY_STAY) { putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1); lcd_putc(CSW_3RD_COLUMN-4, y, '['); - lcd_outdezAtt(CSW_3RD_COLUMN, y, cswTimerValue(cs->v2), LEFT|PREC1|attr2); + lcd_outdezAtt(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1|attr2); lcd_putc(lcdLastPos, y, ':'); if (cs->v3 == 0) lcd_putsAtt(lcdLastPos+3, y, "--", (horz==LS_FIELD_V3 ? attr : 0)); else - lcd_outdezAtt(lcdLastPos+3, y, cswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(horz==LS_FIELD_V3 ? attr : 0)); + lcd_outdezAtt(lcdLastPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(horz==LS_FIELD_V3 ? attr : 0)); lcd_putc(lcdLastPos, y, ']'); v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1; v2_min=-129; v2_max = 122; @@ -4627,8 +4627,8 @@ void menuModelLogicalSwitches(uint8_t event) INCDEC_ENABLE_CHECK(isSourceAvailable); } else if (cstate == LS_FAMILY_TIMER) { - lcd_outdezAtt(CSW_2ND_COLUMN, y, cswTimerValue(cs->v1), LEFT|PREC1|attr1); - lcd_outdezAtt(CSW_3RD_COLUMN, y, cswTimerValue(cs->v2), LEFT|PREC1|attr2); + lcd_outdezAtt(CSW_2ND_COLUMN, y, lswTimerValue(cs->v1), LEFT|PREC1|attr1); + lcd_outdezAtt(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1|attr2); v1_min = v2_min = -128; v1_max = v2_max = 122; INCDEC_SET_FLAG(0); @@ -4649,7 +4649,7 @@ void menuModelLogicalSwitches(uint8_t event) } #if defined(FRSKY) if (v1_val >= MIXSRC_FIRST_TELEM) { - putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertCswTelemValue(cs), LEFT|attr2); + putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2); v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1); #if defined(CPUARM) v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1); @@ -4680,7 +4680,7 @@ void menuModelLogicalSwitches(uint8_t event) } #else if (v1_val >= MIXSRC_FIRST_TELEM) { - putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertCswTelemValue(cs), LEFT|attr2); + putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2); v2_min = -128; v2_max = 127; } else { diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 7125aeec8..6ebe2f66f 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1421,7 +1421,7 @@ bool isSourceAvailable(int source) } if (source>=MIXSRC_SW1 && source<=MIXSRC_LAST_LOGICAL_SWITCH) { - LogicalSwitchData * cs = cswAddress(source-MIXSRC_SW1); + LogicalSwitchData * cs = lswAddress(source-MIXSRC_SW1); return (cs->func != LS_FUNC_NONE); } @@ -1526,7 +1526,7 @@ bool isSwitchAvailable(int swtch) } if (swtch >= SWSRC_FIRST_LOGICAL_SWITCH && swtch <= SWSRC_LAST_LOGICAL_SWITCH) { - LogicalSwitchData * cs = cswAddress(swtch-SWSRC_FIRST_LOGICAL_SWITCH); + LogicalSwitchData * cs = lswAddress(swtch-SWSRC_FIRST_LOGICAL_SWITCH); return (cs->func != LS_FUNC_NONE); } diff --git a/radio/src/gui/view_main.cpp b/radio/src/gui/view_main.cpp index b4074948e..cb0a9476c 100644 --- a/radio/src/gui/view_main.cpp +++ b/radio/src/gui/view_main.cpp @@ -715,7 +715,7 @@ void menuMainView(uint8_t event) div_t qr = div(sw, 10); uint8_t y = 13 + 11 * qr.quot; uint8_t x = TRIM_RH_X - TRIM_LEN + qr.rem*5 + (qr.rem >= 5 ? 3 : 0); - LogicalSwitchData * cs = cswAddress(sw); + LogicalSwitchData * cs = lswAddress(sw); if (cs->func == LS_FUNC_NONE) { lcd_hline(x, y+6, 4); lcd_hline(x, y+7, 4); diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index daa3bd7ff..925a92e14 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -570,7 +570,7 @@ static int luaModelGetLogicalSwitch(lua_State *L) { int idx = luaL_checkunsigned(L, 1); if (idx < NUM_LOGICAL_SWITCH) { - LogicalSwitchData * sw = cswAddress(idx); + LogicalSwitchData * sw = lswAddress(idx); lua_newtable(L); lua_pushtablenumber(L, "function", sw->func); lua_pushtablenumber(L, "v1", sw->v1); @@ -590,7 +590,7 @@ static int luaModelSetLogicalSwitch(lua_State *L) { int idx = luaL_checkunsigned(L, 1); if (idx < NUM_LOGICAL_SWITCH) { - LogicalSwitchData * sw = cswAddress(idx); + LogicalSwitchData * sw = lswAddress(idx); luaL_checktype(L, -1, LUA_TTABLE); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { luaL_checktype(L, -2, LUA_TSTRING); // key is string diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 7a68b4b27..17d7db539 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -1694,7 +1694,7 @@ PACK(typedef struct t_ModelData { CURVDATA curves[MAX_CURVES]; int8_t points[NUM_POINTS]; - LogicalSwitchData customSw[NUM_LOGICAL_SWITCH]; + LogicalSwitchData logicalSw[NUM_LOGICAL_SWITCH]; CustomFnData funcSw[NUM_CFN]; SwashRingData swashR; PhaseData phaseData[MAX_FLIGHT_MODES]; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 8691b0db4..b26c8144b 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1519,7 +1519,7 @@ void flightReset() #if defined(FRSKY) telemetryReset(); #endif - logicalSwitchesReset(); + lswReset(); s_last_switch_value = 0; s_mixer_first_run_done = false; @@ -2220,7 +2220,7 @@ void doMixerCalculations() s_cnt_100ms -= 10; s_cnt_1s += 1; - evalLogicalSwitchTimers(); + lswTimerTick(); if (s_cnt_1s >= 10) { // 1sec s_cnt_1s -= 10; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 5123eb159..3a52bf286 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -693,8 +693,8 @@ NOINLINE void per10ms(); getvalue_t getValue(uint8_t i); bool getSwitch(int8_t swtch); -void evalLogicalSwitchTimers(); -void logicalSwitchesReset(); +void lswTimerTick(); +void lswReset(); #if defined(PCBTARANIS) void getSwitchesPosition(bool startup); @@ -1106,7 +1106,7 @@ ExpoData *expoAddress(uint8_t idx); MixData *mixAddress(uint8_t idx); LimitData *limitAddress(uint8_t idx); int8_t *curveAddress(uint8_t idx); -LogicalSwitchData *cswAddress(uint8_t idx); +LogicalSwitchData *lswAddress(uint8_t idx); #if !defined(PCBTARANIS) struct CurveInfo { @@ -1199,7 +1199,7 @@ enum CswFunctionFamilies { }; uint8_t cswFamily(uint8_t func); -int16_t cswTimerValue(delayval_t val); +int16_t lswTimerValue(delayval_t val); #if defined(CPUARM) #define MASK_CFN_TYPE uint32_t // current max = 32 function switches @@ -1552,7 +1552,7 @@ ls_telemetry_value_t max8bitsTelemValue(uint8_t channel); #endif getvalue_t convert8bitsTelemValue(uint8_t channel, ls_telemetry_value_t value); -getvalue_t convertCswTelemValue(LogicalSwitchData * cs); +getvalue_t convertLswTelemValue(LogicalSwitchData * cs); #if defined(CPUARM) #define convertTelemValue(channel, value) convert16bitsTelemValue(channel, value) diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index aa518ff22..78199b3aa 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -47,9 +47,9 @@ volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_used = 0; volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_value = 0; #if defined(CPUARM) -uint32_t cswDelays[NUM_LOGICAL_SWITCH]; -uint32_t cswDurations[NUM_LOGICAL_SWITCH]; -uint8_t cswStates[NUM_LOGICAL_SWITCH]; +uint32_t lswDelays[NUM_LOGICAL_SWITCH]; +uint32_t lswDurations[NUM_LOGICAL_SWITCH]; +uint8_t lswStates[NUM_LOGICAL_SWITCH]; #endif #if defined(PCBTARANIS) @@ -157,7 +157,7 @@ void getSwitchesPosition(bool startup) #define SWITCH_POSITION(idx) switchState((EnumKeys)(SW_BASE+(idx))) #endif -int16_t csLastValue[NUM_LOGICAL_SWITCH]; +int16_t lsLastValue[NUM_LOGICAL_SWITCH]; #define CS_LAST_VALUE_INIT -32768 /* recursive function. stack as of today (16/03/2012) grows by 8bytes at each call, which is ok! */ @@ -229,23 +229,23 @@ bool getSwitch(int8_t swtch) else { s_last_switch_used |= mask; - LogicalSwitchData * cs = cswAddress(cs_idx); + LogicalSwitchData * ls = lswAddress(cs_idx); #if defined(CPUARM) - int8_t s = cs->andsw; + int8_t s = ls->andsw; #else - uint8_t s = cs->andsw; + uint8_t s = ls->andsw; if (s > SWSRC_LAST_SWITCH) { s += SWSRC_SW1-SWSRC_LAST_SWITCH-1; } #endif - if (cs->func == LS_FUNC_NONE || (s && !getSwitch(s))) { - csLastValue[cs_idx] = CS_LAST_VALUE_INIT; + if (ls->func == LS_FUNC_NONE || (s && !getSwitch(s))) { + lsLastValue[cs_idx] = CS_LAST_VALUE_INIT; result = false; } - else if ((s=cswFamily(cs->func)) == LS_FAMILY_BOOL) { - bool res1 = getSwitch(cs->v1); - bool res2 = getSwitch(cs->v2); - switch (cs->func) { + else if ((s=cswFamily(ls->func)) == LS_FAMILY_BOOL) { + bool res1 = getSwitch(ls->v1); + bool res2 = getSwitch(ls->v2); + switch (ls->func) { case LS_FUNC_AND: result = (res1 && res2); break; @@ -259,23 +259,23 @@ bool getSwitch(int8_t swtch) } } else if (s == LS_FAMILY_TIMER) { - result = (csLastValue[cs_idx] <= 0); + result = (lsLastValue[cs_idx] <= 0); } else if (s == LS_FAMILY_STICKY) { - result = (csLastValue[cs_idx] & (1<<0)); + result = (lsLastValue[cs_idx] & (1<<0)); } #if defined(CPUARM) else if (s == LS_FAMILY_STAY) { - result = (csLastValue[cs_idx] & (1<<0)); + result = (lsLastValue[cs_idx] & (1<<0)); } #endif else { - getvalue_t x = getValue(cs->v1); + getvalue_t x = getValue(ls->v1); getvalue_t y; if (s == LS_FAMILY_COMP) { - y = getValue(cs->v2); + y = getValue(ls->v2); - switch (cs->func) { + switch (ls->func) { case LS_FUNC_EQUAL: result = (x==y); break; @@ -288,44 +288,44 @@ bool getSwitch(int8_t swtch) } } else { - uint8_t v1 = cs->v1; + uint8_t v1 = ls->v1; #if defined(FRSKY) // Telemetry if (v1 >= MIXSRC_FIRST_TELEM) { if ((!TELEMETRY_STREAMING() && v1 >= MIXSRC_FIRST_TELEM+TELEM_FIRST_STREAMED_VALUE-1) || IS_FAI_FORBIDDEN(v1-1)) return swtch > 0 ? false : true; - y = convertCswTelemValue(cs); + y = convertLswTelemValue(ls); #if defined(FRSKY_HUB) && defined(GAUGES) if (s == LS_FAMILY_OFS) { uint8_t idx = v1-MIXSRC_FIRST_TELEM+1-TELEM_ALT; if (idx < THLD_MAX) { // Fill the threshold array - barsThresholds[idx] = 128 + cs->v2; + barsThresholds[idx] = 128 + ls->v2; } } #endif } else if (v1 >= MIXSRC_GVAR1) { - y = cs->v2; + y = ls->v2; } else { - y = calc100toRESX(cs->v2); + y = calc100toRESX(ls->v2); } #else if (v1 >= MIXSRC_FIRST_TELEM) { - y = (int16_t)3 * (128+cs->v2); // it's a Timer + y = (int16_t)3 * (128+ls->v2); // it's a Timer } else if (v1 >= MIXSRC_GVAR1) { - y = cs->v2; // it's a GVAR + y = ls->v2; // it's a GVAR } else { - y = calc100toRESX(cs->v2); + y = calc100toRESX(ls->v2); } #endif - switch (cs->func) { + switch (ls->func) { #if defined(CPUARM) case LS_FUNC_VEQUAL: result = (x==y); @@ -353,15 +353,15 @@ bool getSwitch(int8_t swtch) break; default: { - if (csLastValue[cs_idx] == CS_LAST_VALUE_INIT) - csLastValue[cs_idx] = x; - int16_t diff = x - csLastValue[cs_idx]; - if (cs->func == LS_FUNC_DIFFEGREATER) + if (lsLastValue[cs_idx] == CS_LAST_VALUE_INIT) + lsLastValue[cs_idx] = x; + int16_t diff = x - lsLastValue[cs_idx]; + if (ls->func == LS_FUNC_DIFFEGREATER) result = (y >= 0 ? (diff >= y) : (diff <= y)); else result = (abs(diff) >= y); if (result) - csLastValue[cs_idx] = x; + lsLastValue[cs_idx] = x; break; } } @@ -369,25 +369,25 @@ bool getSwitch(int8_t swtch) } #if defined(CPUARM) - if (cs->delay) { + if (ls->delay) { if (result) { - if (cswDelays[cs_idx] > get_tmr10ms()) + if (lswDelays[cs_idx] > get_tmr10ms()) result = false; } else { - cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*10); + lswDelays[cs_idx] = get_tmr10ms() + (ls->delay*10); } } - if (cs->duration) { - if (result && !cswStates[cs_idx]) { - cswDurations[cs_idx] = get_tmr10ms() + (cs->duration*10); + if (ls->duration) { + if (result && !lswStates[cs_idx]) { + lswDurations[cs_idx] = get_tmr10ms() + (ls->duration*10); } - cswStates[cs_idx] = result; + lswStates[cs_idx] = result; result = false; - if (cswDurations[cs_idx] > get_tmr10ms()) { + if (lswDurations[cs_idx] > get_tmr10ms()) { result = true; } } @@ -599,31 +599,31 @@ void checkSwitches() -void evalLogicalSwitchTimers() { +void lswTimerTick() { for (uint8_t i=0; ifunc == LS_FUNC_TIMER) { - int16_t *lastValue = &csLastValue[i]; + LogicalSwitchData * ls = lswAddress(i); + if (ls->func == LS_FUNC_TIMER) { + int16_t *lastValue = &lsLastValue[i]; if (*lastValue == 0 || *lastValue == CS_LAST_VALUE_INIT) { - *lastValue = -cswTimerValue(cs->v1); + *lastValue = -lswTimerValue(ls->v1); } else if (*lastValue < 0) { if (++(*lastValue) == 0) - *lastValue = cswTimerValue(cs->v2); + *lastValue = lswTimerValue(ls->v2); } else { // if (*lastValue > 0) *lastValue -= 1; } } - else if (cs->func == LS_FUNC_STICKY) { + else if (ls->func == LS_FUNC_STICKY) { PACK(typedef struct { uint8_t state; uint8_t last; - }) cs_sticky_struct; - cs_sticky_struct & lastValue = (cs_sticky_struct &)csLastValue[i]; + }) ls_sticky_struct; + ls_sticky_struct & lastValue = (ls_sticky_struct &)lsLastValue[i]; bool before = lastValue.last & 0x01; if (lastValue.state) { - bool now = getSwitch(cs->v2); + bool now = getSwitch(ls->v2); if (now != before) { lastValue.last ^= 1; if (!before) { @@ -632,7 +632,7 @@ void evalLogicalSwitchTimers() { } } else { - bool now = getSwitch(cs->v1); + bool now = getSwitch(ls->v1); if (before != now) { lastValue.last ^= 1; if (!before) { @@ -642,23 +642,23 @@ void evalLogicalSwitchTimers() { } } //#if defined(CPUARM) - else if (cs->func == LS_FUNC_STAY) { + else if (ls->func == LS_FUNC_STAY) { PACK(typedef struct { uint16_t state:1; uint16_t duration:15; - }) cs_stay_struct; + }) ls_stay_struct; - cs_stay_struct & lastValue = (cs_stay_struct &)csLastValue[i]; + ls_stay_struct & lastValue = (ls_stay_struct &)lsLastValue[i]; lastValue.state = false; - bool state = getSwitch(cs->v1); + bool state = getSwitch(ls->v1); if (state) { - if (cs->v3 == 0 && lastValue.duration == cswTimerValue(cs->v2)) + if (ls->v3 == 0 && lastValue.duration == lswTimerValue(ls->v2)) lastValue.state = true; if (lastValue.duration < 1000) lastValue.duration++; } else { - if (lastValue.duration > cswTimerValue(cs->v2) && lastValue.duration <= cswTimerValue(cs->v2+cs->v3)) + if (lastValue.duration > lswTimerValue(ls->v2) && lastValue.duration <= lswTimerValue(ls->v2+ls->v3)) lastValue.state = true; lastValue.duration = 0; } @@ -667,9 +667,9 @@ void evalLogicalSwitchTimers() { } } -LogicalSwitchData *cswAddress(uint8_t idx) +LogicalSwitchData *lswAddress(uint8_t idx) { - return &g_model.customSw[idx]; + return &g_model.logicalSw[idx]; } uint8_t cswFamily(uint8_t func) @@ -690,27 +690,27 @@ uint8_t cswFamily(uint8_t func) return LS_FAMILY_TIMER+func-LS_FUNC_TIMER; } -int16_t cswTimerValue(delayval_t val) +int16_t lswTimerValue(delayval_t val) { return (val < -109 ? 129+val : (val < 7 ? (113+val)*5 : (53+val)*10)); } -void logicalSwitchesReset() { +void lswReset() { for (uint8_t i=0; iv1 - MIXSRC_FIRST_TELEM + 1, cs->v2); + val = convert16bitsTelemValue(ls->v1 - MIXSRC_FIRST_TELEM + 1, ls->v2); #else - if (cswFamily(cs->func)==LS_FAMILY_OFS) - val = convert8bitsTelemValue(cs->v1 - MIXSRC_FIRST_TELEM + 1, 128+cs->v2); + if (cswFamily(ls->func)==LS_FAMILY_OFS) + val = convert8bitsTelemValue(ls->v1 - MIXSRC_FIRST_TELEM + 1, 128+ls->v2); else - val = convert8bitsTelemValue(cs->v1 - MIXSRC_FIRST_TELEM + 1, 128+cs->v2) - convert8bitsTelemValue(cs->v1 - MIXSRC_FIRST_TELEM + 1, 128); + val = convert8bitsTelemValue(ls->v1 - MIXSRC_FIRST_TELEM + 1, 128+ls->v2) - convert8bitsTelemValue(ls->v1 - MIXSRC_FIRST_TELEM + 1, 128); #endif return val; } diff --git a/radio/src/templates.cpp b/radio/src/templates.cpp index 07e2c9670..6f5eff3df 100644 --- a/radio/src/templates.cpp +++ b/radio/src/templates.cpp @@ -149,9 +149,9 @@ void setCurve(uint8_t c, const pm_int8_t ar[]) } } -void setSwitch(uint8_t idx, uint8_t func, int8_t v1, int8_t v2) +void setLogicalSwitch(uint8_t idx, uint8_t func, int8_t v1, int8_t v2) { - LogicalSwitchData *cs = cswAddress(idx-1); + LogicalSwitchData *cs = lswAddress(idx-1); cs->func = func; cs->v1 = v1; cs->v2 = v2; @@ -200,8 +200,8 @@ void applyTemplate(uint8_t idx) md=setDest(13, MIXSRC_CH14); // md->weight= 100; done by setDest anyway md=setDest(13, MIXSRC_MAX); mixSetWeight(md, -100); md->swtch=SWSRC_SWB; md->mltpx=MLTPX_REP; md=setDest(13, MIXSRC_MAX); /* md->weight= 100;*/ md->swtch=SWSRC_THR; md->mltpx=MLTPX_REP; - setSwitch(11, LS_FUNC_VNEG, STK_THR, -99); - setSwitch(12, LS_FUNC_VPOS, MIXSRC_CH14, 0); + setLogicalSwitch(11, LS_FUNC_VNEG, STK_THR, -99); + setLogicalSwitch(12, LS_FUNC_VPOS, MIXSRC_CH14, 0); break; // V-Tail @@ -285,7 +285,7 @@ void applyTemplate(uint8_t idx) // Servo Test case TMPL_SERVO_TEST: md=setDest(NUM_CHNOUT-1, MIXSRC_SW1, true); md->weight=110; md->mltpx=MLTPX_ADD; md->delayUp = 6; md->delayDown = 6; md->speedUp = 8; md->speedDown = 8; - setSwitch(1, LS_FUNC_VNEG, MIXSRC_LAST_CH, 0); + setLogicalSwitch(1, LS_FUNC_VNEG, MIXSRC_LAST_CH, 0); break; default: