diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index 5790264..b116494 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -2,9 +2,9 @@ #include #include +#include "../modules/pico-onewire/api/one_wire.h" #include "hardware/i2c.h" #include "pico/stdlib.h" -#include "../modules/pico-onewire/api/one_wire.h" #include "config.h" #include "ds18b20.h" @@ -55,7 +55,8 @@ int main() { sleep_ms(3000); while (true) { - int duration = oneWire.convert_temperature(address, true, false); + absolute_time_t start = get_absolute_time(); + oneWire.convert_temperature(address, true, false); temp_act = oneWire.temperature(address); if (isSystemOn && temp_act < temp_tgt - temp_diff) { @@ -78,8 +79,13 @@ int main() { myLCD.setCursor(0, 0); myLCD.sendString(lcdText.str()); - if (duration > 0 && duration <= 1000) { - sleep_ms(1000 - duration); - } + + absolute_time_t stop = get_absolute_time(); + + int64_t duration_ms = absolute_time_diff_us(start, stop) / 1000; + int64_t timeToSleep = 1000 - duration_ms; + + if (timeToSleep > 0) + sleep_ms(timeToSleep); } } \ No newline at end of file