From 80cceedee6949609627006fa8d8019740a2e354d Mon Sep 17 00:00:00 2001 From: Leon Oostrum Date: Thu, 28 Nov 2024 15:45:01 +0100 Subject: [PATCH] Decrease missed packets when using marker: sendData set to false as quickly as possible so it can be set to true again by the interrupt handler while sending data is still in progress --- 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 5bf8e11..d679cc4 100644 --- a/device/PowerSensor/PowerSensor.ino +++ b/device/PowerSensor/PowerSensor.ino @@ -411,6 +411,7 @@ void setup() { void loop() { if (sendData) { + sendData = false; // copy serialData to avoid overwrite by next values in IRQ handler uint8_t serialDataToSend[sizeof(serialData)]; memcpy(serialDataToSend, serialData, sizeof(serialData)); @@ -421,7 +422,6 @@ void loop() { sendMarkers--; } Serial.write(serialDataToSend, sizeof(serialDataToSend)); - sendData = false; } // check for serial events serialEvent();