Improve custom functions

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:02 +01:00
parent 3da2aee1ff
commit b5e9c68056
31 changed files with 481 additions and 132 deletions
+5 -4
View File
@@ -154,6 +154,7 @@ PACK(struct LogicalSwitchData {
PACK(struct CustomFunctionData {
int16_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
uint16_t func:7 ENUM(Functions);
CUST_ATTR(def,r_customFn,w_customFn);
PACK(union {
NOBACKUP(PACK(struct {
char name[LEN_FUNCTION_NAME];
@@ -163,15 +164,15 @@ PACK(struct CustomFunctionData {
int16_t val;
uint8_t mode;
uint8_t param;
NOBACKUP(CFN_SPARE_TYPE spare SKIP);
NOBACKUP(CFN_SPARE_TYPE spare);
}) all;
NOBACKUP(PACK(struct {
int32_t val1;
NOBACKUP(CFN_SPARE_TYPE val2 SKIP);
NOBACKUP(CFN_SPARE_TYPE val2);
}) clear);
}) NAME(fp) FUNC(select_custom_fn);
uint8_t active;
}) SKIP;
uint8_t active SKIP;
bool isEmpty() const
{
@@ -210,23 +210,7 @@ uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
return 0;
}
uint8_t select_custom_fn(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(CustomFunctionData, all);
auto cf = reinterpret_cast<CustomFunctionData*>(data);
switch(cf->func) {
case FUNC_PLAY_TRACK:
case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT:
// play: 0
return 0;
}
// all: 1
return 1;
}
uint8_t select_script_input(void* user, uint8_t* data, uint32_t bitoffs)
{
@@ -698,3 +682,144 @@ bool w_flightModes(const YamlNode* node, uint32_t val,
}
return true;
}
#define r_customFn nullptr
static const char* _func_reset_param_lookup[] = {
"Tmr1","Tmr2","Tmr3","All","Tele"
};
static const char* _func_failsafe_lookup[] = {
"Int","Ext"
};
// used in read routine as well
const char* _func_sound_lookup[] = {
"Bp1","Bp2","Bp3","Wrn1","Wrn2",
"Chee","Rata","Tick","Sirn","Ring",
"SciF","Robt","Chrp","Tada","Crck","Alrm"
};
// force external linkage
extern const uint8_t _func_sound_lookup_size = sizeof(_func_sound_lookup);
bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data += bitoffs >> 3UL;
data -= offsetof(CustomFunctionData, all);
auto cfn = reinterpret_cast<CustomFunctionData*>(data);
uint8_t func = CFN_FUNC(cfn);
const char* str = nullptr;
switch (func) {
case FUNC_OVERRIDE_CHANNEL:
str = yaml_unsigned2str(CFN_CH_INDEX(cfn)); // CH index
if (!wf(opaque, str, strlen(str))) return false;
if (!wf(opaque, ",", 1)) return false;
str = yaml_unsigned2str(CFN_PARAM(cfn)); // value
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_TRAINER: {
int16_t value = CFN_CH_INDEX(cfn);
switch(value) {
case 0:
if (!wf(opaque, "sticks", 6)) return false;
break;
case NUM_STICKS + 1:
if (!wf(opaque, "chans", 5)) return false;
break;
default:
if (value > 0 && value < NUM_STICKS + 1) {
str = yaml_output_enum(value - 1 + MIXSRC_FIRST_STICK, enum_MixSources);
if (str && !wf(opaque, str, strlen(str))) return false;
}
}
} break;
case FUNC_RESET:
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
// Tmr1,Tmr2,Tmr3,All
str = _func_reset_param_lookup[CFN_PARAM(cfn)];
} else {
// sensor index
str = yaml_unsigned2str(CFN_PARAM(cfn) - FUNC_RESET_PARAM_FIRST_TELEM);
}
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_VOLUME:
case FUNC_BACKLIGHT:
case FUNC_PLAY_VALUE:
if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn), wf, opaque)) return false;
break;
case FUNC_PLAY_SOUND:
// Bp1,Bp2,Bp3,Wrn1,Wrn2,Chee,Rata,Tick,Sirn,Ring,SciF,Robt,Chrp,Tada,Crck,Alrm
str = _func_sound_lookup[CFN_PARAM(cfn)];
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_PLAY_TRACK:
case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT:
if (!wf(opaque, cfn->play.name, strnlen(cfn->play.name, LEN_FUNCTION_NAME)))
return false;
break;
case FUNC_SET_TIMER:
// Tmr1,Tmr2,Tmr3
str = _func_reset_param_lookup[CFN_TIMER_INDEX(cfn)];
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_SET_FAILSAFE:
// Int,Ext
str = _func_failsafe_lookup[CFN_PARAM(cfn)];
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_HAPTIC:
case FUNC_LOGS: // 10th of seconds
str = yaml_unsigned2str(CFN_PARAM(cfn));
if (!wf(opaque, str, strlen(str))) return false;
break;
case FUNC_ADJUST_GVAR:
switch(CFN_GVAR_MODE(cfn)) {
case FUNC_ADJUST_GVAR_CONSTANT:
case FUNC_ADJUST_GVAR_INCDEC:
str = yaml_signed2str(CFN_PARAM(cfn));
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;
break;
case FUNC_ADJUST_GVAR_GVAR:
if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn) + MIXSRC_FIRST_GVAR, wf, opaque)) return false;
break;
}
}
if (HAS_ENABLE_PARAM(func)) {
// ",0/1"
if (!wf(opaque,CFN_ACTIVE(cfn) ? ",1":",0",2)) return false;
} else if (HAS_REPEAT_PARAM(func)) {
// ","
if (!wf(opaque,",",1)) return false;
if (CFN_PLAY_REPEAT(cfn) == 0) {
// "1x"
if (!wf(opaque,"1x",2)) return false;
} else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
// "!1x"
if (!wf(opaque,"!1x",3)) return false;
} else {
// repeat time in seconds
str = yaml_unsigned2str(CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL);
if (!wf(opaque, str, strlen(str))) return false;
}
}
return true;
}
@@ -300,12 +300,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -318,8 +318,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -321,12 +321,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -339,8 +339,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -321,12 +321,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -339,8 +339,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -300,12 +300,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -318,8 +318,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -339,12 +339,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -357,8 +357,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -280,12 +280,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -298,8 +298,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -288,12 +288,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -306,8 +306,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -285,12 +285,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -303,8 +303,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -287,12 +287,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -305,8 +305,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -62,6 +62,12 @@ namespace yaml_conv_220 {
bool w_flightModes(const YamlNode* node, uint32_t val,
yaml_writer_func wf, void* opaque);
extern const char* _func_sound_lookup[];
extern const uint8_t _func_sound_lookup_size;
bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque);
};
//
@@ -855,3 +861,192 @@ static bool w_flightModes(const YamlNode* node, uint32_t val,
{
return yaml_conv_220::w_flightModes(node, val, wf, opaque);
}
static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data += bitoffs >> 3UL;
data -= offsetof(CustomFunctionData, all);
auto cfn = reinterpret_cast<CustomFunctionData*>(data);
uint8_t func = CFN_FUNC(cfn);
if (func == FUNC_OVERRIDE_CHANNEL) {
// CH index
CFN_CH_INDEX(cfn) = yaml_str2uint_ref(val, val_len);
// ","
if (!val_len || val[0] != ',') return;
// value
CFN_PARAM(cfn) = yaml_str2int_ref(val, val_len);
}
// find "," and cut val_len
const char* sep = (const char *)memchr(val, ',', val_len);
uint8_t l_sep = sep ? sep - val : val_len;
// read values...
switch (func) {
case FUNC_OVERRIDE_CHANNEL:
break;
case FUNC_TRAINER:
if (l_sep == 6
&& val[0] == 's'
&& val[1] == 't'
&& val[2] == 'i'
&& val[3] == 'c'
&& val[4] == 'k'
&& val[5] == 's') {
CFN_CH_INDEX(cfn) = 0;
} else if (l_sep == 5
&& val[0] == 'c'
&& val[1] == 'h'
&& val[2] == 'a'
&& val[3] == 'n'
&& val[4] == 's') {
CFN_CH_INDEX(cfn) = NUM_STICKS + 1;
} else {
uint32_t stick = yaml_parse_enum(enum_MixSources, val, l_sep);
if (stick >= MIXSRC_FIRST_STICK && stick <= MIXSRC_LAST_STICK) {
CFN_CH_INDEX(cfn) = stick - MIXSRC_FIRST_STICK + 1;
}
}
break;
case FUNC_RESET:
if (l_sep == 4
&& val[0] == 'T'
&& val[1] == 'm'
&& val[2] == 'r'
&& val[3] >= '1'
&& val[3] <= '3') {
CFN_PARAM(cfn) = val[3] - '1';
} else if (l_sep == 3
&& val[0] == 'A'
&& val[1] == 'l'
&& val[2] == 'l') {
CFN_PARAM(cfn) = FUNC_RESET_FLIGHT;
} else if (l_sep == 4
&& val[0] == 'T'
&& val[1] == 'e'
&& val[2] == 'l'
&& val[3] == 'e') {
CFN_PARAM(cfn) = FUNC_RESET_TELEMETRY;
} else {
uint32_t sensor = yaml_str2uint(val, l_sep);
CFN_PARAM(cfn) = sensor + FUNC_RESET_PARAM_FIRST_TELEM;
}
break;
case FUNC_VOLUME:
case FUNC_BACKLIGHT:
case FUNC_PLAY_VALUE:
// find "," and cut val_len
CFN_PARAM(cfn) = r_mixSrcRaw(nullptr, val, l_sep);
break;
case FUNC_PLAY_SOUND:
// find "," and cut val_len
for (int i=0; i < yaml_conv_220::_func_sound_lookup_size; i++) {
if (!strncmp(yaml_conv_220::_func_sound_lookup[i],val,l_sep)) {
CFN_PARAM(cfn) = i;
break;
}
}
break;
case FUNC_PLAY_TRACK:
case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT:
strncpy(cfn->play.name, val, std::min<uint8_t>(l_sep, LEN_FUNCTION_NAME));
break;
case FUNC_SET_TIMER:
// Tmr1,Tmr2,Tmr3
if (l_sep >= 4
&& val[0] == 'T'
&& val[1] == 'm'
&& val[2] == 'r'
&& val[3] >= '1'
&& val[3] <= '3') {
CFN_TIMER_INDEX(cfn) = val[3] - '1';
}
break;
case FUNC_SET_FAILSAFE:
// Int,Ext
if (l_sep == 3) {
if (val[0] == 'I'
&& val[1] == 'n'
&& val[2] == 't') {
CFN_PARAM(cfn) = 0;
} else if (val[0] == 'E'
&& val[1] == 'x'
&& val[2] == 't') {
CFN_PARAM(cfn) = 1;
}
}
break;
case FUNC_HAPTIC:
case FUNC_LOGS: // 10th of seconds
CFN_PARAM(cfn) = yaml_str2uint(val, l_sep);
break;
case FUNC_ADJUST_GVAR:
switch(CFN_GVAR_MODE(cfn)) {
case FUNC_ADJUST_GVAR_CONSTANT:
case FUNC_ADJUST_GVAR_INCDEC:
CFN_PARAM(cfn) = yaml_str2int(val, l_sep);
break;
case FUNC_ADJUST_GVAR_SOURCE:
CFN_PARAM(cfn) = r_mixSrcRaw(nullptr, val, l_sep);
break;
case FUNC_ADJUST_GVAR_GVAR: {
uint32_t gvar = r_mixSrcRaw(nullptr, val, l_sep);
if (gvar >= MIXSRC_FIRST_GVAR) {
CFN_PARAM(cfn) = gvar - MIXSRC_FIRST_GVAR;
}
} break;
} break;
}
val += l_sep;
val_len -= l_sep;
if (val_len == 0 || val[0] != ',')
return;
val++; val_len--;
if (HAS_ENABLE_PARAM(func)) {
// "0/1"
if (val_len > 0) {
if (val[0] == '0') {
CFN_ACTIVE(cfn) = 0;
} else if (val[0] == '1') {
CFN_ACTIVE(cfn) = 1;
}
}
} else if (HAS_REPEAT_PARAM(func)) {
if (val_len == 2
&& val[0] == '1'
&& val[1] == 'x') {
CFN_PLAY_REPEAT(cfn) = 0;
} else if (val_len == 3
&& val[0] == '!'
&& val[1] == '1'
&& val[2] == 'x') {
CFN_PLAY_REPEAT(cfn) = CFN_PLAY_REPEAT_NOSTART;
} else {
// repeat time in seconds
CFN_PLAY_REPEAT(cfn) = yaml_str2uint(val,val_len) / CFN_PLAY_REPEAT_MUL;
}
}
}
static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
return yaml_conv_220::w_customFn(user, data, bitoffs, wf, opaque);
}
@@ -300,12 +300,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -318,8 +318,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -321,12 +321,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -339,8 +339,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -321,12 +321,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "spare", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_SIGNED( "val2", 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -339,8 +339,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -293,12 +293,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -311,8 +311,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -300,12 +300,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -318,8 +318,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -339,12 +339,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -357,8 +357,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -280,12 +280,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -298,8 +298,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -288,12 +288,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -306,8 +306,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -285,12 +285,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -303,8 +303,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
@@ -287,12 +287,12 @@ static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "spare", 32 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 32 ),
YAML_SIGNED( "val2", 32 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
@@ -305,8 +305,9 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 64, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {