Skip to content

Commit

Permalink
Merge pull request #7 from mcci-catena/issue6
Browse files Browse the repository at this point in the history
Fix #6: now that cTimer is part of CatenaArduinoPlatform, remove it here
  • Loading branch information
terrillmoore authored Aug 25, 2019
2 parents 0b0dcf5 + 729ee7c commit e22aa10
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 324 deletions.
99 changes: 1 addition & 98 deletions examples/catena4630-pms7003-demo/catena4630-pms7003-demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Author:
#include <Catena_Log.h>
#include <Catena_Mx25v8035f.h>
#include <Catena_PollableInterface.h>
#include <Catena_Timer.h>
#include <Adafruit_BME280.h>
#include <Catena-PMS7003.h>
#include <Catena-PMS7003Hal-4630.h>
Expand All @@ -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;
}

/****************************************************************************\
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Module: catena-pms7003-lora-cMeasurementLoop.h

#pragma once

#include "catena-pms7003-lora-cTimer.h"

#include <Arduino.h>
#include <Wire.h>
Expand All @@ -28,6 +27,7 @@ Module: catena-pms7003-lora-cMeasurementLoop.h
#include <Catena_Log.h>
#include <Catena_Mx25v8035f.h>
#include <Catena_PollableInterface.h>
#include <Catena_Timer.h>
#include <Catena_TxBuffer.h>
#include <Adafruit_BME280.h>
#include <Catena-PMS7003.h>
Expand Down Expand Up @@ -287,7 +287,7 @@ class cMeasurementLoop : public McciCatena::cPollableObject
McciCatenaPMS7003::cPMS7003::DustBins<std::uint16_t[kNumMeasurements]> 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;
Expand Down
128 changes: 0 additions & 128 deletions examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.cpp

This file was deleted.

96 changes: 0 additions & 96 deletions examples/catena4630-pms7003-lora/catena-pms7003-lora-cTimer.h

This file was deleted.

0 comments on commit e22aa10

Please sign in to comment.