cleanup period stuff for new scheduler

This commit is contained in:
geeksville 2020-02-21 10:20:47 -08:00
parent d4efb2c44c
commit a6b98bec1f
5 changed files with 14 additions and 7 deletions

View File

@ -70,7 +70,7 @@ uint32_t GPS::getValidTime()
return timeSetFromGPS ? getTime() : 0; return timeSetFromGPS ? getTime() : 0;
} }
uint32_t GPS::doTask() void GPS::doTask()
{ {
#ifdef GPS_RX_PIN #ifdef GPS_RX_PIN
// Consume all characters that have arrived // 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 // 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() String GPS::getTimeStr()

View File

@ -27,7 +27,7 @@ public:
virtual void loop(); 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 /// If we haven't yet set our RTC this boot, set it from a GPS derived time
void perhapsSetRTC(const struct timeval *tv); void perhapsSetRTC(const struct timeval *tv);

View File

@ -18,5 +18,5 @@ public:
protected: protected:
uint32_t doTask(); void doTask();
}; };

View File

@ -12,8 +12,12 @@ void PeriodicTask::loop()
if (period && (now - lastMsec) >= period) if (period && (now - lastMsec) >= period)
{ {
lastMsec = now; lastMsec = now;
period = doTask(); doTask();
} }
} }
uint32_t Periodic::doTask() { return callback(); } void Periodic::doTask()
{
uint32_t p = callback();
setPeriod(p);
}

View File

@ -25,6 +25,9 @@ public:
/// call this from loop /// call this from loop
virtual void 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: protected:
virtual uint32_t doTask() = 0; virtual void doTask() = 0;
}; };