2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2015-10-29 09:28:29 -04:00
|
|
|
//
|
|
|
|
// FILE: CountDown.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-11 05:04:32 -05:00
|
|
|
// VERSION: 0.3.0
|
2015-10-29 09:28:29 -04:00
|
|
|
// PURPOSE: CountDown library for Arduino
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/CountDown
|
2015-10-29 09:28:29 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-10-29 09:28:29 -04:00
|
|
|
#include "Arduino.h"
|
2020-11-27 05:10:47 -05:00
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
#define COUNTDOWN_LIB_VERSION (F("0.3.0"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-10-29 09:28:29 -04:00
|
|
|
|
|
|
|
class CountDown
|
|
|
|
{
|
|
|
|
public:
|
2023-01-11 05:04:32 -05:00
|
|
|
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
|
2015-10-29 09:28:29 -04:00
|
|
|
|
|
|
|
explicit CountDown(const enum Resolution res = MILLIS);
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void setResolution(const enum Resolution res = MILLIS);
|
2023-01-11 05:04:32 -05:00
|
|
|
enum Resolution resolution() { return _res; };
|
|
|
|
char getUnits();
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
// one need to set the resolution before calling start(ticks).
|
2021-01-29 06:31:58 -05:00
|
|
|
bool start(uint32_t ticks);
|
2023-01-11 05:04:32 -05:00
|
|
|
// Implicit set resolution to SECONDS.
|
2021-01-29 06:31:58 -05:00
|
|
|
bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds);
|
2023-01-11 05:04:32 -05:00
|
|
|
// Implicit set resolution to MINUTES.
|
2021-01-29 06:31:58 -05:00
|
|
|
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
|
|
|
|
|
|
|
|
void stop();
|
|
|
|
void cont();
|
2017-07-16 05:46:43 -04:00
|
|
|
|
|
|
|
uint32_t remaining();
|
2021-01-29 06:31:58 -05:00
|
|
|
bool isRunning();
|
2023-01-11 05:04:32 -05:00
|
|
|
bool isStopped();
|
|
|
|
|
2015-10-29 09:28:29 -04:00
|
|
|
|
|
|
|
private:
|
2017-07-16 05:46:43 -04:00
|
|
|
enum State { RUNNING, STOPPED };
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
uint32_t _ticks;
|
|
|
|
uint32_t _remaining;
|
|
|
|
enum State _state;
|
2015-10-29 09:28:29 -04:00
|
|
|
enum Resolution _res;
|
2023-01-11 05:04:32 -05:00
|
|
|
uint32_t _startTime;
|
2020-11-27 05:10:47 -05:00
|
|
|
void calcRemaining();
|
2015-10-29 09:28:29 -04:00
|
|
|
};
|
|
|
|
|
2021-10-19 15:40:11 -04:00
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
// -- END OF FILE --
|
|
|
|
|