WiP pass YamlTreeParser where needed
This commit is contained in:
@@ -127,7 +127,7 @@ static bool w_vbat_max(const YamlNode* node, uint32_t val, yaml_writer_func wf,
|
||||
}
|
||||
|
||||
#if defined(COLORLCD)
|
||||
static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_zov(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
data += bitoffs >> 3UL;
|
||||
data -= sizeof(ZoneOptionValueEnum);
|
||||
@@ -138,7 +138,7 @@ static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
data += bitoffs >> 3UL;
|
||||
data -= offsetof(ModuleData, ppm);
|
||||
@@ -174,74 +174,86 @@ static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_custom_fn(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
// always use 'all'
|
||||
//TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint8_t select_script_input(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_script_input(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
// always use 'value'
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t select_id1(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_id1(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
// always use 'id'
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t select_id2(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_id2(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
// always use 'instance'
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
|
||||
static uint8_t select_sensor_cfg(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
// always use 'param'
|
||||
return 5;
|
||||
}
|
||||
|
||||
static uint32_t sw_read(const char* val, uint8_t val_len)
|
||||
static uint32_t sw_read(void* user, const char* val, uint8_t val_len)
|
||||
{
|
||||
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (sw >= MIXSRC_FIRST_SWITCH)
|
||||
return sw - MIXSRC_FIRST_SWITCH;
|
||||
(void)user;
|
||||
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (sw >= MIXSRC_FIRST_SWITCH) return sw - MIXSRC_FIRST_SWITCH;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool sw_write(void* user, yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts();
|
||||
|
||||
const char* str =
|
||||
yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
|
||||
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,
|
||||
static void r_stick_name(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
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));
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
if (idx >= NUM_STICKS) return;
|
||||
|
||||
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,
|
||||
static bool w_stick_name(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
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));
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
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)
|
||||
static bool stick_name_valid(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
return rd->anaNames[idx][0] != '\0';
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts();
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
return rd->anaNames[idx][0] != '\0';
|
||||
}
|
||||
|
||||
static const struct YamlNode struct_sticksConfig[] = {
|
||||
@@ -250,27 +262,34 @@ static const struct YamlNode struct_sticksConfig[] = {
|
||||
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)
|
||||
static void sw_name_read(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
const char* val, uint8_t val_len)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
strncpy(rd->switchNames[idx], val, std::min<uint8_t>(val_len, LEN_SWITCH_NAME));
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
strncpy(rd->switchNames[idx], val,
|
||||
std::min<uint8_t>(val_len, LEN_SWITCH_NAME));
|
||||
}
|
||||
|
||||
static bool sw_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool sw_name_write(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
const char* str = rd->switchNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, switchConfig);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
const char* str = rd->switchNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
|
||||
}
|
||||
|
||||
static const struct YamlIdStr enum_SwitchConfig[] = {
|
||||
@@ -282,50 +301,59 @@ static const struct YamlIdStr enum_SwitchConfig[] = {
|
||||
};
|
||||
|
||||
static const struct YamlNode struct_switchConfig[] = {
|
||||
YAML_IDX_CUST( "sw", sw_read, sw_write ),
|
||||
YAML_IDX_CUST( "sw", sw_read, sw_write),
|
||||
YAML_ENUM( "type", 2, enum_SwitchConfig),
|
||||
YAML_CUSTOM( "name", sw_name_read, sw_name_write),
|
||||
YAML_END
|
||||
};
|
||||
|
||||
static uint32_t pot_read(const char* val, uint8_t val_len)
|
||||
static uint32_t pot_read(void* user, const char* val, uint8_t val_len)
|
||||
{
|
||||
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (pot >= MIXSRC_FIRST_POT)
|
||||
return pot - MIXSRC_FIRST_POT;
|
||||
(void)user;
|
||||
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (pot >= MIXSRC_FIRST_POT) return pot - MIXSRC_FIRST_POT;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool pot_write(void* user, yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts();
|
||||
|
||||
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
}
|
||||
|
||||
static void pot_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, const char* val, uint8_t val_len)
|
||||
static void pot_name_read(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
const char* val, uint8_t val_len)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, potsConfig);
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS;
|
||||
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, potsConfig);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS;
|
||||
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static bool pot_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool pot_name_write(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, potsConfig);
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS;
|
||||
const char* str = rd->anaNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
|
||||
// data / bitoffs already incremented
|
||||
data -= ((idx + 1) * 2) / 8;
|
||||
data -= offsetof(RadioData, potsConfig);
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS;
|
||||
const char* str = rd->anaNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static const struct YamlIdStr enum_PotConfig[] = {
|
||||
@@ -343,62 +371,72 @@ static const struct YamlNode struct_potConfig[] = {
|
||||
YAML_END
|
||||
};
|
||||
|
||||
static uint32_t slider_read(const char* val, uint8_t val_len)
|
||||
static uint32_t slider_read(void* user, const char* val, uint8_t val_len)
|
||||
{
|
||||
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (sl >= MIXSRC_FIRST_SLIDER)
|
||||
return sl - MIXSRC_FIRST_SLIDER;
|
||||
(void)user;
|
||||
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||
if (sl >= MIXSRC_FIRST_SLIDER) return sl - MIXSRC_FIRST_SLIDER;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool slider_write(void* user, yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts();
|
||||
|
||||
const char* str =
|
||||
yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
|
||||
return str ? wf(opaque, str, strlen(str)) : true;
|
||||
}
|
||||
|
||||
static void sl_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, const char* val, uint8_t val_len)
|
||||
static void sl_name_read(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
const char* val, uint8_t val_len)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
// data / bitoffs already incremented
|
||||
#if defined(PCBTARANIS)
|
||||
// Please note:
|
||||
// slidersConfig is defined as a bit-field member,
|
||||
// so let's take the next field and subtract 1
|
||||
//
|
||||
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
|
||||
data -= offsetof(RadioData, potsConfig) - 1;
|
||||
// Please note:
|
||||
// slidersConfig is defined as a bit-field member,
|
||||
// so let's take the next field and subtract 1
|
||||
//
|
||||
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
|
||||
data -= offsetof(RadioData, potsConfig) - 1;
|
||||
#else
|
||||
data -= (idx + 1) / 8;
|
||||
data -= offsetof(RadioData, slidersConfig);
|
||||
data -= (idx + 1) / 8;
|
||||
data -= offsetof(RadioData, slidersConfig);
|
||||
#endif
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS + STORAGE_NUM_POTS;
|
||||
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS + STORAGE_NUM_POTS;
|
||||
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static bool sl_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
|
||||
uint16_t idx, yaml_writer_func wf, void* opaque)
|
||||
static bool sl_name_write(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
// data / bitoffs already incremented
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(1);
|
||||
|
||||
// data / bitoffs already incremented
|
||||
#if defined(PCBTARANIS)
|
||||
// Please note:
|
||||
// slidersConfig is defined as a bit-field member,
|
||||
// so let's take the next field and subtract 1
|
||||
//
|
||||
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
|
||||
data -= offsetof(RadioData, potsConfig) - 1;
|
||||
// Please note:
|
||||
// slidersConfig is defined as a bit-field member,
|
||||
// so let's take the next field and subtract 1
|
||||
//
|
||||
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
|
||||
data -= offsetof(RadioData, potsConfig) - 1;
|
||||
#else
|
||||
data -= (idx + 1) / 8;
|
||||
data -= offsetof(RadioData, slidersConfig);
|
||||
data -= (idx + 1) / 8;
|
||||
data -= offsetof(RadioData, slidersConfig);
|
||||
#endif
|
||||
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS + STORAGE_NUM_POTS;
|
||||
const char* str = rd->anaNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
|
||||
RadioData* rd = reinterpret_cast<RadioData*>(data);
|
||||
idx += NUM_STICKS + STORAGE_NUM_POTS;
|
||||
const char* str = rd->anaNames[idx];
|
||||
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
|
||||
}
|
||||
|
||||
static const struct YamlIdStr enum_SliderConfig[] = {
|
||||
@@ -514,19 +552,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, uint16_t idx)
|
||||
static bool cfn_is_active(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
data += bitoffs >> 3UL;
|
||||
return ((CustomFunctionData*)data)->swtch;
|
||||
}
|
||||
|
||||
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
static bool gvar_is_active(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
gvar_t* gvar = (gvar_t*)(data + (bitoffs>>3UL));
|
||||
return *gvar != GVAR_MAX+1;
|
||||
}
|
||||
|
||||
static bool fmd_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
|
||||
static bool fmd_is_active(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
uint32_t data_ofs = bitoffs >> 3UL;
|
||||
if (data_ofs == offsetof(ModelData, flightModeData)) {
|
||||
@@ -727,3 +765,27 @@ static bool w_trainerMode(const YamlNode* node, uint32_t val,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !defined(COLORLCD)
|
||||
static uint8_t select_tele_screen_data(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
{
|
||||
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
|
||||
uint16_t idx = tw->getElmts(2);
|
||||
|
||||
auto md = reinterpret_cast<ModelData*>(data);
|
||||
uint8_t st = (md->screensType >> (2 * idx)) & 0x03;
|
||||
switch(st){
|
||||
case TELEMETRY_SCREEN_TYPE_NONE:
|
||||
break;
|
||||
case TELEMETRY_SCREEN_TYPE_VALUES:
|
||||
return 1; // lines
|
||||
case TELEMETRY_SCREEN_TYPE_BARS:
|
||||
return 0; // bars
|
||||
case TELEMETRY_SCREEN_TYPE_SCRIPT:
|
||||
return 2;
|
||||
}
|
||||
|
||||
TRACE("select_tele_screen_data(idx=%d)", idx);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user