From 729ee7cdbff184c3c3464d882283bc178f62b331 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 25 Aug 2019 16:31:59 -0400 Subject: [PATCH] Fix #6: now that cTimer is part of CatenaArduinoPlatform, remove it here --- .../catena4630-pms7003-demo.ino | 99 +------------- .../catena-pms7003-lora-cMeasurementLoop.h | 4 +- .../catena-pms7003-lora-cTimer.cpp | 128 ------------------ .../catena-pms7003-lora-cTimer.h | 96 ------------- 4 files changed, 3 insertions(+), 324 deletions(-) delete mode 100644 examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.cpp delete mode 100644 examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.h diff --git a/examples/catena4630-pms7003-demo/catena4630-pms7003-demo.ino b/examples/catena4630-pms7003-demo/catena4630-pms7003-demo.ino index 1a74d7b..94a2dad 100644 --- a/examples/catena4630-pms7003-demo/catena4630-pms7003-demo.ino +++ b/examples/catena4630-pms7003-demo/catena4630-pms7003-demo.ino @@ -19,6 +19,7 @@ Author: #include #include #include +#include #include #include #include @@ -32,104 +33,6 @@ Author: extern McciCatena::Catena gCatena; -/****************************************************************************\ -| -| A simple timer -- this uses cPollableObject because it's easier -| -\****************************************************************************/ - -class cTimer : public McciCatena::cPollableObject - { -public: - // constructor - cTimer() {} - - // neither copyable nor movable - cTimer(const cTimer&) = delete; - cTimer& operator=(const cTimer&) = delete; - cTimer(const cTimer&&) = delete; - cTimer& operator=(const cTimer&&) = delete; - - // initialze to fire every nMillis - bool begin(std::uint32_t nMillis); - - // stop operation - void end(); - - // poll function (updates data) - virtual void poll() override; - - bool isready(); - std::uint32_t readTicks(); - std::uint32_t peekTicks() const; - - void debugDisplay() const - { - Serial.print("time="); Serial.print(this->m_time); - Serial.print(" interval="); Serial.print(this->m_interval); - Serial.print(" events="); Serial.print(this->m_events); - Serial.print(" overrun="); Serial.println(this->m_overrun); - } - -private: - std::uint32_t m_time; - std::uint32_t m_interval; - std::uint32_t m_events; - std::uint32_t m_overrun; - }; - -bool cTimer::begin(std::uint32_t nMillis) - { - this->m_interval = nMillis; - this->m_time = millis(); - this->m_events = 0; - - // set up for polling. - gCatena.registerObject(this); - - return true; - } - -void cTimer::poll() /* override */ - { - auto const tNow = millis(); - - if (tNow - this->m_time >= this->m_interval) - { - this->m_time += this->m_interval; - ++this->m_events; - - /* if this->m_time is now in the future, we're done */ - if (std::int32_t(tNow - this->m_time) < std::int32_t(this->m_interval)) - return; - - // rarely, we need to do arithmetic. time and events are in sync. - // arrange for m_time to be greater than tNow, and adjust m_events - // accordingly. - std::uint32_t const tDiff = tNow - this->m_time; - std::uint32_t const nTicks = tDiff / this->m_interval; - this->m_events += nTicks; - this->m_time += nTicks * this->m_interval; - this->m_overrun += nTicks; - } - } - -bool cTimer::isready() - { - return this->readTicks() != 0; - } - -std::uint32_t cTimer::readTicks() - { - auto const result = this->m_events; - this->m_events = 0; - return result; - } - -std::uint32_t cTimer::peekTicks() const - { - return this->m_events; - } /****************************************************************************\ | diff --git a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cMeasurementLoop.h b/examples/catena4630-pms7003-lora/catena-pms7003-lora-cMeasurementLoop.h index b84297a..05689e4 100644 --- a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cMeasurementLoop.h +++ b/examples/catena4630-pms7003-lora/catena-pms7003-lora-cMeasurementLoop.h @@ -18,7 +18,6 @@ Module: catena-pms7003-lora-cMeasurementLoop.h #pragma once -#include "catena-pms7003-lora-cTimer.h" #include #include @@ -28,6 +27,7 @@ Module: catena-pms7003-lora-cMeasurementLoop.h #include #include #include +#include #include #include #include @@ -287,7 +287,7 @@ class cMeasurementLoop : public McciCatena::cPollableObject McciCatenaPMS7003::cPMS7003::DustBins m_Dust; // uplink time control - cTimer m_UplinkTimer; + McciCatena::cTimer m_UplinkTimer; std::uint32_t m_txCycleSec; std::uint32_t m_txCycleCount; std::uint32_t m_txCycleSec_Permanent; diff --git a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.cpp b/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.cpp deleted file mode 100644 index dfe6f56..0000000 --- a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - -Module: catena-pms7003-lora-cTimer.cpp - -Function: - cTimer methods - -Copyright: - See accompanying LICENSE file for copyright and license information. - -Author: - Terry Moore, MCCI Corporation July 2019 - -*/ - -#include "catena-pms7003-lora-cTimer.h" - -#include - -#ifndef ARDUINO_MCCI_CATENA_4630 -# error "This sketch targets the MCCI Catena 4630" -#endif - -extern McciCatena::Catena gCatena; - -/****************************************************************************\ -| -| A simple timer -- this uses cPollableObject because it's easier -| -\****************************************************************************/ - -bool cTimer::begin(std::uint32_t nMillis) - { - this->m_interval = nMillis; - this->m_time = millis(); - this->m_events = 0; - - // set up for polling. - if (! this->m_registered) - { - gCatena.registerObject(this); - this->m_registered = true; - } - - this->m_running = true; - return true; - } - -void cTimer::end() - { - this->m_running = false; - } - -std::uint32_t cTimer::setInterval( - std::uint32_t uInterval - ) - { - // this->m_time is the last trigger time. We change the - // time, and then poll the timer to adjust ticks -- so - // if you set the time shorter than current, you may get - // immediate ticks. - auto const uResult = this->m_interval; - this->m_interval = uInterval; - this->poll(); - return uResult; - } - -void cTimer::retrigger() - { - if (this->m_running) - this->m_time = millis(); - } - -void cTimer::poll() /* override */ - { - if (! this->m_running) - return; - - auto const tNow = millis(); - - if (tNow - this->m_time >= this->m_interval) - { - this->m_time += this->m_interval; - ++this->m_events; - - /* if this->m_time is now in the future, we're done */ - if (std::int32_t(tNow - this->m_time) < std::int32_t(this->m_interval)) - return; - - // rarely, we need to do arithmetic. time and events are in sync. - // arrange for m_time to be greater than tNow, and adjust m_events - // accordingly. - std::uint32_t const tDiff = tNow - this->m_time; - std::uint32_t const nTicks = tDiff / this->m_interval; - this->m_events += nTicks; - this->m_time += nTicks * this->m_interval; - this->m_overrun += nTicks; - } - } - -bool cTimer::isready() - { - return this->readTicks() != 0; - } - -std::uint32_t cTimer::readTicks() - { - auto const result = this->m_events; - this->m_events = 0; - return result; - } - -std::uint32_t cTimer::peekTicks() const - { - return this->m_events; - } - -std::uint32_t cTimer::getRemaining() const - { - auto const tNow = millis(); - - auto const elapsed = tNow - this->m_time; - - if (elapsed > this->m_interval) - return 0; - else - return this->m_interval - elapsed; - } diff --git a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.h b/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.h deleted file mode 100644 index 10329f3..0000000 --- a/examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - -Module: catena-pms7003-lora-cTimer.h - -Function: - cTimer implementation - -Copyright: - See accompanying LICENSE file for copyright and license information. - -Author: - Terry Moore, MCCI Corporation July 2019 - -*/ - -#ifndef _cTimer_h_ -# define _cTimer_h_ - -#pragma once - -#include -#include -#include - -/****************************************************************************\ -| -| A simple timer -- this uses cPollableObject because it's easier -| -\****************************************************************************/ - -class cTimer : public McciCatena::cPollableObject - { -public: - // constructor - cTimer() : m_registered(false) - , m_running(false) - {} - - // neither copyable nor movable - cTimer(const cTimer&) = delete; - cTimer& operator=(const cTimer&) = delete; - cTimer(const cTimer&&) = delete; - cTimer& operator=(const cTimer&&) = delete; - - // initialze to fire every nMillis - bool begin(std::uint32_t nMillis); - - // stop operation - void end(); - - // poll function (updates data) - virtual void poll() override; - - // return true if one or more events has occured; consumes ticks. - bool isready(); - // return number of pending ticks, consuming them. - std::uint32_t readTicks(); - // return number of pendign ticks, without consuming them. - std::uint32_t peekTicks() const; - // get the currrent tick interval. - std::uint32_t getInterval() const - { return this->m_interval; } - std::uint32_t getRemaining() const; - // change the tick interval. May cause immediate tick(s) if shortening - // interval. - std::uint32_t setInterval(std::uint32_t uInterval); - // retrigger the timer, meaning that any active interval starts now. - void retrigger(); - - // display some info for debugging. - void debugDisplay() const - { - Serial.print("time="); Serial.print(this->m_time); - Serial.print(" interval="); Serial.print(this->m_interval); - Serial.print(" events="); Serial.print(this->m_events); - Serial.print(" overrun="); Serial.print(this->m_overrun); - Serial.print(" registered="); Serial.print(this->m_registered); - Serial.print(" running="); Serial.println(this->m_running); - } - -private: - // millis() at last tick time. - std::uint32_t m_time; - // millis() between ticks. - std::uint32_t m_interval; - // number of unconsumed ticks (events) - std::uint32_t m_events; - // count of ticks that were coalesced - std::uint32_t m_overrun; - // true if clock is registered for polling. - bool m_registered; - // true if clock is running. - bool m_running; - }; - -#endif