Various Companion fixes (#1449)

- Fix (de-)serializing enable param for backlight custom function
- Fix OFF backlight
- Fix power ON/OFF delay
- Fix flight mode trim disabled
- Fix trim switch index
- Fix deserializing SLIDER[1,2]
- Fix shift for logical switches in raw sources
This commit is contained in:
Peter Feerick
2022-01-18 11:13:11 +10:00
committed by GitHub
5 changed files with 18 additions and 10 deletions
@@ -27,7 +27,8 @@ static bool fnHasEnable(AssignFunc fn)
return (fn <= FuncInstantTrim) return (fn <= FuncInstantTrim)
|| (fn >= FuncReset && fn <= FuncSetTimerLast) || (fn >= FuncReset && fn <= FuncSetTimerLast)
|| (fn >= FuncAdjustGV1 && fn <= FuncBindExternalModule) || (fn >= FuncAdjustGV1 && fn <= FuncBindExternalModule)
|| (fn == FuncVolume); || (fn == FuncVolume)
|| (fn == FuncBacklight);
} }
static bool fnHasRepeat(AssignFunc fn) static bool fnHasRepeat(AssignFunc fn)
@@ -147,6 +147,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["gpsFormat"] = rhs.gpsFormat; node["gpsFormat"] = rhs.gpsFormat;
node["speakerVolume"] = rhs.speakerVolume + 12; node["speakerVolume"] = rhs.speakerVolume + 12;
node["backlightBright"] = rhs.backlightBright; node["backlightBright"] = rhs.backlightBright;
node["blOffBright"] = rhs.backlightOffBright;
node["switchesDelay"] = rhs.switchesDelay; node["switchesDelay"] = rhs.switchesDelay;
node["globalTimer"] = rhs.globalTimer; node["globalTimer"] = rhs.globalTimer;
node["bluetoothName"] = rhs.bluetoothName; node["bluetoothName"] = rhs.bluetoothName;
@@ -169,6 +170,8 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["aux2SerialMode"] = uartModeLut << rhs.aux2SerialMode; node["aux2SerialMode"] = uartModeLut << rhs.aux2SerialMode;
node["antennaMode"] = antennaModeLut << rhs.antennaMode; node["antennaMode"] = antennaModeLut << rhs.antennaMode;
node["backlightColor"] = rhs.backlightColor; node["backlightColor"] = rhs.backlightColor;
node["pwrOnSpeed"] = rhs.pwrOnSpeed;
node["pwrOffSpeed"] = rhs.pwrOffSpeed;
for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) {
const CustomFunctionData& fn = rhs.customFn[i]; const CustomFunctionData& fn = rhs.customFn[i];
@@ -304,6 +307,7 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["gpsFormat"] >> rhs.gpsFormat; node["gpsFormat"] >> rhs.gpsFormat;
node["speakerVolume"] >> ioffset_int(rhs.speakerVolume, 12); node["speakerVolume"] >> ioffset_int(rhs.speakerVolume, 12);
node["backlightBright"] >> rhs.backlightBright; node["backlightBright"] >> rhs.backlightBright;
node["blOffBright"] >> rhs.backlightOffBright;
node["switchesDelay"] >> rhs.switchesDelay; node["switchesDelay"] >> rhs.switchesDelay;
node["globalTimer"] >> rhs.globalTimer; node["globalTimer"] >> rhs.globalTimer;
node["bluetoothName"] >> rhs.bluetoothName; node["bluetoothName"] >> rhs.bluetoothName;
@@ -326,6 +330,9 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode; node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode;
node["antennaMode"] >> antennaModeLut >> rhs.antennaMode; node["antennaMode"] >> antennaModeLut >> rhs.antennaMode;
node["backlightColor"] >> rhs.backlightColor; node["backlightColor"] >> rhs.backlightColor;
node["pwrOnSpeed"] >> rhs.pwrOnSpeed;
node["pwrOffSpeed"] >> rhs.pwrOffSpeed;
node["customFn"] >> rhs.customFn; node["customFn"] >> rhs.customFn;
YamlStickConfig stickConfig; YamlStickConfig stickConfig;
@@ -369,7 +369,7 @@ struct convert<YamlTrim> {
Node node; Node node;
node["value"] = rhs.value; node["value"] = rhs.value;
if (rhs.mode < 0) { if (rhs.mode < 0) {
node["mode"] = -1; node["mode"] = (1 << 5) - 1;
} else { } else {
node["mode"] = 2 * rhs.ref + rhs.mode; node["mode"] = 2 * rhs.ref + rhs.mode;
} }
@@ -381,8 +381,8 @@ struct convert<YamlTrim> {
int trimMode = 0; int trimMode = 0;
node["mode"] >> trimMode; node["mode"] >> trimMode;
if (trimMode < 0) { if (trimMode == (1 << 5) - 1) {
rhs.mode = trimMode; rhs.mode = -1;
} else { } else {
rhs.mode = trimMode % 2; rhs.mode = trimMode % 2;
rhs.ref = trimMode / 2; rhs.ref = trimMode / 2;
@@ -49,7 +49,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
break; break;
case SOURCE_TYPE_CUSTOM_SWITCH: case SOURCE_TYPE_CUSTOM_SWITCH:
src_str += "ls("; src_str += "ls(";
src_str += std::to_string(rhs.index); src_str += std::to_string(rhs.index + 1);
src_str += ")"; src_str += ")";
break; break;
case SOURCE_TYPE_CYC: case SOURCE_TYPE_CYC:
@@ -108,7 +108,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
if (idx < CPN_MAX_INPUTS) { if (idx < CPN_MAX_INPUTS) {
rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, idx); rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, idx);
} }
} else if (val_len >= 2 } else if (val_len == 2
&& val[0] == 'S' && val[0] == 'S'
&& val[1] >= 'A' && val[1] >= 'A'
&& val[1] <= 'Z') { && val[1] <= 'Z') {
@@ -139,8 +139,8 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
std::stringstream src(src_str.substr(3)); std::stringstream src(src_str.substr(3));
int ls = 0; int ls = 0;
src >> ls; src >> ls;
if (ls < CPN_MAX_LOGICAL_SWITCHES) if (ls > 0 && ls < CPN_MAX_LOGICAL_SWITCHES)
rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls); rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls - 1);
} else if (val_len > 3 && } else if (val_len > 3 &&
val[0] == 't' && val[0] == 't' &&
@@ -50,7 +50,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs)
break; break;
case SWITCH_TYPE_TRIM: case SWITCH_TYPE_TRIM:
sw_str += getCurrentFirmware()->getTrimSwitchesTag(sval); sw_str += getCurrentFirmware()->getTrimSwitchesTag(sval - 1);
break; break;
case SWITCH_TYPE_FLIGHT_MODE: case SWITCH_TYPE_FLIGHT_MODE:
@@ -132,7 +132,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str_tmp.c_str()); int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str_tmp.c_str());
if (tsw_idx >= 0) { if (tsw_idx >= 0) {
rhs.type = SWITCH_TYPE_TRIM; rhs.type = SWITCH_TYPE_TRIM;
rhs.index = tsw_idx; rhs.index = tsw_idx + 1;
} }
} else if (val_len >= 3 && val[0] == 'S' && } else if (val_len >= 3 && val[0] == 'S' &&