From 9fac2d8d81095c6afc90daee5da6d6f500aa99f4 Mon Sep 17 00:00:00 2001 From: Leon Oostrum Date: Fri, 28 Jul 2023 11:46:51 +0200 Subject: [PATCH 1/2] Do not update display when all sensors are inactive to avoid infinite loop --- device/PowerSensor/PowerSensor.ino | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/device/PowerSensor/PowerSensor.ino b/device/PowerSensor/PowerSensor.ino index 64b1f97..3098d89 100644 --- a/device/PowerSensor/PowerSensor.ino +++ b/device/PowerSensor/PowerSensor.ino @@ -82,6 +82,7 @@ bool sendData = false; bool streamValues = false; bool sendSingleValue = false; bool sendMarkerNext = false; +bool allSensorsInactive = false; // include device-specific code for setting up the ADC and DMA #if defined STM32F401xC || defined STM32F411xE @@ -302,6 +303,14 @@ void configureDevice() { LL_ADC_Enable(ADC2); #endif LL_ADC_REG_StartConversionSWStart(ADC1); + checkActiveSensors(); +} + +void checkActiveSensors() { + allSensorsInactive = true; + for (int pair=0; pair < PAIRS; pair++) { + allSensorsInactive &= !(eeprom.sensors[2 * pair].inUse & eeprom.sensors[2 * pair + 1].inUse); + } } @@ -327,7 +336,7 @@ void updateDisplay() { static unsigned long previousMillis = 0; unsigned long interval = (unsigned long)(millis() - previousMillis); - if (interval > UPDATE_INVERVAL) { + if (interval > UPDATE_INVERVAL) { static unsigned int sensor_pair = 0; previousMillis = millis(); @@ -382,7 +391,7 @@ void loop() { serialEvent(); // update display if enabled #ifndef NODISPLAY - if (!displayPaused) { + if (!displayPaused && !allSensorsInactive) { updateDisplay(); } #endif From da85087f4a4c4f833099e4705eb44734c7aec110 Mon Sep 17 00:00:00 2001 From: Leon Oostrum Date: Fri, 28 Jul 2023 11:49:20 +0200 Subject: [PATCH 2/2] Fix linter issue --- device/PowerSensor/PowerSensor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/PowerSensor/PowerSensor.ino b/device/PowerSensor/PowerSensor.ino index 3098d89..253b1f2 100644 --- a/device/PowerSensor/PowerSensor.ino +++ b/device/PowerSensor/PowerSensor.ino @@ -336,7 +336,7 @@ void updateDisplay() { static unsigned long previousMillis = 0; unsigned long interval = (unsigned long)(millis() - previousMillis); - if (interval > UPDATE_INVERVAL) { + if (interval > UPDATE_INVERVAL) { static unsigned int sensor_pair = 0; previousMillis = millis();