Improved logical switches

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:02 +01:00
parent 4333e4267c
commit 397674021e
41 changed files with 365 additions and 103 deletions
+5 -4
View File
@@ -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
+1 -1
View File
@@ -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;
@@ -20,6 +20,7 @@
*/
#include "opentx.h"
#include "switches.h"
enum LogicalSwitchFields {
LS_FIELD_FUNCTION,
@@ -20,6 +20,7 @@
*/
#include "opentx.h"
#include "switches.h"
enum LogicalSwitchFields {
LS_FIELD_FUNCTION,
@@ -22,6 +22,7 @@
#include "model_logical_switches.h"
#include "opentx.h"
#include "libopenui.h"
#include "switches.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
+40
View File
@@ -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 <cinttypes>
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);
+1
View File
@@ -21,6 +21,7 @@
#include "opentx.h"
#include "timers.h"
#include "switches.h"
int8_t virtualInputsTrims[MAX_INPUTS];
int16_t anas [MAX_INPUTS] = {0};
-14
View File
@@ -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,
@@ -28,6 +28,8 @@
#include <debug.h>
#include <string.h>
#include "switches.h"
namespace yaml_conv_220 {
#include "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<LogicalSwitchData*>(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;
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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<LogicalSwitchData*>(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);
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
+5
View File
@@ -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));
+40
View File
@@ -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 <cinttypes>
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);