fix(yaml): flex switch warnings (#4949)

Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
Co-authored-by: 3djc <3djc@gh.com>
Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Raphael Coeffic
2024-05-03 13:14:50 +10:00
committed by GitHub
co-authored by raphaelcoeffic 3djc elecpower
parent dd87ecb89a
commit 0d6ce7d22d
22 changed files with 174 additions and 101 deletions
@@ -263,6 +263,88 @@ struct YamlBeepANACenter {
}
};
// modeldata: uint64_t switchWarningStates
// Yaml switchWarning:
// SA:
// pos: mid
// SB:
// pos: up
// FL1:
// pos: down
struct YamlSwitchWarning {
static constexpr size_t MASK_LEN = 2;
static constexpr size_t MASK = (1 << MASK_LEN) - 1;
unsigned int enabled;
YamlSwitchWarning() = default;
YamlSwitchWarning(YAML::Node& node, uint64_t cpn_value, unsigned int switchWarningEnable)
: enabled(~switchWarningEnable)
{
uint64_t states = cpn_value;
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
if (!Boards::isSwitchFunc(i) && (enabled & (1 << i))) {
std::string posn;
switch(states & MASK) {
case 0:
posn = "up";
break;
case 1:
posn = "mid";
break;
case 2:
posn = "down";
break;
}
node[Boards::getSwitchTag(i).toStdString()]["pos"] = posn;
}
states >>= MASK_LEN;
}
}
uint64_t toCpn(const YAML::Node &warn)
{
uint64_t states = 0;
enabled = 0;
if (warn.IsMap()) {
for (const auto& sw : warn) {
std::string tag;
sw.first >> tag;
int index = Boards::getSwitchIndex(tag.c_str(), Board::LVT_NAME);
if (index < 0)
continue;
std::string posn;
if (warn[tag]["pos"])
warn[tag]["pos"] >> posn;
int value = 0;
if (posn == "up")
value = 0;
else if (posn == "mid")
value = 1;
else if (posn == "down")
value = 2;
states |= ((uint64_t)value << (index * MASK_LEN));
enabled |= (1 << index);
}
}
return states;
}
};
// Depreciated - only used for decoding refer YamlSwitchWarning for replacement
// modeldata: uint64_t switchWarningStates
// Yaml switchWarningState: AuBuEuFuG-IuJu
struct YamlSwitchWarningState {
@@ -985,8 +1067,11 @@ Node convert<ModelData>::encode(const ModelData& rhs)
YamlThrTrace thrTrace(rhs.thrTraceSrc);
node["thrTraceSrc"] = thrTrace.src;
YamlSwitchWarningState switchWarningState(rhs.switchWarningStates, rhs.switchWarningEnable);
node["switchWarningState"] = switchWarningState.src_str;
Node sw_warn;
YamlSwitchWarning switchWarning(sw_warn, rhs.switchWarningStates, rhs.switchWarningEnable);
if (sw_warn && sw_warn.IsMap()) {
node["switchWarning"] = sw_warn;
}
node["thrTrimSw"] = rhs.thrTrimSwitch;
node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode;
@@ -1239,10 +1324,17 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
node["thrTraceSrc"] >> thrTrace.src;
rhs.thrTraceSrc = thrTrace.toCpn();
YamlSwitchWarningState switchWarningState;
node["switchWarningState"] >> switchWarningState.src_str;
rhs.switchWarningStates = switchWarningState.toCpn();
rhs.switchWarningEnable = ~switchWarningState.enabled;
if (node["switchWarning"]) {
YamlSwitchWarning switchWarning;
rhs.switchWarningStates = switchWarning.toCpn(node["switchWarning"]);
rhs.switchWarningEnable = ~switchWarning.enabled;
}
else if (node["switchWarningState"]) { // depreciated
YamlSwitchWarningState switchWarningState;
node["switchWarningState"] >> switchWarningState.src_str;
rhs.switchWarningStates = switchWarningState.toCpn();
rhs.switchWarningEnable = ~switchWarningState.enabled;
}
node["thrTrimSw"] >> rhs.thrTrimSwitch;
node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode;
+2 -2
View File
@@ -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];
+5 -5
View File
@@ -975,7 +975,7 @@ void menuModelSetup(event_t event)
break;
}
swarnstate_t states = g_model.switchWarningState;
swarnstate_t states = g_model.switchWarning;
lcdDrawTextAlignedLeft(y, STR_SWITCHWARNING);
#if defined(PCBXLITE)
@@ -1003,10 +1003,10 @@ void menuModelSetup(event_t event)
swarnstate_t sw_mask = 0;
for(uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (SWITCH_WARNING_ALLOWED(i))
if (g_model.switchWarningState & (0x07 << (3 * i)))
if (g_model.switchWarning & (0x07 << (3 * i)))
sw_mask |= (0x07 << (3 * i));
}
g_model.switchWarningState = switches_states & sw_mask;
g_model.switchWarning = switches_states & sw_mask;
AUDIO_WARNING1();
storageDirty(EE_MODEL);
}
@@ -1024,10 +1024,10 @@ void menuModelSetup(event_t event)
l_posHorz == current && old_posHorz >= 0) {
uint8_t curr_state = (states & 0x07);
// remove old setting
g_model.switchWarningState &= ~(0x07 << (3 * i));
g_model.switchWarning &= ~(0x07 << (3 * i));
// add the new one (if switch UP and 2POS, jump directly to DOWN)
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
g_model.switchWarningState |= (curr_state & 0x03) << (3 * i);
g_model.switchWarning |= (curr_state & 0x03) << (3 * i);
storageDirty(EE_MODEL);
#if defined(PCBXLITE)
s_editMode = 0;
+5 -5
View File
@@ -872,7 +872,7 @@ void menuModelSetup(event_t event)
}
#endif
lcdDrawTextAlignedLeft(y, STR_SWITCHWARNING);
swarnstate_t states = g_model.switchWarningState;
swarnstate_t states = g_model.switchWarning;
if (attr) {
s_editMode = 0;
@@ -889,10 +889,10 @@ void menuModelSetup(event_t event)
swarnstate_t sw_mask = 0;
for(uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (SWITCH_WARNING_ALLOWED(i))
if (g_model.switchWarningState & (0x07 << (3 * i)))
if (g_model.switchWarning & (0x07 << (3 * i)))
sw_mask |= (0x07 << (3 * i));
}
g_model.switchWarningState = switches_states & sw_mask;
g_model.switchWarning = switches_states & sw_mask;
AUDIO_WARNING1();
storageDirty(EE_MODEL);
}
@@ -912,10 +912,10 @@ void menuModelSetup(event_t event)
l_posHorz == current) {
uint8_t curr_state = (states & 0x07);
// remove old setting
g_model.switchWarningState &= ~(0x07 << (3 * i));
g_model.switchWarning &= ~(0x07 << (3 * i));
// add the new one (if switch UP and 2POS, jump directly to DOWN)
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
g_model.switchWarningState |= (curr_state & 0x03) << (3 * i);
g_model.switchWarning |= (curr_state & 0x03) << (3 * i);
storageDirty(EE_MODEL);
}
lcdDrawChar(
+5 -5
View File
@@ -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));
}
@@ -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);
@@ -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) :
@@ -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));
+2 -2
View File
@@ -123,14 +123,14 @@ 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
// enable switch warnings
for (int i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_WARNING_ALLOWED(i))
g_model.switchWarningState |= (1 << (3 * i));
g_model.switchWarning |= (1 << (3 * i));
}
#endif
@@ -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("switchWarning", 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 ),
@@ -1147,56 +1147,19 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
}
static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data += (bitoffs >> 3UL);
static const struct YamlIdStr enum_SwitchWarnPos[] = {
{ 0, "none" },
{ 1, "up" },
{ 2, "mid" },
{ 3, "down" },
{ 0, nullptr },
};
swarnstate_t states;
memcpy(&states, data, sizeof(states));
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
// TODO: SWITCH_EXISTS() uses the g_eeGeneral stucture, which might not be
// avail
if (SWITCH_EXISTS(i)) {
// decode check state
// -> 3 bits per switch
auto state = (states >> (3 * i)) & 0x07;
// state == 0 -> no check
// state == 1 -> UP
// state == 2 -> MIDDLE
// state == 3 -> DOWN
char swtchWarn[2] = {switchGetLetter(i), 0};
switch (state) {
case 0:
break;
case 1:
swtchWarn[1] = 'u';
break;
case 2:
swtchWarn[1] = '-';
break;
case 3:
swtchWarn[1] = 'd';
break;
default:
// this should never happen
swtchWarn[1] = 'x';
break;
}
if (swtchWarn[0] >= 'A' && swtchWarn[1] != 0) {
if (!wf(opaque, swtchWarn, 2)) {
return false;
}
}
}
}
return true;
}
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[];
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
@@ -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("switchWarning", 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 ),
+3 -3
View File
@@ -216,7 +216,7 @@ char switchGetLetter(uint8_t idx)
return -1;
uint8_t c = 1;
if (idx >= switchGetMaxSwitches()) c = 2;
if (idx >= switchGetMaxSwitches() || switchIsFlex(idx)) c = 2;
const char* name = switchGetName(idx);
if (!name) return -1;
@@ -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();
@@ -809,7 +809,7 @@ void checkSwitches()
void checkSwitches()
{
swarnstate_t last_bad_switches = 0xff;
swarnstate_t states = g_model.switchWarningState;
swarnstate_t states = g_model.switchWarning;
uint16_t bad_pots = 0, last_bad_pots = 0xff;
#if defined(PWR_BUTTON_PRESS)
+3 -3
View File
@@ -74,7 +74,7 @@ TEST(Conversions, ConversionX9DPFrom23)
(0x02 << (3 * 6)); // SG middle
// check only the "allowed switches"
EXPECT_EQ(state, g_model.switchWarningState & 0xFFFFF);
EXPECT_EQ(state, g_model.switchWarning & 0xFFFFF);
EXPECT_STRNEQ("Test", g_model.header.name); // ZSTREQ
EXPECT_EQ(TMRMODE_ON, g_model.timers[0].mode); // new!
@@ -267,7 +267,7 @@ TEST(Conversions, ConversionX7From23)
// check only configured switches (as the code does)
swarnstate_t sw_mask = get_configured_switch_warn_mask();
EXPECT_EQ(state & sw_mask, g_model.switchWarningState & sw_mask);
EXPECT_EQ(state & sw_mask, g_model.switchWarning & sw_mask);
EXPECT_STRNEQ("Test", g_model.header.name);
EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
@@ -502,7 +502,7 @@ TEST(Conversions, ConversionTX16SFrom25)
(0x01) |// SA up
(0x02 << (3 * 2)) | // SB middle
(0x03 << (3 * 5)); // SF down
EXPECT_EQ(swWarnState, g_model.switchWarningState);
EXPECT_EQ(swWarnState, g_model.switchWarning);
EXPECT_EQ(MIXSRC_FIRST_LOGICAL_SWITCH + 4, g_model.mixData[4].srcRaw);
EXPECT_EQ(MIXSRC_SC, g_model.mixData[5].srcRaw);
+5
View File
@@ -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
View File
@@ -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 %}