Stick names in own config list
This commit is contained in:
@@ -750,6 +750,7 @@ PACK(struct TrainerData {
|
||||
#define EXTRA_GENERAL_FIELDS \
|
||||
NOBACKUP(uint8_t auxSerialMode:4); \
|
||||
NOBACKUP(uint8_t aux2SerialMode:4); \
|
||||
CUST_ARRAY(sticksConfig, struct_sticksConfig, stick_name_valid); \
|
||||
swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \
|
||||
uint16_t potsConfig ARRAY(2,struct_potConfig,nullptr); /* two bits per pot */ \
|
||||
uint8_t slidersConfig ARRAY(1,struct_sliderConfig,nullptr); /* 1 bit per slider */ \
|
||||
@@ -773,6 +774,7 @@ PACK(struct TrainerData {
|
||||
uint8_t potsConfig ARRAY(2,struct_potConfig,nullptr); /* two bits per pot */\
|
||||
uint8_t backlightColor; \
|
||||
swarnstate_t switchUnlockStates; \
|
||||
CUST_ARRAY(sticksConfig, struct_sticksConfig, stick_name_valid); \
|
||||
swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \
|
||||
char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME] SKIP; \
|
||||
char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME] SKIP; \
|
||||
@@ -798,6 +800,8 @@ PACK(struct TrainerData {
|
||||
#endif
|
||||
|
||||
PACK(struct RadioData {
|
||||
|
||||
// Real attributes
|
||||
NOBACKUP(uint8_t version);
|
||||
NOBACKUP(uint16_t variant SKIP);
|
||||
CalibData calib[NUM_STICKS + STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS + STORAGE_NUM_MOUSE_ANALOGS];
|
||||
|
||||
@@ -218,6 +218,36 @@ static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
}
|
||||
|
||||
static void r_stick_name(const YamlNode* node, uint8_t* data,
|
||||
uint32_t bitoffs, uint16_t idx,
|
||||
const char* val, uint8_t val_len)
|
||||
{
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static bool w_stick_name(const YamlNode* node, uint8_t* data,
|
||||
uint32_t bitoffs, uint16_t idx,
|
||||
yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
return wf(opaque, rd->anaNames[idx], strnlen(rd->anaNames[idx], LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static bool stick_name_valid(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
{
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
return rd->anaNames[idx][0] != '\0';
|
||||
}
|
||||
|
||||
static const struct YamlNode struct_sticksConfig[] = {
|
||||
YAML_IDX,
|
||||
YAML_CUSTOM( "name", r_stick_name, w_stick_name),
|
||||
YAML_END
|
||||
};
|
||||
|
||||
static void sw_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, const char* val, uint8_t val_len)
|
||||
{
|
||||
@@ -464,19 +494,19 @@ static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf,
|
||||
return wf(opaque, str, strlen(str));
|
||||
}
|
||||
|
||||
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs)
|
||||
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
{
|
||||
data += bitoffs >> 3UL;
|
||||
return ((CustomFunctionData*)data)->swtch;
|
||||
}
|
||||
|
||||
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs)
|
||||
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
{
|
||||
gvar_t* gvar = (gvar_t*)(data + (bitoffs>>3UL));
|
||||
return *gvar != GVAR_MAX+1;
|
||||
}
|
||||
|
||||
static bool fmd_is_active(uint8_t* data, uint32_t bitoffs)
|
||||
static bool fmd_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
{
|
||||
uint32_t data_ofs = bitoffs >> 3UL;
|
||||
if (data_ofs == offsetof(ModelData, flightModeData)) {
|
||||
|
||||
@@ -368,6 +368,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
|
||||
YAML_UNSIGNED( "auxSerialMode", 4 ),
|
||||
YAML_UNSIGNED( "aux2SerialMode", 4 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
|
||||
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
|
||||
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
|
||||
|
||||
@@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 192 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 192 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 192 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 192 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -385,6 +385,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
|
||||
YAML_UNSIGNED( "auxSerialMode", 4 ),
|
||||
YAML_UNSIGNED( "aux2SerialMode", 4 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
|
||||
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
|
||||
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
|
||||
|
||||
@@ -385,6 +385,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
|
||||
YAML_UNSIGNED( "auxSerialMode", 4 ),
|
||||
YAML_UNSIGNED( "aux2SerialMode", 4 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
|
||||
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
|
||||
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
|
||||
|
||||
@@ -345,6 +345,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 192 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -352,6 +352,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 32 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 216 ),
|
||||
YAML_PADDING( 216 ),
|
||||
|
||||
@@ -391,6 +391,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 64 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 32, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 432 ),
|
||||
YAML_PADDING( 288 ),
|
||||
|
||||
@@ -332,6 +332,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 120 ),
|
||||
YAML_PADDING( 120 ),
|
||||
|
||||
@@ -340,6 +340,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 168 ),
|
||||
YAML_PADDING( 120 ),
|
||||
|
||||
@@ -337,6 +337,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 144 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -339,6 +339,7 @@ static const struct YamlNode struct_RadioData[] = {
|
||||
YAML_ARRAY("potsConfig", 2, 4, struct_potConfig, nullptr),
|
||||
YAML_UNSIGNED( "backlightColor", 8 ),
|
||||
YAML_UNSIGNED( "switchUnlockStates", 16 ),
|
||||
YAML_ARRAY("sticksConfig", 0, 4, struct_sticksConfig, stick_name_valid),
|
||||
YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr),
|
||||
YAML_PADDING( 144 ),
|
||||
YAML_PADDING( 144 ),
|
||||
|
||||
@@ -30,18 +30,26 @@
|
||||
|
||||
/* public definitions */
|
||||
#define ENUM(label) _yaml_attribute("enum:" _yaml_note(label))
|
||||
#define SKIP _yaml_attribute("skip:true")
|
||||
#define USE_IDX _yaml_attribute("idx:true")
|
||||
#define FUNC(name) _yaml_attribute("func:" _yaml_note(name))
|
||||
#define SKIP _yaml_attribute("skip:true")
|
||||
#define USE_IDX _yaml_attribute("idx:true")
|
||||
#define FUNC(name) _yaml_attribute("func:" _yaml_note(name))
|
||||
#define NAME(label) _yaml_attribute("name:" _yaml_note(label))
|
||||
|
||||
#define CUST(read,write) \
|
||||
_yaml_attribute("read:" _yaml_note(read)) \
|
||||
_yaml_attribute("write:" _yaml_note(write))
|
||||
#define CUST(read, write) \
|
||||
_yaml_attribute("read:" _yaml_note(read)) \
|
||||
_yaml_attribute("write:" _yaml_note(write))
|
||||
|
||||
#define ARRAY(elmt_size,elmt_type,fcn) \
|
||||
_yaml_attribute("array:" _yaml_note(elmt_size) "|" \
|
||||
_yaml_note(elmt_type) "|" _yaml_note(fcn))
|
||||
#define ARRAY(elmt_size, elmt_type, fcn) \
|
||||
_yaml_attribute("array:" _yaml_note(elmt_size) "|" _yaml_note( \
|
||||
elmt_type) "|" _yaml_note(fcn))
|
||||
|
||||
#define CUST_ATTR(tag, read, write) \
|
||||
int _dummy_##tag[0] _yaml_attribute("raw:YAML_CUSTOM(" _yaml_note( \
|
||||
#tag) "," _yaml_note(read) "," _yaml_note(write) ")")
|
||||
|
||||
#define CUST_ARRAY(tag, elmt_type, fcn) \
|
||||
int _dummy_##tag[0] _yaml_attribute("raw:YAML_ARRAY(" _yaml_note( \
|
||||
#tag) ", 0, 4, " _yaml_note(elmt_type) ", " _yaml_note(fcn) ")")
|
||||
|
||||
#else
|
||||
|
||||
@@ -50,8 +58,10 @@
|
||||
#define USE_IDX
|
||||
#define FUNC(name)
|
||||
#define NAME(label)
|
||||
#define CUST(read,write)
|
||||
#define ARRAY(elmt_size,elmt_type,fcn)
|
||||
#define CUST(read, write)
|
||||
#define ARRAY(elmt_size, elmt_type, fcn)
|
||||
#define CUST_ATTR(tag, read, write)
|
||||
#define CUST_ARRAY(tag, elmt_type, fcn)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef bool (*yaml_writer_func)(void* opaque, const char* str, size_t len);
|
||||
|
||||
struct YamlNode
|
||||
{
|
||||
typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs);
|
||||
typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs, uint16_t idx);
|
||||
|
||||
typedef uint32_t (*cust_to_uint_func)(const YamlNode* node, const char* val, uint8_t val_len);
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ bool YamlTreeWalker::isElmtEmpty(uint8_t* data)
|
||||
|
||||
// assume structs aligned on 8bit boundaries
|
||||
if (node->u._array.u._a.is_active)
|
||||
return !node->u._array.u._a.is_active(data, bit_ofs);
|
||||
return !node->u._array.u._a.is_active(data, bit_ofs, getElmts());
|
||||
|
||||
return yaml_is_zero(data, bit_ofs, node->size);
|
||||
}
|
||||
|
||||
@@ -342,6 +342,8 @@ def parse_field_array(f, node):
|
||||
for a in ann:
|
||||
if a['type'] == 'idx':
|
||||
use_idx = True
|
||||
elif a['type'] == 'raw':
|
||||
f.raw = a['val']
|
||||
|
||||
# let's see first if it's some kind of struct/union/enum
|
||||
elmt_st = parse_node(RootAST, elmt_decl)
|
||||
|
||||
@@ -45,8 +45,10 @@ static const struct YamlNode {{ struct.name }}[] = {
|
||||
YAML_UNION("{{ max_len(elmt.name) }}", {{elmt.bits}}, {{elmt.var_type}}_elmts, {{ elmt.func}}),
|
||||
{% elif elmt.type == 'array' %}
|
||||
YAML_ARRAY("{{ max_len(elmt.name) }}", {{elmt.bits // elmt.length}}, {{elmt.length}}, {{elmt.var_type}}, {{ elmt.func }}),
|
||||
{% elif elmt.raw %}
|
||||
{{ elmt.raw }},
|
||||
{% else %}
|
||||
// name='{{elmt.name}}', type='{{elmt.type}}', bits='{{elmt.bits}}', is_array='{{elmt.is_array}}', var_type='{{elmt.var_type}}', kind='{{elmt.cursor.kind}}' , type.kind='{{elmt.cursor.type.kind}}'
|
||||
// name='{{elmt.name}}', type='{{elmt.type}}', bits='{{elmt.bits}}', is_array='{{elmt.is_array}}', var_type='{{elmt.var_type}}', kind='{{elmt.cursor.kind}}' , type.kind='{{elmt.cursor.type.kind}}', raw='{{elmt.raw}}'
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
YAML_END
|
||||
|
||||
Reference in New Issue
Block a user