MMDVM/FMTimer.cpp

71 lines
1.5 KiB
C++
Raw Normal View History

2020-04-15 16:24:01 +02:00
/*
2020-04-15 18:18:01 +02:00
* Copyright (C) 2009,2010,2015,2020 by Jonathan Naylor G4KLX
2020-04-15 16:24:01 +02:00
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Config.h"
#include "Globals.h"
#include "FMTimer.h"
2020-04-15 17:31:49 +02:00
CFMTimer::CFMTimer() :
2020-04-15 18:18:01 +02:00
m_timeout(0U),
m_timer(0U)
2020-04-15 16:24:01 +02:00
{
}
2020-04-15 18:18:01 +02:00
void CFMTimer::setTimeout(uint16_t secs, uint32_t msecs)
2020-04-15 16:24:01 +02:00
{
2020-04-15 18:18:01 +02:00
m_timeout = (secs * 24000U) + (msecs * 24U);
2020-04-15 17:31:49 +02:00
}
2020-04-15 18:18:01 +02:00
uint32_t CFMTimer::getTimeout() const
2020-04-15 17:31:49 +02:00
{
2020-04-15 18:18:01 +02:00
return m_timeout / 24U;
2020-04-15 16:24:01 +02:00
}
void CFMTimer::start()
{
2020-04-15 18:18:01 +02:00
if (m_timeout > 0U)
m_timer = 1U;
2020-04-15 16:24:01 +02:00
}
void CFMTimer::stop()
{
2020-04-15 18:18:01 +02:00
m_timer = 0U;
2020-04-15 16:24:01 +02:00
}
2020-04-15 18:18:01 +02:00
void CFMTimer::clock(uint8_t length)
2020-04-15 16:24:01 +02:00
{
2020-04-15 18:18:01 +02:00
if (m_timer > 0U && m_timeout > 0U)
m_timer += length;
2020-04-15 16:24:01 +02:00
}
bool CFMTimer::isRunning() const
{
2020-04-15 18:18:01 +02:00
return m_timer > 0U;
2020-04-15 16:24:01 +02:00
}
bool CFMTimer::hasExpired() const
{
2020-04-15 18:18:01 +02:00
if (m_timeout == 0U || m_timer == 0U)
return false;
if (m_timer > m_timeout)
return true;
return false;
2020-04-15 16:24:01 +02:00
}