From 7dc2f8991738432256825a1714c0883e9bd44e4b Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 17 Jan 2023 15:35:13 +1100 Subject: [PATCH] fix(ui,cpn): Error in value conversion when loading LS data (#3026) * Fix error in value conversion when loading logical switch data from YAML files (for 'Edge' and 'Timer' functions). * Remove debug print. * Fix handling of telemetry sensors in Companion. --- companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp | 2 +- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_funcs.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp index 41ecc4109..9128718c0 100644 --- a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp @@ -47,7 +47,7 @@ static int timerValue2lsw(uint32_t t) { if (t < 20) { return t - 129; - } else if (600) { + } else if (t < 600) { return t / 5 - 113; } else { return t / 10 - 53; diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index ac2bccd82..5e9a94bc8 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -71,7 +71,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) case SWITCH_TYPE_SENSOR: sw_str += "T"; - sw_str += std::to_string(sval + 1); + sw_str += std::to_string(sval); break; default: @@ -131,7 +131,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) // starts at T1 int sensor_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1)); if ((sensor_idx > 0) && (sensor_idx <= CPN_MAX_SENSORS)) { - rhs = RawSwitch(SWITCH_TYPE_SENSOR, sensor_idx - 1); + rhs = RawSwitch(SWITCH_TYPE_SENSOR, sensor_idx); } } else if (sw_str_tmp.substr(0, 4) == std::string("Trim")) { diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index da804d3f2..aaa252b3f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -1647,7 +1647,7 @@ static delayval_t timerValue2lsw(uint32_t t) { if (t < 20) { return t - 129; - } else if (600) { + } else if (t < 600) { return t / 5 - 113; } else { return t / 10 - 53;