Revamped switch state checking
This commit is contained in:
@@ -525,6 +525,7 @@ bool swash_is_active(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
|
||||
#define r_swtchWarn nullptr
|
||||
|
||||
#if defined(COLORLCD)
|
||||
bool w_swtchWarn(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
for (int i = 0; i < STORAGE_NUM_SWITCHES; i++) {
|
||||
@@ -568,6 +569,58 @@ bool w_swtchWarn(const YamlNode* node, uint32_t val, yaml_writer_func wf, void*
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
yaml_writer_func wf, void* opaque)
|
||||
{
|
||||
data += (bitoffs >> 3UL);
|
||||
|
||||
// switchWarningState
|
||||
swarnstate_t states = *(swarnstate_t*)data;
|
||||
data += sizeof(swarnstate_t);
|
||||
|
||||
// switchWarningEnable
|
||||
swarnenable_t enables = *(swarnenable_t*)data;
|
||||
|
||||
for (int i = 0; i < STORAGE_NUM_SWITCHES; i++) {
|
||||
// decode check state
|
||||
// -> 2 bits per switch + enable
|
||||
swarnenable_t en = (enables >> i) & 0x01;
|
||||
if (en) continue;
|
||||
|
||||
// state == 0 -> no check
|
||||
// state == 1 -> UP
|
||||
// state == 2 -> MIDDLE
|
||||
// state == 3 -> DOWN
|
||||
char swtchWarn[2] = {(char)('A' + i), 0};
|
||||
|
||||
uint8_t state = (states >> (2 * i)) & 0x03;
|
||||
switch (state) {
|
||||
case 0:
|
||||
swtchWarn[1] = 'u';
|
||||
break;
|
||||
case 1:
|
||||
swtchWarn[1] = '-';
|
||||
break;
|
||||
case 2:
|
||||
swtchWarn[1] = 'd';
|
||||
break;
|
||||
default:
|
||||
// this should never happen
|
||||
swtchWarn[1] = 'x';
|
||||
break;
|
||||
}
|
||||
|
||||
if (swtchWarn[1] != 0) {
|
||||
if (!wf(opaque, swtchWarn, 2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern const struct YamlIdStr enum_BeeperMode[];
|
||||
|
||||
|
||||
@@ -818,8 +818,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -818,8 +818,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -818,8 +818,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -818,8 +818,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -818,8 +818,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -831,8 +831,8 @@ 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_UNSIGNED_CUST( "switchWarningState", 32, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 16 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 48 ),
|
||||
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 ),
|
||||
|
||||
@@ -870,8 +870,8 @@ 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_UNSIGNED_CUST( "switchWarningState", 64, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 32 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 96 ),
|
||||
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 ),
|
||||
|
||||
@@ -803,8 +803,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -813,8 +813,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -810,8 +810,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
@@ -814,8 +814,8 @@ static const struct YamlNode struct_ModelData[] = {
|
||||
YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active),
|
||||
YAML_ARRAY("flightModeData", 288, 9, struct_FlightModeData, fmd_is_active),
|
||||
YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ),
|
||||
YAML_UNSIGNED_CUST( "switchWarningState", 16, r_swtchWarn, w_swtchWarn ),
|
||||
YAML_UNSIGNED( "switchWarningEnable", 8 ),
|
||||
YAML_CUSTOM("switchWarningState", NULL, w_swtchWarn ),
|
||||
YAML_PADDING( 24 ),
|
||||
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 ),
|
||||
|
||||
Reference in New Issue
Block a user