feat: add inverted sources (#4722)

Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Neil Horne
2024-05-25 09:25:15 +10:00
committed by GitHub
co-authored by elecpower
parent ca50d4ee04
commit 80659c3e3f
87 changed files with 798 additions and 496 deletions
@@ -395,7 +395,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -429,7 +429,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -417,6 +417,38 @@ static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf,
return true;
}
static uint32_t r_mixSrcRawEx(const YamlNode* node, const char* val, uint8_t val_len)
{
bool invert = false;
if (val[0] == '!') {
invert = true;
val += 1;
val_len -= 1;
}
int32_t rv = r_mixSrcRaw(node, val, val_len);
if (invert)
rv = -rv;
return (uint32_t)rv;
}
static bool w_mixSrcRawExNoQuote(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
// Check for negative 10 bit value. TODO: handle this better!
val &= 0x3FF;
if (val >= 512) {
if (!wf(opaque, "!", 1)) return false;
val = 1024 - val;
}
return w_mixSrcRaw(node, val, wf, opaque);
}
static bool w_mixSrcRawEx(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
if (!wf(opaque, "\"", 1)) return false;
if (!w_mixSrcRawExNoQuote(node, val, wf, opaque)) return false;
return wf(opaque, "\"", 1);
}
static void r_rssiDisabled(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
@@ -1459,7 +1491,7 @@ static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs,
case FUNC_BACKLIGHT:
case FUNC_PLAY_VALUE:
// find "," and cut val_len
CFN_PARAM(cfn) = r_mixSrcRaw(nullptr, val, l_sep);
CFN_PARAM(cfn) = r_mixSrcRawEx(nullptr, val, l_sep);
break;
case FUNC_PLAY_SOUND:
@@ -1554,10 +1586,10 @@ static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs,
CFN_PARAM(cfn) = yaml_str2int(val, l_sep);
break;
case FUNC_ADJUST_GVAR_SOURCE:
CFN_PARAM(cfn) = r_mixSrcRaw(nullptr, val, l_sep);
CFN_PARAM(cfn) = r_mixSrcRawEx(nullptr, val, l_sep);
break;
case FUNC_ADJUST_GVAR_GVAR: {
uint32_t gvar = r_mixSrcRaw(nullptr, val, l_sep);
uint32_t gvar = r_mixSrcRawEx(nullptr, val, l_sep);
if (gvar >= MIXSRC_FIRST_GVAR) {
CFN_PARAM(cfn) = gvar - MIXSRC_FIRST_GVAR;
}
@@ -1680,7 +1712,7 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
case FUNC_VOLUME:
case FUNC_BACKLIGHT:
case FUNC_PLAY_VALUE:
if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn), wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(nullptr, CFN_PARAM(cfn), wf, opaque)) return false;
break;
case FUNC_PLAY_SOUND:
@@ -1739,10 +1771,10 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_ADJUST_GVAR_SOURCE:
if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn), wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(nullptr, CFN_PARAM(cfn), wf, opaque)) return false;
break;
case FUNC_ADJUST_GVAR_GVAR:
if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn) + MIXSRC_FIRST_GVAR, wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(nullptr, CFN_PARAM(cfn) + MIXSRC_FIRST_GVAR, wf, opaque)) return false;
break;
}
break;
@@ -1837,11 +1869,11 @@ static void r_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
break;
case LS_FAMILY_COMP:
ls->v1 = r_mixSrcRaw(nullptr, val, l_sep);
ls->v1 = r_mixSrcRawEx(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);
ls->v2 = r_mixSrcRawEx(nullptr, val, val_len);
break;
case LS_FAMILY_TIMER:
@@ -1853,7 +1885,7 @@ static void r_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
break;
default:
ls->v1 = r_mixSrcRaw(nullptr, val, l_sep);
ls->v1 = r_mixSrcRawEx(nullptr, val, l_sep);
val += l_sep; val_len -= l_sep;
if (!val_len || val[0] != ',') return;
val++; val_len--;
@@ -1902,9 +1934,9 @@ static bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
break;
case LS_FAMILY_COMP:
if (!w_mixSrcRaw(nullptr, ls->v1, wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(nullptr, ls->v1, wf, opaque)) return false;
if (!wf(opaque,",",1)) return false;
if (!w_mixSrcRaw(nullptr, ls->v2, wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(nullptr, ls->v2, wf, opaque)) return false;
break;
case LS_FAMILY_TIMER:
@@ -1916,7 +1948,7 @@ static bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
break;
default:
if (!w_mixSrcRaw(nullptr, ls->v1, wf, opaque)) return false;
if (!w_mixSrcRawExNoQuote(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);
@@ -422,7 +422,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -456,7 +456,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -422,7 +422,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -456,7 +456,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -395,7 +395,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -429,7 +429,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -395,7 +395,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -429,7 +429,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -424,7 +424,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -458,7 +458,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -424,7 +424,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -458,7 +458,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -395,7 +395,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -429,7 +429,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -396,7 +396,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -430,7 +430,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
@@ -398,7 +398,7 @@ static const struct YamlNode struct_CurveRef[] = {
static const struct YamlNode struct_MixData[] = {
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
@@ -432,7 +432,7 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED( "scale", 14 ),
YAML_CUSTOM("carryTrim",r_carryTrim,nullptr),
YAML_SIGNED( "trimSource", 6 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED_CUST( "srcRaw", 10, r_mixSrcRawEx, w_mixSrcRawEx ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),