diff --git a/companion/src/constants.h b/companion/src/constants.h index 3bc547d81..c3b8b9d74 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -46,6 +46,7 @@ #define CPN_MAX_MOUSE_ANALOGS 2 #define CPN_MAX_GYRO_ANALOGS 2 #define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_SLIDERS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) +#define CPN_MAX_SENSORS 60 #define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion") #define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 3e7512aa4..35a6d1f18 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -111,21 +111,25 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); - if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_LOGICAL_SWITCHES - rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { + rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && (val[2] >= '0' && val[2] <= '9') && (val[3] >= '0' && val[3] < (multiposcnt + '0'))) { rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, (val[2] - '0') * multiposcnt + (val[3] - '0')); } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && - (val[2] >= '0' && val[2] <= '9')) { // TODO: range check < CPN_MAX_FLIGHT_MODES + (val[2] >= '0' && val[2] <= '9')) { rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); } else if (val_len >= 2 && val[0] == 'T' && - (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_SENSORS - rhs = RawSwitch(SWITCH_TYPE_SENSOR, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { + rhs = RawSwitch(SWITCH_TYPE_SENSOR, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } } else if (sw_str.substr(0, 3) == std::string("Trim")) { // TODO: use lookup of trims in Boards ??? rhs.type = SWITCH_TYPE_TRIM; diff --git a/companion/src/firmwares/sensordata.h b/companion/src/firmwares/sensordata.h index cec9a6a63..4722f9453 100644 --- a/companion/src/firmwares/sensordata.h +++ b/companion/src/firmwares/sensordata.h @@ -24,7 +24,6 @@ #include -constexpr int CPN_MAX_SENSORS { 60 }; constexpr int SENSOR_LABEL_LEN { 4 }; constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 };