diff --git a/src/GPS.cpp b/src/GPS.cpp index c89a55368..6b89e6324 100644 --- a/src/GPS.cpp +++ b/src/GPS.cpp @@ -70,7 +70,7 @@ uint32_t GPS::getValidTime() return timeSetFromGPS ? getTime() : 0; } -uint32_t GPS::doTask() +void GPS::doTask() { #ifdef GPS_RX_PIN // Consume all characters that have arrived @@ -111,7 +111,7 @@ uint32_t GPS::doTask() } // Once we have sent a location we only poll the GPS rarely, otherwise check back every 100ms until we have something over the serial - return hasValidLocation ? 30 * 1000 : 100; + setPeriod(hasValidLocation ? 30 * 1000 : 100); } String GPS::getTimeStr() diff --git a/src/GPS.h b/src/GPS.h index 1a2c82ad9..9ff98cca3 100644 --- a/src/GPS.h +++ b/src/GPS.h @@ -27,7 +27,7 @@ public: virtual void loop(); - virtual uint32_t doTask(); + virtual void doTask(); /// If we haven't yet set our RTC this boot, set it from a GPS derived time void perhapsSetRTC(const struct timeval *tv); diff --git a/src/Periodic.h b/src/Periodic.h index 92d66241f..2081a5065 100644 --- a/src/Periodic.h +++ b/src/Periodic.h @@ -18,5 +18,5 @@ public: protected: - uint32_t doTask(); + void doTask(); }; diff --git a/src/PeriodicTask.cpp b/src/PeriodicTask.cpp index bb46d1ce2..b9410c69e 100644 --- a/src/PeriodicTask.cpp +++ b/src/PeriodicTask.cpp @@ -12,8 +12,12 @@ void PeriodicTask::loop() if (period && (now - lastMsec) >= period) { lastMsec = now; - period = doTask(); + doTask(); } } - uint32_t Periodic::doTask() { return callback(); } \ No newline at end of file +void Periodic::doTask() +{ + uint32_t p = callback(); + setPeriod(p); +} \ No newline at end of file diff --git a/src/PeriodicTask.h b/src/PeriodicTask.h index 5ac90e29a..59659e2d4 100644 --- a/src/PeriodicTask.h +++ b/src/PeriodicTask.h @@ -25,6 +25,9 @@ public: /// call this from loop virtual void loop(); + /// Set a new period in msecs (can be called from doTask or elsewhere and the scheduler will cope) + void setPeriod(uint32_t p) { period = p; } + protected: - virtual uint32_t doTask() = 0; + virtual void doTask() = 0; };