mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.7 CountDown
This commit is contained in:
parent
3e787c524d
commit
b1199cbeec
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -8,4 +23,6 @@ compile:
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
51
libraries/CountDown/CHANGELOG.md
Normal file
51
libraries/CountDown/CHANGELOG.md
Normal file
@ -0,0 +1,51 @@
|
||||
# Change Log CountDown
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.7] - 2022-10-30
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
- minor edit unit test
|
||||
|
||||
|
||||
## [0.2.6] - 2021-12-14
|
||||
- update library.json, license
|
||||
|
||||
## [0.2.5] - 2021-10-19
|
||||
- update Arduino-CI
|
||||
- add badges
|
||||
|
||||
## [0.2.4] - 2021-01-15
|
||||
- start detect overflow now
|
||||
|
||||
## [0.2.3] - 2020-12-17
|
||||
- add Arduino-CI + unit test
|
||||
|
||||
## [0.2.2] - 2020-07-08
|
||||
- add MINUTES
|
||||
- refactor
|
||||
|
||||
## [0.2.1] - 2020-06-05
|
||||
- fix library.json
|
||||
|
||||
## [0.2.0] - 2020-03-29
|
||||
- add #pragma once
|
||||
- removed pre 1.0 support
|
||||
|
||||
----
|
||||
|
||||
## [0.1.3] - 2017-07-16
|
||||
- TODO improved seconds - OdoMeter see below ... TODO
|
||||
|
||||
## [0.1.2] - 2017-07-16
|
||||
- add start(days, hours, minutes, seconds) + cont() == continue countdown
|
||||
|
||||
## [0.1.1] - 2015-10-29
|
||||
- add start(h, m, s)
|
||||
|
||||
## [0.1.0] - 2015-10-27
|
||||
- initial version
|
@ -1,22 +1,11 @@
|
||||
//
|
||||
// FILE: CountDown.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.6
|
||||
// VERSION: 0.2.7
|
||||
// PURPOSE: CountDown library for Arduino
|
||||
// URL: https://github.com/RobTillaart/CountDown
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2015-10-27 initial version
|
||||
// 0.1.1 2015-10-29 added start(h, m, s)
|
||||
// 0.1.2 2017-07-16 added start(days, hours, minutes, seconds) + cont() == continue countdown
|
||||
// 0.1.3 2017-07-16 TODO improved seconds - OdoMeter see below ... TODO
|
||||
// 0.2.0 2020-03-29 #pragma once, removed pre 1.0 support
|
||||
// 0.2.1 2020-06-05 fix library.json
|
||||
// 0.2.2 2020-07-08 add MINUTES; refactor
|
||||
// 0.2.3 2020-12-17 add Arduino-CI + unit test
|
||||
// 0.2.4 2021-01-15 start detect overflow now.
|
||||
// 0.2.5 2021-10-19 update Arduino-CI + badges
|
||||
// 0.2.6 2021-12-14 update library.json, license
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "CountDown.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: CountDown.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.6
|
||||
// VERSION: 0.2.7
|
||||
// PURPOSE: CountDown library for Arduino
|
||||
// URL: https://github.com/RobTillaart/CountDown
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define COUNTDOWN_LIB_VERSION (F("0.2.6"))
|
||||
#define COUNTDOWN_LIB_VERSION (F("0.2.7"))
|
||||
|
||||
|
||||
class CountDown
|
||||
|
@ -15,25 +15,30 @@ Arduino Library to implement a CountDown clock (in SW polling, no HW timer).
|
||||
|
||||
The countdown library is a clock that counts down from a given time to zero.
|
||||
It does not call a function or so as the user is responsible to check the time remaining.
|
||||
Typically one checks the remaining time in every loop.
|
||||
Typically one checks the remaining time in every **loop()**.
|
||||
|
||||
UNder the hood the function uses **micros()** or **millis()** which results in a maximum time
|
||||
of 4294 seconds in micros (1h10m) or about 49+ days when using milliseconds.
|
||||
Under the hood the function uses **micros()** or **millis()** which results in a maximum time
|
||||
of 4294 seconds in micros (1h 10m) or about 49+ days when using milliseconds.
|
||||
|
||||
For longer periods one could cascade countDown, so when one is finished the next one starts.
|
||||
For longer periods one could cascade countDown objects, so when one is finished the next one starts.
|
||||
|
||||
Note the countdown object is as accurate as the underlying **millis()** or **micros()**.
|
||||
Interrupts etc might cause deviations.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
The main functions of the CountDown clock are:
|
||||
|
||||
- **bool start(uint32_t ticks)**
|
||||
- **bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds)**
|
||||
- **bool start(uint8_t days, uint16_t hours, uint32_t minutes)**
|
||||
- **void stop()**
|
||||
- **void cont()** *(note continue is a C-Keyword)*
|
||||
- **uint32_t remaining()**
|
||||
- **bool isRunning()**
|
||||
- **CountDown(const enum Resolution res = MILLIS)** constructor, with default resolution of milliseconds.
|
||||
- **bool start(uint32_t ticks)** (re)start in current resolution.
|
||||
- **bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds)** Implicit set resolution to SECONDS.
|
||||
- **bool start(uint8_t days, uint16_t hours, uint32_t minutes)** Implicit set resolution to MINUTES.
|
||||
- **void stop()** stop the count-down.
|
||||
- **void cont()** resumes / continue the count-down.
|
||||
*(note continue is a C-Keyword)*
|
||||
- **uint32_t remaining()** returns the remaining ticks in current resolution.
|
||||
- **bool isRunning()** idem.
|
||||
|
||||
These functions work straightforward.
|
||||
|
||||
@ -42,36 +47,42 @@ These functions work straightforward.
|
||||
|
||||
The function **start(days, hours, minutes, seconds)** has changed its
|
||||
parameters type to minimize them, given that the total time may not exceed 2^32 milliseconds.
|
||||
This allows the user to call **start()** with e.g. four hundred minutes **start(0, 0, 400, 0)**
|
||||
or a million seconds **start(0, 0, 0, 1000000)** as parameter.
|
||||
This allows the user to call **start()** with e.g.
|
||||
- four hundred minutes **start(0, 0, 400, 0)**
|
||||
- a million seconds **start(0, 0, 0, 1000000)**
|
||||
- a unusual mix **start(0, 0, 400, 1000)** as parameter.
|
||||
The resolution is implicitly set to **CountDown::SECONDS**.
|
||||
|
||||
Since 0.2.4 the function **start()** will check if the parameters cause an overflow
|
||||
in the underlying math. If there is no overflow call to **start()** returns true.
|
||||
If there is an overflow it returns false.
|
||||
|
||||
Total amount of time to countdown for **CountDown::MICROS** may not exceed 2\^32 micros ~ 1 hour 10 minutes.
|
||||
Total amount of time to countdown for **CountDown::MILLIS**, **CountDown::SECONDS** and **CountDown::MINUTES**
|
||||
may not exceed 2\^32 milliseconds ~49 days.
|
||||
in the underlying math.
|
||||
If there is no overflow, a call to **start()** returns true.
|
||||
If there is an overflow, a call to **start()** returns false.
|
||||
|
||||
Total amount of time to countdown for **CountDown::MICROS** may not exceed 2\^32 micros
|
||||
which equals about 1 hour and 10 minutes.
|
||||
Total amount of time to countdown for **CountDown::MILLIS**, **CountDown::SECONDS**
|
||||
and **CountDown::MINUTES** may not exceed 2\^32 milliseconds, about 49 days.
|
||||
|
||||
The function **start(days, hours, minutes)** is new since 0.2.2.
|
||||
It also uses **millis()** under the hood. The resolution is implicitly set to **CountDown::MINUTES**.
|
||||
It also uses **millis()** under the hood.
|
||||
The resolution is implicitly set to **CountDown::MINUTES**.
|
||||
|
||||
|
||||
| Call to start() | resolution | max time | comments |
|
||||
|:--------------------------------------|:-----------------|:---------:|:---------|
|
||||
| start(days, hours, minutes, seconds) | SECONDS = millis | 49+ days | |
|
||||
| start(days, hours, minutes) | MINUTES = millis | 49+ days | |
|
||||
| start(ticks) | MILLIS = millis | 49+ days | default |
|
||||
| start(ticks) | MICROS = micros | ~70 min | use setResolution(CountDown::MICROS) |
|
||||
| start(ticks) | SECONDS = millis | 49+ days | use setResolution(CountDown::SECONDS) |
|
||||
| start(ticks) | MINUTES = millis | 49+ days | use setResolution(CountDown::MINUTES) |
|
||||
| Call to start() | resolution | max time | comments |
|
||||
|:-------------------------------------|:-----------------|:--------:|:---------|
|
||||
| start(days, hours, minutes, seconds) | SECONDS = millis | 49+ days | |
|
||||
| start(days, hours, minutes) | MINUTES = millis | 49+ days | |
|
||||
| start(ticks) | MILLIS = millis | 49+ days | default |
|
||||
| start(ticks) | MICROS = micros | ~70 min | setResolution(CountDown::MICROS) |
|
||||
| start(ticks) | SECONDS = millis | 49+ days | setResolution(CountDown::SECONDS) |
|
||||
| start(ticks) | MINUTES = millis | 49+ days | setResolution(CountDown::MINUTES) |
|
||||
|
||||
|
||||
The Countdown clock uses by default **millis()** to do the time keeping,
|
||||
although this can be changed runtime by **setResolution(res)**. The parameter
|
||||
**res** can be:
|
||||
although this can be changed runtime by **setResolution(res)**.
|
||||
|
||||
The parameter **res** can be:
|
||||
|
||||
- **CountDown::MICROS** // based upon micros()
|
||||
- **CountDown::MILLIS** // default
|
||||
- **CountDown::SECONDS** // based upon millis()
|
||||
@ -80,18 +91,34 @@ although this can be changed runtime by **setResolution(res)**. The parameter
|
||||
Although possible one should not change the resolution of the CountDown
|
||||
clock while it is running as you mix up different timescales.
|
||||
|
||||
One can call **start(...)** at any time to reset the running clock to
|
||||
a new value. This allows to implement a sort of watchdog clock in which e.g.
|
||||
the user must press a button at least once per minute to show he is still
|
||||
awake.
|
||||
|
||||
#### Watchdog
|
||||
|
||||
One can call **start(...)** at any time to reset the running clock to a new value.
|
||||
This allows to implement a sort of watchdog clock in which e.g.
|
||||
the user must press a button at least once per minute to show he is still awake.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- incorporate a real time clock? or EEPROM to be reboot proof?
|
||||
- examples with visualisations (e.g. hexadecimal countdown)
|
||||
- Countdown based upon external pulses.
|
||||
#### must
|
||||
- documentation
|
||||
|
||||
#### should
|
||||
|
||||
|
||||
#### could
|
||||
- incorporate a real time clock
|
||||
- or EEPROM to be reboot proof?
|
||||
- examples
|
||||
- visualisations - hexadecimal - alphabetical (radix 26)
|
||||
- depends on sensor
|
||||
- uint64_t version ==> **CountDown64** class? (only on request)
|
||||
- would be useful for micros() in theory but drift / interrupts would make it fail.
|
||||
-
|
||||
- countdown with a big number e.g. billions/ second ==> national deficit coounter.
|
||||
|
||||
#### wont
|
||||
- Countdown based upon external pulses.
|
||||
- pulse counter
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/CountDown.git"
|
||||
},
|
||||
"version": "0.2.6",
|
||||
"version": "0.2.7",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=CountDown
|
||||
version=0.2.6
|
||||
version=0.2.7
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to implement a CountDown clock in SW.
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", (char *) COUNTDOWN_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
@ -42,8 +43,6 @@ unittest_teardown()
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", (char *) COUNTDOWN_LIB_VERSION);
|
||||
|
||||
CountDown a(CountDown::MINUTES);
|
||||
CountDown b(CountDown::SECONDS);
|
||||
CountDown c(CountDown::MILLIS);
|
||||
|
Loading…
Reference in New Issue
Block a user