Add the timer class functionality.

This commit is contained in:
Jonathan Naylor 2020-04-15 17:18:01 +01:00
parent db6fde90e0
commit a9a985182f
6 changed files with 50 additions and 45 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 by Jonathan Naylor G4KLX
* Copyright (C) 2009,2010,2015,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,36 +21,50 @@
#include "FMTimer.h"
CFMTimer::CFMTimer() :
m_timeout(0U)
m_timeout(0U),
m_timer(0U)
{
}
void CFMTimer::setTimeout(uint16_t timeout)
void CFMTimer::setTimeout(uint16_t secs, uint32_t msecs)
{
m_timeout = timeout;
m_timeout = (secs * 24000U) + (msecs * 24U);
}
uint16_t CFMTimer::getTimeout() const
uint32_t CFMTimer::getTimeout() const
{
return m_timeout;
return m_timeout / 24U;
}
void CFMTimer::start()
{
if (m_timeout > 0U)
m_timer = 1U;
}
void CFMTimer::stop()
{
m_timer = 0U;
}
void CFMTimer::clock()
void CFMTimer::clock(uint8_t length)
{
if (m_timer > 0U && m_timeout > 0U)
m_timer += length;
}
bool CFMTimer::isRunning() const
{
return m_timer > 0U;
}
bool CFMTimer::hasExpired() const
{
if (m_timeout == 0U || m_timer == 0U)
return false;
if (m_timer > m_timeout)
return true;
return false;
}