From 889e88d6712bf9eb97eb600dbb630dbce1754dc1 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 18 Dec 2020 19:07:12 +0100 Subject: [PATCH] cumulate uptime after deep sleep --- include/cyclic.h | 1 + src/cyclic.cpp | 8 +++++++- src/reset.cpp | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/cyclic.h b/include/cyclic.h index 6bd9b2a7..10509f1b 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -15,6 +15,7 @@ extern Ticker cyclicTimer; void setCyclicIRQ(void); void doHousekeeping(void); +uint64_t _uptime(uint64_t diff); uint64_t uptime(void); void reset_counters(void); uint32_t getFreeRAM(); diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 2799b918..7e12db65 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -136,7 +136,13 @@ void doHousekeeping() { } // doHousekeeping() -uint64_t uptime() { return millis(); } +uint64_t _uptime(uint64_t diff) { + static uint64_t offset = 0; + offset += diff; + return millis() + offset; +} + +uint64_t uptime(void){return _uptime(0);}; uint32_t getFreeRAM() { #ifndef BOARD_HAS_PSRAM diff --git a/src/reset.cpp b/src/reset.cpp index f740d002..40fd9772 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -49,6 +49,7 @@ void do_after_reset(void) { (sleep_stop_time.tv_sec - RTC_sleep_start_time.tv_sec) * 1000 + (sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000; ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms); + _uptime(sleep_time_ms); // increment uptime RTC_runmode = RUNMODE_WAKEUP; break;