fix: Pot and slider warnings weren't being set properly on radio or syncing with Companion (#1981)

- fix Companion yaml model read and write
- B&W radios treat bit values the same as color to avoid unnecessary complication for Companion and radio conversions
- B&W radios default is therefore off for all pots and sliders
- B&W radios fix runtime warnings check
- all radios fix to save last pot or slider position when checked and mode AUTO on change of model or power off
- all radios do not display Pots Warning in model setup if no pots or sliders supported
This commit is contained in:
Neil Horne
2022-06-07 13:04:40 +10:00
committed by GitHub
parent cd59eac89f
commit cba4e07ce1
7 changed files with 45 additions and 35 deletions
@@ -140,6 +140,15 @@ struct YamlThrTrace {
struct YamlPotsWarnEnabled {
unsigned int value;
const int cnt = CPN_MAX_POTS + CPN_MAX_SLIDERS; // must not exceed 16 as radio stores in uint16_t
#define MAXPOTWARNINGS (CPN_MAX_POTS + CPN_MAX_SLIDERS)
#if MAXPOTWARNINGS > 16
#error Not enough space for pot and slider warnings
#endif
#undef MAXPOTWARNINGS
YamlPotsWarnEnabled() = default;
@@ -147,17 +156,17 @@ struct YamlPotsWarnEnabled {
{
value = 0;
for (int i = 0; i < 8; i++) {
value |= (*(potsWarnEnabled + i) << (7 - i));
for (int i = 0; i < cnt; i++) {
value |= (*(potsWarnEnabled + i)) << i;
}
}
void toCpn(bool * potsWarnEnabled)
{
memset(potsWarnEnabled, 0, sizeof(bool) * (CPN_MAX_POTS + CPN_MAX_SLIDERS));
memset(potsWarnEnabled, 0, sizeof(bool) * cnt);
for (int i = 1; i <= 8; i++) {
*(potsWarnEnabled + (i - 1)) = (bool)((value >> (8 - i)) & 1);
for (int i = 0; i < cnt; i++) {
*(potsWarnEnabled + i) = (bool)((value >> i) & 1);
}
}
};
@@ -856,7 +865,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode;
node["jitterFilter"] = jitterFilterLut << rhs.jitterFilter;
YamlPotsWarnEnabled potsWarnEnabled(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]);
YamlPotsWarnEnabled potsWarnEnabled(&rhs.potsWarnEnabled[0]);
node["potsWarnEnabled"] = potsWarnEnabled.value;
for (int i = 0; i < CPN_MAX_POTS + CPN_MAX_SLIDERS; i++) {
@@ -1048,7 +1057,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
YamlPotsWarnEnabled potsWarnEnabled;
node["potsWarnEnabled"] >> potsWarnEnabled.value;
potsWarnEnabled.toCpn(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]);
potsWarnEnabled.toCpn(&rhs.potsWarnEnabled[0]);
node["potsWarnPosition"] >> rhs.potsWarnPosition;