From 397674021e79a81c8062a9373ef892882d41aae9 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 26 Oct 2021 13:02:03 +0200 Subject: [PATCH] Improved logical switches --- radio/src/datastructs.h | 9 +- radio/src/globals.h | 2 +- .../src/gui/128x64/model_logical_switches.cpp | 1 + .../src/gui/212x64/model_logical_switches.cpp | 1 + .../gui/colorlcd/model_logical_switches.cpp | 1 + radio/src/gui/colorlcd/switches.h | 40 ++++++++ radio/src/mixer.cpp | 1 + radio/src/opentx.h | 14 --- .../conversions/yaml/yaml_datastructs.cpp | 2 + .../yaml/yaml_datastructs_funcs.cpp | 63 +++++++++++++ .../yaml/yaml_datastructs_nv14.cpp | 7 +- .../conversions/yaml/yaml_datastructs_t12.cpp | 7 +- .../conversions/yaml/yaml_datastructs_t8.cpp | 7 +- .../yaml/yaml_datastructs_tlite.cpp | 7 +- .../yaml/yaml_datastructs_tx12.cpp | 7 +- .../conversions/yaml/yaml_datastructs_x10.cpp | 7 +- .../yaml/yaml_datastructs_x12s.cpp | 8 +- .../conversions/yaml/yaml_datastructs_x7.cpp | 7 +- .../conversions/yaml/yaml_datastructs_x9d.cpp | 7 +- .../conversions/yaml/yaml_datastructs_x9e.cpp | 7 +- .../yaml/yaml_datastructs_x9lite.cpp | 7 +- .../yaml/yaml_datastructs_x9lites.cpp | 7 +- .../yaml/yaml_datastructs_xlite.cpp | 7 +- .../yaml/yaml_datastructs_xlites.cpp | 7 +- .../storage/yaml/yaml_datastructs_funcs.cpp | 91 +++++++++++++++++++ .../storage/yaml/yaml_datastructs_nv14.cpp | 7 +- .../src/storage/yaml/yaml_datastructs_t12.cpp | 7 +- .../src/storage/yaml/yaml_datastructs_t8.cpp | 7 +- .../storage/yaml/yaml_datastructs_tlite.cpp | 7 +- .../storage/yaml/yaml_datastructs_tx12.cpp | 7 +- .../src/storage/yaml/yaml_datastructs_x10.cpp | 7 +- .../storage/yaml/yaml_datastructs_x12s.cpp | 8 +- .../src/storage/yaml/yaml_datastructs_x7.cpp | 7 +- .../src/storage/yaml/yaml_datastructs_x9d.cpp | 7 +- .../src/storage/yaml/yaml_datastructs_x9e.cpp | 7 +- .../storage/yaml/yaml_datastructs_x9lite.cpp | 7 +- .../storage/yaml/yaml_datastructs_x9lites.cpp | 7 +- .../storage/yaml/yaml_datastructs_xlite.cpp | 7 +- .../storage/yaml/yaml_datastructs_xlites.cpp | 7 +- radio/src/switches.cpp | 5 + radio/src/switches.h | 40 ++++++++ 41 files changed, 365 insertions(+), 103 deletions(-) create mode 100644 radio/src/gui/colorlcd/switches.h create mode 100644 radio/src/switches.h diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 72709b784..43a1c18f1 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -130,12 +130,13 @@ PACK(struct LimitData { PACK(struct LogicalSwitchData { uint8_t func ENUM(LogicalSwitchesFunctions); - int32_t v1:10; - int32_t v3:10; + CUST_ATTR(def,r_logicSw,w_logicSw); + int32_t v1:10 SKIP; + int32_t v3:10 SKIP; int32_t andsw:9 CUST(r_swtchSrc,w_swtchSrc); // TODO rename to xswtch uint32_t andswtype:1 SKIP; // TODO rename to xswtchType (AND / OR) uint32_t spare:2 SKIP; // anything else needed? - int16_t v2; + int16_t v2 SKIP; uint8_t delay; uint8_t duration; }); @@ -171,7 +172,7 @@ PACK(struct CustomFunctionData { int32_t val1; NOBACKUP(CFN_SPARE_TYPE val2); }) clear); - }) SKIP; + }) NAME(fp) SKIP; uint8_t active SKIP; bool isEmpty() const diff --git a/radio/src/globals.h b/radio/src/globals.h index 8b06d3261..8eb8a59c6 100644 --- a/radio/src/globals.h +++ b/radio/src/globals.h @@ -61,7 +61,7 @@ enum MainRequest { extern uint8_t mainRequestFlags; #define DELAY_POS_MARGIN 3 -typedef int16_t delayval_t; + PACK(struct SwOn { uint16_t delay:14; // max = 2550 uint8_t activeMix:1; diff --git a/radio/src/gui/128x64/model_logical_switches.cpp b/radio/src/gui/128x64/model_logical_switches.cpp index 4710e476f..f8880710a 100644 --- a/radio/src/gui/128x64/model_logical_switches.cpp +++ b/radio/src/gui/128x64/model_logical_switches.cpp @@ -20,6 +20,7 @@ */ #include "opentx.h" +#include "switches.h" enum LogicalSwitchFields { LS_FIELD_FUNCTION, diff --git a/radio/src/gui/212x64/model_logical_switches.cpp b/radio/src/gui/212x64/model_logical_switches.cpp index 36ac110d1..7f17e7fbe 100644 --- a/radio/src/gui/212x64/model_logical_switches.cpp +++ b/radio/src/gui/212x64/model_logical_switches.cpp @@ -20,6 +20,7 @@ */ #include "opentx.h" +#include "switches.h" enum LogicalSwitchFields { LS_FIELD_FUNCTION, diff --git a/radio/src/gui/colorlcd/model_logical_switches.cpp b/radio/src/gui/colorlcd/model_logical_switches.cpp index 8ac931800..542904308 100644 --- a/radio/src/gui/colorlcd/model_logical_switches.cpp +++ b/radio/src/gui/colorlcd/model_logical_switches.cpp @@ -22,6 +22,7 @@ #include "model_logical_switches.h" #include "opentx.h" #include "libopenui.h" +#include "switches.h" #define SET_DIRTY() storageDirty(EE_MODEL) diff --git a/radio/src/gui/colorlcd/switches.h b/radio/src/gui/colorlcd/switches.h new file mode 100644 index 000000000..1b272483b --- /dev/null +++ b/radio/src/gui/colorlcd/switches.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include + +enum LogicalSwitchFamilies { + LS_FAMILY_OFS, + LS_FAMILY_BOOL, + LS_FAMILY_COMP, + LS_FAMILY_DIFF, + LS_FAMILY_TIMER, + LS_FAMILY_STICKY, + LS_FAMILY_RANGE, + LS_FAMILY_EDGE +}; + +typedef int16_t delayval_t; + +uint8_t lswFamily(uint8_t func); +int16_t lswTimerValue(delayval_t val); diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index e19cc6637..92214f605 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -21,6 +21,7 @@ #include "opentx.h" #include "timers.h" +#include "switches.h" int8_t virtualInputsTrims[MAX_INPUTS]; int16_t anas [MAX_INPUTS] = {0}; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 7b824087a..0b5ac805e 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -818,20 +818,6 @@ inline bool isMixActive(uint8_t mix) return swOn[mix].activeMix; } -enum LogicalSwitchFamilies { - LS_FAMILY_OFS, - LS_FAMILY_BOOL, - LS_FAMILY_COMP, - LS_FAMILY_DIFF, - LS_FAMILY_TIMER, - LS_FAMILY_STICKY, - LS_FAMILY_RANGE, - LS_FAMILY_EDGE -}; - -uint8_t lswFamily(uint8_t func); -int16_t lswTimerValue(delayval_t val); - enum FunctionsActive { FUNCTION_TRAINER_STICK1, FUNCTION_TRAINER_CHANNELS = FUNCTION_TRAINER_STICK1 + NUM_STICKS, diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs.cpp index 1206b4a7d..59ae1a3e8 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs.cpp @@ -28,6 +28,8 @@ #include #include +#include "switches.h" + namespace yaml_conv_220 { #include "yaml_datastructs_funcs.cpp" diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index b5e2f4511..bf7b84068 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -823,3 +823,66 @@ bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, } return true; } + +#define r_logicSw nullptr + +static const struct YamlNode _ls_node_v1 = YAML_PADDING(10); +static const struct YamlNode _ls_node_v2 = YAML_PADDING(16); + +bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + data += bitoffs >> 3UL; + data -= sizeof(LogicalSwitchData::func); + + const char* str = nullptr; + auto ls = reinterpret_cast(data); + switch(lswFamily(ls->func)) { + + case LS_FAMILY_BOOL: + case LS_FAMILY_STICKY: + if (!w_swtchSrc(&_ls_node_v1, ls->v1, wf, opaque)) return false; + if (!wf(opaque,",",1)) return false; + if (!w_swtchSrc(&_ls_node_v2, ls->v2, wf, opaque)) return false; + break; + + case LS_FAMILY_EDGE: + if (!w_swtchSrc(&_ls_node_v1, ls->v1, wf, opaque)) return false; + if (!wf(opaque,",",1)) return false; + str = yaml_unsigned2str(lswTimerValue(ls->v2)); + if (!wf(opaque,str,strlen(str))) return false; + if (!wf(opaque,",",1)) return false; + if (ls->v3 < 0) { + if (!wf(opaque,"<",1)) return false; + } else if(ls->v3 == 0) { + if (!wf(opaque,"-",1)) return false; + } else { + str = yaml_unsigned2str(lswTimerValue(ls->v2 + ls->v3)); + } + break; + + case LS_FAMILY_COMP: + if (!w_mixSrcRaw(nullptr, ls->v1, wf, opaque)) return false; + if (!wf(opaque,",",1)) return false; + if (!w_mixSrcRaw(nullptr, ls->v2, wf, opaque)) return false; + break; + + case LS_FAMILY_TIMER: + str = yaml_unsigned2str(lswTimerValue(ls->v1)); + if (!wf(opaque,str,strlen(str))) return false; + if (!wf(opaque,",",1)) return false; + str = yaml_unsigned2str(lswTimerValue(ls->v2)); + if (!wf(opaque,str,strlen(str))) return false; + break; + + default: + if (!w_mixSrcRaw(nullptr, ls->v1, wf, opaque)) return false; + if (!wf(opaque,",",1)) return false; + // TODO?: ls->v1 <= MIXSRC_LAST_CH ? calc100toRESX(ls->v2) : ls->v2 + str = yaml_signed2str(ls->v2); + if (!wf(opaque,str,strlen(str))) return false; + break; + } + + return true; +} diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index d9d97a1d6..cd04f3422 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -522,12 +522,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp index 7871c3131..b35ec6ef2 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index 9d689f2d3..92980839e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -539,12 +539,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index 7c66dc58e..21d8ccd95 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -66,6 +66,7 @@ const struct YamlIdStr enum_Functions[] = { { FUNC_BACKLIGHT, "BACKLIGHT" }, { FUNC_SCREENSHOT, "SCREENSHOT" }, { FUNC_RACING_MODE, "RACING_MODE" }, + { FUNC_DISABLE_TOUCH, "DISABLE_TOUCH" }, { 0, NULL } }; const struct YamlIdStr enum_UartModes[] = { @@ -538,12 +539,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp index 6d794b55a..49084757c 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp @@ -499,12 +499,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp index 0fd22eba4..ca024b019 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp @@ -538,12 +538,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp index 4b8536d6d..de87dd052 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp @@ -476,12 +476,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp index 32229c287..6e1beb9a6 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp @@ -486,12 +486,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp index f83978aab..75e7f7ca8 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp @@ -483,12 +483,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp index c6ddd9ec9..c2299506a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp @@ -487,12 +487,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 96afe9421..97ba9da37 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -67,6 +67,9 @@ namespace yaml_conv_220 { bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, yaml_writer_func wf, void* opaque); + + bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque); }; // @@ -1044,3 +1047,91 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, { return yaml_conv_220::w_customFn(user, data, bitoffs, wf, opaque); } + +#include "switches.h" + +static delayval_t timerValue2lsw(uint32_t t) +{ + if (t < 20) { + return t - 129; + } else if (600) { + return t / 5 - 113; + } else { + return t / 10 - 53; + } +} + +static void r_logicSw(void* user, uint8_t* data, uint32_t bitoffs, + const char* val, uint8_t val_len) +{ + data += bitoffs >> 3UL; + data -= sizeof(LogicalSwitchData::func); + + // find "," and cut val_len + const char* sep = (const char *)memchr(val, ',', val_len); + uint8_t l_sep = sep ? sep - val : val_len; + + auto ls = reinterpret_cast(data); + switch(lswFamily(ls->func)) { + + case LS_FAMILY_BOOL: + case LS_FAMILY_STICKY: + ls->v1 = r_swtchSrc(nullptr, val, l_sep); + val += l_sep; val_len -= l_sep; + if (!val_len || val[0] != ',') return; + val++; val_len--; + ls->v2 = r_swtchSrc(nullptr, val, val_len); + break; + + case LS_FAMILY_EDGE: + ls->v1 = r_swtchSrc(nullptr, val, l_sep); + val += l_sep; val_len -= l_sep; + if (!val_len || val[0] != ',') return; + val++; val_len--; + ls->v2 = timerValue2lsw(yaml_str2uint_ref(val, val_len)); + if (!val_len || val[0] != ',') return; + val++; val_len--; + if (val_len == 1) { + if (val[0] == '<') + ls->v3 = -1; + else if (val[0] == '-') + ls->v3 = 0; + } else { + int16_t t = (int16_t)timerValue2lsw(yaml_str2uint_ref(val, val_len)); + ls->v3 = t - ls->v2; + } + break; + + case LS_FAMILY_COMP: + ls->v1 = r_mixSrcRaw(nullptr, val, l_sep); + val += l_sep; val_len -= l_sep; + if (!val_len || val[0] != ',') return; + val++; val_len--; + ls->v2 = r_mixSrcRaw(nullptr, val, val_len); + break; + + case LS_FAMILY_TIMER: + ls->v1 = timerValue2lsw(yaml_str2uint(val, l_sep)); + val += l_sep; val_len -= l_sep; + if (!val_len || val[0] != ',') return; + val++; val_len--; + ls->v2 = timerValue2lsw(yaml_str2uint(val, val_len)); + break; + + default: + ls->v1 = r_mixSrcRaw(nullptr, val, l_sep); + val += l_sep; val_len -= l_sep; + if (!val_len || val[0] != ',') return; + val++; val_len--; + // TODO?: ls->v1 <= MIXSRC_LAST_CH ? calc100toRESX(ls->v2) : ls->v2 + ls->v2 = yaml_str2int_ref(val, val_len); + break; + } + +} + +static bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + return yaml_conv_220::w_logicSw(user, data, bitoffs, wf, opaque); +} diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index d9d97a1d6..cd04f3422 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -522,12 +522,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 7871c3131..b35ec6ef2 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 9d689f2d3..92980839e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -539,12 +539,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 7c66dc58e..21d8ccd95 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -66,6 +66,7 @@ const struct YamlIdStr enum_Functions[] = { { FUNC_BACKLIGHT, "BACKLIGHT" }, { FUNC_SCREENSHOT, "SCREENSHOT" }, { FUNC_RACING_MODE, "RACING_MODE" }, + { FUNC_DISABLE_TOUCH, "DISABLE_TOUCH" }, { 0, NULL } }; const struct YamlIdStr enum_UartModes[] = { @@ -538,12 +539,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index b73889039..f40f25d6e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -491,12 +491,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 6d794b55a..49084757c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -499,12 +499,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 0fd22eba4..ca024b019 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -538,12 +538,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 4b8536d6d..de87dd052 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -476,12 +476,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 32229c287..6e1beb9a6 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -486,12 +486,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index f83978aab..75e7f7ca8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -483,12 +483,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index c6ddd9ec9..c2299506a 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -487,12 +487,13 @@ static const struct YamlNode struct_signed_8[] = { static const struct YamlNode struct_LogicalSwitchData[] = { YAML_IDX, YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions), - YAML_SIGNED( "v1", 10 ), - YAML_SIGNED( "v3", 10 ), + YAML_CUSTOM("def",r_logicSw,w_logicSw), + YAML_PADDING( 10 ), + YAML_PADDING( 10 ), YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ), YAML_PADDING( 1 ), YAML_PADDING( 2 ), - YAML_SIGNED( "v2", 16 ), + YAML_PADDING( 16 ), YAML_UNSIGNED( "delay", 8 ), YAML_UNSIGNED( "duration", 8 ), YAML_END diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 296f5ab9e..325f3d35a 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -20,6 +20,7 @@ */ #include "opentx.h" +#include "switches.h" #define CS_LAST_VALUE_INIT -32768 @@ -881,6 +882,10 @@ uint8_t lswFamily(uint8_t func) return LS_FAMILY_TIMER+func-LS_FUNC_TIMER; } +// val = [-129,-110] => [0,19] (step 1) +// val = [-109,6] => [20,595] (step 5) +// val = [7,122] => [600,1750] (step 10) +// int16_t lswTimerValue(delayval_t val) { return (val < -109 ? 129+val : (val < 7 ? (113+val)*5 : (53+val)*10)); diff --git a/radio/src/switches.h b/radio/src/switches.h new file mode 100644 index 000000000..1b272483b --- /dev/null +++ b/radio/src/switches.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include + +enum LogicalSwitchFamilies { + LS_FAMILY_OFS, + LS_FAMILY_BOOL, + LS_FAMILY_COMP, + LS_FAMILY_DIFF, + LS_FAMILY_TIMER, + LS_FAMILY_STICKY, + LS_FAMILY_RANGE, + LS_FAMILY_EDGE +}; + +typedef int16_t delayval_t; + +uint8_t lswFamily(uint8_t func); +int16_t lswTimerValue(delayval_t val);