fix(radio): potential crash if too many telemetry sensors discovered (#6288)
This commit is contained in:
@@ -214,7 +214,7 @@ void menuModelTelemetry(event_t event)
|
|||||||
pushMenu(menuModelSensor);
|
pushMenu(menuModelSensor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
allowNewSensors = 0;
|
allowNewSensors = false;
|
||||||
POPUP_WARNING(STR_TELEMETRYFULL);
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ void menuModelTelemetry(event_t event)
|
|||||||
pushMenu(menuModelSensor);
|
pushMenu(menuModelSensor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
allowNewSensors = 0;
|
allowNewSensors = false;
|
||||||
POPUP_WARNING(STR_TELEMETRYFULL);
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -773,25 +773,26 @@ void ModelTelemetryPage::checkEvents()
|
|||||||
{
|
{
|
||||||
int _lastKnownIndex = availableTelemetryIndex();
|
int _lastKnownIndex = availableTelemetryIndex();
|
||||||
|
|
||||||
if (lastKnownIndex >= 0 && lastKnownIndex != _lastKnownIndex) {
|
if (_lastKnownIndex < 0) {
|
||||||
rebuild(window);
|
if (discover->checked()) {
|
||||||
|
buildSensorList(-1);
|
||||||
|
discover->setText(STR_DISCOVER_SENSORS);
|
||||||
|
discover->check(false);
|
||||||
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
|
}
|
||||||
|
} else if (lastKnownIndex != _lastKnownIndex) {
|
||||||
|
buildSensorList(-1);
|
||||||
lastKnownIndex = _lastKnownIndex;
|
lastKnownIndex = _lastKnownIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
PageTab::checkEvents();
|
PageTab::checkEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelTelemetryPage::rebuild(Window* window, int8_t focusSensorIndex)
|
void ModelTelemetryPage::editSensor(uint8_t index)
|
||||||
{
|
|
||||||
buildSensorList(focusSensorIndex);
|
|
||||||
lastKnownIndex = availableTelemetryIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelTelemetryPage::editSensor(Window* window, uint8_t index)
|
|
||||||
{
|
{
|
||||||
lastKnownIndex = -1;
|
lastKnownIndex = -1;
|
||||||
Window* editWindow = new SensorEditWindow(index);
|
Window* editWindow = new SensorEditWindow(index);
|
||||||
editWindow->setCloseHandler([=]() { rebuild(window, index); });
|
editWindow->setCloseHandler([=]() { buildSensorList(index); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
|
void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
|
||||||
@@ -809,7 +810,7 @@ void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
|
|||||||
|
|
||||||
button->setPressHandler([=]() -> uint8_t {
|
button->setPressHandler([=]() -> uint8_t {
|
||||||
Menu* menu = new Menu();
|
Menu* menu = new Menu();
|
||||||
menu->addLine(STR_EDIT, [=]() { editSensor(window, idx); });
|
menu->addLine(STR_EDIT, [=]() { editSensor(idx); });
|
||||||
menu->addLine(STR_COPY, [=]() {
|
menu->addLine(STR_COPY, [=]() {
|
||||||
auto newIndex = availableTelemetryIndex();
|
auto newIndex = availableTelemetryIndex();
|
||||||
if (newIndex >= 0) {
|
if (newIndex >= 0) {
|
||||||
@@ -820,26 +821,26 @@ void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
|
|||||||
TelemetryItem& newItem = telemetryItems[newIndex];
|
TelemetryItem& newItem = telemetryItems[newIndex];
|
||||||
newItem = sourceItem;
|
newItem = sourceItem;
|
||||||
SET_DIRTY();
|
SET_DIRTY();
|
||||||
rebuild(window, newIndex);
|
buildSensorList(newIndex);
|
||||||
} else {
|
} else {
|
||||||
new FullScreenDialog(WARNING_TYPE_ALERT, "", STR_TELEMETRYFULL);
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu->addLine(STR_DELETE, [=]() {
|
menu->addLine(STR_DELETE, [=]() {
|
||||||
delTelemetryIndex(idx); // calls setDirty internally
|
delTelemetryIndex(idx); // calls setDirty internally
|
||||||
for (uint8_t i = idx + 1; i < MAX_TELEMETRY_SENSORS; i += 1) {
|
for (uint8_t i = idx + 1; i < MAX_TELEMETRY_SENSORS; i += 1) {
|
||||||
if (g_model.telemetrySensors[i].isAvailable()) {
|
if (g_model.telemetrySensors[i].isAvailable()) {
|
||||||
rebuild(window, i);
|
buildSensorList(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int8_t i = idx - 1; i >= 0; i -= 1) {
|
for (int8_t i = idx - 1; i >= 0; i -= 1) {
|
||||||
if (g_model.telemetrySensors[i].isAvailable()) {
|
if (g_model.telemetrySensors[i].isAvailable()) {
|
||||||
rebuild(window, i);
|
buildSensorList(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rebuild(window, -1);
|
buildSensorList(-1);
|
||||||
});
|
});
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
@@ -859,6 +860,11 @@ void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
|
|||||||
|
|
||||||
uint8_t sensorsCount = getTelemetrySensorsCount();
|
uint8_t sensorsCount = getTelemetrySensorsCount();
|
||||||
deleteAll->show(sensorsCount > 0);
|
deleteAll->show(sensorsCount > 0);
|
||||||
|
|
||||||
|
if (availableTelemetryIndex() >= 0)
|
||||||
|
lastKnownIndex = availableTelemetryIndex();
|
||||||
|
else
|
||||||
|
lastKnownIndex = MAX_TELEMETRY_SENSORS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelTelemetryPage::build(Window* window)
|
void ModelTelemetryPage::build(Window* window)
|
||||||
@@ -867,8 +873,6 @@ void ModelTelemetryPage::build(Window* window)
|
|||||||
window->padBottom(PAD_LARGE);
|
window->padBottom(PAD_LARGE);
|
||||||
window->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO);
|
window->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO);
|
||||||
|
|
||||||
this->window = window;
|
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
new Subtitle(window, STR_TELEMETRY_SENSORS);
|
new Subtitle(window, STR_TELEMETRY_SENSORS);
|
||||||
|
|
||||||
@@ -902,9 +906,9 @@ void ModelTelemetryPage::build(Window* window)
|
|||||||
new TextButton(line, rect_t{}, STR_TELEMETRY_NEWSENSOR, [=]() -> uint8_t {
|
new TextButton(line, rect_t{}, STR_TELEMETRY_NEWSENSOR, [=]() -> uint8_t {
|
||||||
int idx = availableTelemetryIndex();
|
int idx = availableTelemetryIndex();
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
editSensor(window, idx);
|
editSensor(idx);
|
||||||
else
|
else
|
||||||
new FullScreenDialog(WARNING_TYPE_ALERT, "", STR_TELEMETRYFULL);
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
lv_obj_set_grid_cell(b->getLvObj(), LV_GRID_ALIGN_STRETCH, 1, 1,
|
lv_obj_set_grid_cell(b->getLvObj(), LV_GRID_ALIGN_STRETCH, 1, 1,
|
||||||
|
|||||||
@@ -37,14 +37,12 @@ class ModelTelemetryPage : public PageTab
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
int lastKnownIndex = 0;
|
int lastKnownIndex = 0;
|
||||||
Window* window = nullptr;
|
|
||||||
Window* sensorWindow = nullptr;
|
Window* sensorWindow = nullptr;
|
||||||
TextButton* discover = nullptr;
|
TextButton* discover = nullptr;
|
||||||
TextButton* deleteAll = nullptr;
|
TextButton* deleteAll = nullptr;
|
||||||
|
|
||||||
void checkEvents() override;
|
void checkEvents() override;
|
||||||
|
|
||||||
void editSensor(Window* window, uint8_t index);
|
void editSensor(uint8_t index);
|
||||||
void rebuild(Window* window, int8_t focusSensorIndex = -1);
|
|
||||||
void buildSensorList(int8_t focusSensorIndex = -1);
|
void buildSensorList(int8_t focusSensorIndex = -1);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS];
|
TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS];
|
||||||
uint8_t allowNewSensors;
|
bool allowNewSensors;
|
||||||
|
|
||||||
bool isFaiForbidden(source_t idx)
|
bool isFaiForbidden(source_t idx)
|
||||||
{
|
{
|
||||||
@@ -597,7 +597,11 @@ int setTelemetryValue(TelemetryProtocol protocol, uint16_t id, uint8_t subId,
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
allowNewSensors = false;
|
||||||
|
#if !defined(COLORLCD)
|
||||||
|
// Not safe on color LCD - handled in telemetry page instead
|
||||||
POPUP_WARNING(STR_TELEMETRYFULL);
|
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,5 +130,5 @@ class TelemetryItem
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS];
|
extern TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS];
|
||||||
extern uint8_t allowNewSensors;
|
extern bool allowNewSensors;
|
||||||
bool isFaiForbidden(source_t idx);
|
bool isFaiForbidden(source_t idx);
|
||||||
|
|||||||
Reference in New Issue
Block a user