Fix switch indexes (#1362)

Resolves #1353
This commit is contained in:
Raphael Coeffic
2022-01-07 10:31:37 +10:00
committed by GitHub
parent c7e7443c30
commit d97afb6f8e
@@ -45,8 +45,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
src_str += "MAX"; src_str += "MAX";
break; break;
case SOURCE_TYPE_SWITCH: case SOURCE_TYPE_SWITCH:
src_str += "S"; src_str += getCurrentFirmware()->getSwitchesTag(rhs.index);
src_str += (rhs.index + 'A');
break; break;
case SOURCE_TYPE_CUSTOM_SWITCH: case SOURCE_TYPE_CUSTOM_SWITCH:
src_str += "ls("; src_str += "ls(";
@@ -114,8 +113,8 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
&& val[1] >= 'A' && val[1] >= 'A'
&& val[1] <= 'Z') { && val[1] <= 'Z') {
int idx = val[1] - 'A'; int idx = getCurrentFirmware()->getSwitchesIndex(src_str.c_str());
if (idx < CPN_MAX_SWITCHES) if (idx >= 0 && idx < CPN_MAX_SWITCHES)
rhs = RawSource(SOURCE_TYPE_SWITCH, idx); rhs = RawSource(SOURCE_TYPE_SWITCH, idx);
} else if (val_len > 4 && } else if (val_len > 4 &&