Fixed switch warnings
This commit is contained in:
@@ -158,7 +158,12 @@ struct YamlPotsWarnEnabled {
|
|||||||
// modeldata: uint64_t switchWarningStates
|
// modeldata: uint64_t switchWarningStates
|
||||||
// Yaml switchWarningState: AuBuEuFuG-IuJu
|
// Yaml switchWarningState: AuBuEuFuG-IuJu
|
||||||
struct YamlSwitchWarningState {
|
struct YamlSwitchWarningState {
|
||||||
|
|
||||||
|
static constexpr size_t MASK_LEN = 2;
|
||||||
|
static constexpr size_t MASK = (1 << MASK_LEN) - 1;
|
||||||
|
|
||||||
std::string src_str;
|
std::string src_str;
|
||||||
|
uint64_t enabled;
|
||||||
|
|
||||||
YamlSwitchWarningState() = default;
|
YamlSwitchWarningState() = default;
|
||||||
|
|
||||||
@@ -166,84 +171,73 @@ struct YamlSwitchWarningState {
|
|||||||
{
|
{
|
||||||
uint64_t states = cpn_value;
|
uint64_t states = cpn_value;
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
||||||
|
//TODO: exclude 2-pos toggle from switch warnings
|
||||||
if (!(switchWarningEnable & (1 << i))) {
|
if (!(switchWarningEnable & (1 << i))) {
|
||||||
std::string tag = getCurrentFirmware()->getSwitchesTag(i);
|
std::string tag = getCurrentFirmware()->getSwitchesTag(i);
|
||||||
const char *sw = tag.data();
|
const char *sw = tag.data();
|
||||||
|
|
||||||
if (tag.size() >= 2 && sw[0] == 'S') {
|
if (tag.size() >= 2 && sw[0] == 'S') {
|
||||||
char val[3];
|
ss << sw[1];
|
||||||
val[0] = sw[1];
|
switch(states & MASK) {
|
||||||
|
case 0:
|
||||||
uint64_t value = (i == 0 ? states & 0x3 : states & 0x1);
|
ss << 'u';
|
||||||
|
break;
|
||||||
if (value == 0)
|
case 1:
|
||||||
val[1] = 'u';
|
ss << '-';
|
||||||
else if (value == 1)
|
break;
|
||||||
val[1] = '-';
|
case 2:
|
||||||
else
|
ss << 'd';
|
||||||
val[1] = 'd';
|
break;
|
||||||
val[2] = '\0';
|
}
|
||||||
|
|
||||||
src_str.append(val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
states >>= MASK_LEN;
|
||||||
states >>= (i == 0 ? 2 : 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ss >> src_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t toCpn()
|
uint64_t toCpn()
|
||||||
{
|
{
|
||||||
uint64_t states = 0;
|
uint64_t states = 0;
|
||||||
|
enabled = 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < src_str.size() / 2; i++) {
|
std::stringstream ss(src_str);
|
||||||
auto val = src_str.substr(i * 2, 2);
|
while (!ss.eof()) {
|
||||||
if (val[0] >= 'A' && val[0] <= 'Z' && (
|
auto c = ss.get();
|
||||||
val[1] == 'u' || val[1] == '-' || val[1] == 'd')) {
|
if (c < 'A' && c > 'Z') {
|
||||||
|
ss.ignore();
|
||||||
int shift = 0;
|
continue;
|
||||||
uint64_t mask;
|
|
||||||
|
|
||||||
char sw[3];
|
|
||||||
sw[0] = 'S';
|
|
||||||
sw[1] = val[0];
|
|
||||||
sw[2] = '\0';
|
|
||||||
|
|
||||||
int index = getCurrentFirmware()->getSwitchesIndex(sw);
|
|
||||||
|
|
||||||
if (index > -1) {
|
|
||||||
|
|
||||||
if (IS_HORUS_OR_TARANIS(getCurrentFirmware()->getBoard())) {
|
|
||||||
shift = index * 2;
|
|
||||||
mask = 0x03ull << shift;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (index == 0) {
|
|
||||||
mask = 0x03;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
shift = index + 1;
|
|
||||||
mask = 0x01ull << shift;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states &= ~mask;
|
|
||||||
|
|
||||||
uint64_t value;
|
|
||||||
|
|
||||||
if (val[1] == 'u')
|
|
||||||
value = 0;
|
|
||||||
else if (val[1] == '-')
|
|
||||||
value = 1;
|
|
||||||
else
|
|
||||||
value = 2;
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
states |= ((uint64_t)value << shift);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string sw = std::string("S") + (char)c;
|
||||||
|
int index = getCurrentFirmware()->getSwitchesIndex(sw.c_str());
|
||||||
|
if (index < 0) {
|
||||||
|
ss.ignore();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto s = ss.get();
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
switch(s) {
|
||||||
|
case 'u':
|
||||||
|
value = 0;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
value = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
value = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
states |= ((uint64_t)value << (index * MASK_LEN));
|
||||||
|
enabled |= (1 << index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return states;
|
return states;
|
||||||
@@ -933,6 +927,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
|||||||
YamlSwitchWarningState switchWarningState;
|
YamlSwitchWarningState switchWarningState;
|
||||||
node["switchWarningState"] >> switchWarningState.src_str;
|
node["switchWarningState"] >> switchWarningState.src_str;
|
||||||
rhs.switchWarningStates = switchWarningState.toCpn();
|
rhs.switchWarningStates = switchWarningState.toCpn();
|
||||||
|
rhs.switchWarningEnable = ~switchWarningState.enabled;
|
||||||
|
|
||||||
node["thrTrimSw"] >> rhs.thrTrimSwitch;
|
node["thrTrimSw"] >> rhs.thrTrimSwitch;
|
||||||
node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode;
|
node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user