Skip to content

Commit

Permalink
fix: flex switch warnings
Browse files Browse the repository at this point in the history
Fixes #4938
  • Loading branch information
raphaelcoeffic committed May 1, 2024
1 parent 7968867 commit e56e6b2
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 30 deletions.
4 changes: 2 additions & 2 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ PACK(struct ModelData {
FlightModeData flightModeData[MAX_FLIGHT_MODES] FUNC(fmd_is_active);

NOBACKUP(uint8_t thrTraceSrc CUST(r_thrSrc,w_thrSrc));
CUST_ATTR(switchWarningState, r_swtchWarn, w_swtchWarn);
NOBACKUP(swarnstate_t switchWarningState SKIP);
CUST_ATTR(switchWarningState, r_swtchWarn, nullptr);
NOBACKUP(swarnstate_t switchWarning ARRAY(3, struct_swtchWarn, nullptr));

GVarData gvars[MAX_GVARS];

Expand Down
10 changes: 5 additions & 5 deletions radio/src/gui/colorlcd/preflight_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)

static std::string switchWarninglabel(swsrc_t index)
{
auto warn_pos = g_model.switchWarningState >> (3 * index) & 0x07;
auto warn_pos = g_model.switchWarning >> (3 * index) & 0x07;
return std::string(switchGetName(index)) +
std::string(getSwitchWarnSymbol(warn_pos));
}
Expand Down Expand Up @@ -244,14 +244,14 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id)
if (btn_id >= MAX_SWITCHES) return;
auto sw = sw_idx[btn_id];

swarnstate_t newstate = bfGet(g_model.switchWarningState, 3 * sw, 3);
swarnstate_t newstate = bfGet(g_model.switchWarning, 3 * sw, 3);
if (newstate == 1 && SWITCH_CONFIG(sw) != SWITCH_3POS)
newstate = 3;
else
newstate = (newstate + 1) % 4;

g_model.switchWarningState =
bfSet(g_model.switchWarningState, newstate, 3 * sw, 3);
g_model.switchWarning =
bfSet(g_model.switchWarning, newstate, 3 * sw, 3);
SET_DIRTY();

setTextAndState(btn_id);
Expand All @@ -260,7 +260,7 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id)
bool SwitchWarnMatrix::isActive(uint8_t btn_id)
{
if (btn_id >= MAX_SWITCHES) return false;
return bfGet(g_model.switchWarningState, 3 * sw_idx[btn_id], 3) != 0;
return bfGet(g_model.switchWarning, 3 * sw_idx[btn_id], 3) != 0;
}

PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) :
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/switch_warn_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void SwitchWarnDialog::checkEvents()
FullScreenDialog::checkEvents();

std::string warn_txt;
swarnstate_t states = g_model.switchWarningState;
swarnstate_t states = g_model.switchWarning;
for (int i = 0; i < MAX_SWITCHES; ++i) {
if (SWITCH_WARNING_ALLOWED(i)) {
swarnstate_t mask = ((swarnstate_t)0x07 << (i * 3));
Expand Down
2 changes: 1 addition & 1 deletion radio/src/model_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void applyDefaultTemplate()
// enable switch warnings
for (int i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
g_model.switchWarningState |= (1 << (3 * i));
g_model.switchWarning |= (1 << (3 * i));
}
}
#else
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
14 changes: 14 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,20 @@ static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
return true;
}

static const struct YamlIdStr enum_SwitchWarnPos[] = {
{ 0, "none" },
{ 1, "up" },
{ 2, "mid" },
{ 3, "down" },
{ 0, nullptr },
};

static const struct YamlNode struct_swtchWarn[] {
YAML_IDX_CUST( "sw", sw_read, sw_write ),
YAML_ENUM( "pos", 2, enum_SwitchWarnPos ),
YAML_END,
};

extern const struct YamlIdStr enum_BeeperMode[];

static uint32_t r_beeperMode(const YamlNode* node, const char* val, uint8_t val_len)
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_nv14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_pl18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 384, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_t20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_tpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_x10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_x12s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_x9d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_x9e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
5 changes: 3 additions & 2 deletions radio/src/storage/yaml/yaml_datastructs_xlites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,9 @@ static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn),
YAML_PADDING( 64 ),
YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr),
YAML_ARRAY("switchWarningState", 3, 21, struct_swtchWarn, nullptr),
YAML_PADDING(1),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
Expand Down
2 changes: 1 addition & 1 deletion radio/src/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ swsrc_t getMovedSwitch()

bool isSwitchWarningRequired(uint16_t &bad_pots)
{
swarnstate_t states = g_model.switchWarningState;
swarnstate_t states = g_model.switchWarning;

if (!mixerTaskRunning()) getADC();
getMovedSwitch();
Expand Down
5 changes: 5 additions & 0 deletions radio/util/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,16 @@ def max_bits(struct):
bits = s.bits
return bits

def padding_bits(array):
array_bits = (array.bits // array.length) * array.length
return array.bits - array_bits

template = jinja2.Template(open(sys.argv[2]).read(), lstrip_blocks=True, trim_blocks=True)

template.globals['max_len'] = max_len
template.globals['get_max_len'] = get_max_len
template.globals['max_bits'] = max_bits
template.globals['padding_bits'] = padding_bits

## fixme: root_node_name needs to be mangled (contains ',')
print(template.render(root=RootAST,root_nodes=top_node_names,root_node_name=root_nodes_name))
3 changes: 3 additions & 0 deletions radio/util/yaml_parser.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ 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 }}),
{% if padding_bits(elmt) > 0 %}
YAML_PADDING({{ padding_bits(elmt) }}),
{% endif %}
{% elif elmt.raw %}
{{ elmt.raw }},
{% else %}
Expand Down

0 comments on commit e56e6b2

Please sign in to comment.