diff --git a/.arduino-ci.yml b/.arduino-ci.yml index 82a8e04..b3e33db 100644 --- a/.arduino-ci.yml +++ b/.arduino-ci.yml @@ -2,9 +2,13 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - due - zero + - leonardo + - m4 + - esp32 + - esp8266 + - mega2560 libraries: - "printHelpers" - + diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml index 476456b..096b975 100644 --- a/.github/workflows/arduino_test_runner.yml +++ b/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/README.md b/README.md index 3373385..2f77ac6 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ [![Arduino CI](https://github.com/RobTillaart/timing/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/timing/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/timing.svg?maxAge=3600)](https://github.com/RobTillaart/timing/releases) + # Timing -Arduino library with wrappers for seconds millis micros +Arduino library with wrappers for seconds millis micros. ## Description @@ -16,54 +19,54 @@ This library provide wrapper classes around **millis()** and **micros()** with the extra function to do this. To implement this only a 4 byte offset is needed. +The classes are based upon **millis()** and **micros()**. +Therefore they have the same restrictions as these functions with respect to +overflow and accuracy. Depending on e.g. interrupts millis and micros can drift. + + +| class | overflow after | Notes | +|:-------------|:-------------------------|:--------------------| +| seconds | 49 days, 17:02:47 | based upon millis() | +| milliSeconds | 49 days, 17:02:47.297 | +| microSeconds | 00 days 01:11:34.967296 | + + +## Applications + These classes make it easy to make a simple stopwatch. +Or sync the time with an external source. ## Interface -The library has 3 classes that are very similar. -- microSeconds -- milliSeconds -- seconds (wrapper around millis() too) - -The interface of all three are very similar, so only one is described +The interface of all three are very similar: +- **microSeconds()** constructor, sets the offset so it starts at 0. - **milliSeconds()** constructor, sets the offset so it starts at 0. -- **now()** returs the time elapsed since its 'zero moment', either construction -or by a set(0). -- **set(value)** sets the offset of the object. As it is possible to set it -to a non zero value it is easy to adjust the time. +- **seconds()** constructor, sets the offset so it starts at 0. +- **uint32_t now()** returns the time elapsed since its 'zero moment'. +Ether set during construction or by a call to **set(0)**. +- **void set(uint32_t value = 0UL)** sets the offset of the object. +As it is possible to set it to a non zero value it is easy to adjust the time. +This allows one e.g. to compensate for overhead. Default = zero. - **uint32_t getOffset()** returns current offset. -The classes are based upon **millis()** and **micros()** therefor have the same -restrictions as these functions with respect to overflow and accuracy. -Depending on e.g. interrupts millis and micros can drift. -| class | overflow after | -|:----|:----|:----:| -|seconds | 49 days, 17:02:47.297 | -| milliSeconds | 49 days, 17:02:47.297 | -| microSeconds | 00 days 01:11:34.967296 | +## Operation +See examples. -## Future -idea to give it a clock print layout +## Future +- test on ESP32 +- nanos() on ESP32 ? +- implement printable interface (add unit) +- idea to give it a clock print layout - seconds.toClock() -> DD 12:34:56 -- milliSeconds.toClock(3) -> 12:23:45.123 +- milliSeconds.toClock(3) -> 12:23:45.123 (3) == 3 decimals.. - milliSeconds.toClock(1) -> 12:23:45.1 - microSeconds.toCLock() -> 12:23:45.123456 ??? - +- update documentation - rounding effect, describe - -## Operation - -See examples - - -## Todo - -- test on ESP32 - diff --git a/examples/microSeconds/microSeconds.ino b/examples/microSeconds/microSeconds.ino index 32fb7e7..28e6707 100644 --- a/examples/microSeconds/microSeconds.ino +++ b/examples/microSeconds/microSeconds.ino @@ -59,3 +59,4 @@ uint64_t fibonaci(uint32_t n) // -- END OF FILE -- + diff --git a/examples/seconds/seconds.ino b/examples/seconds/seconds.ino index dcad9df..a665c92 100644 --- a/examples/seconds/seconds.ino +++ b/examples/seconds/seconds.ino @@ -22,7 +22,7 @@ const uint32_t mx = 15000; uint16_t primes[MAXPRIMES]; uint16_t idx = 0; -uint32_t x = 1; +uint32_t x = 1; void setup() @@ -84,3 +84,4 @@ int nextPrime() // -- END OF FILE -- + diff --git a/keywords.txt b/keywords.txt index c12cca7..081dea8 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,13 +1,16 @@ -# Syntax Coloring Map for timing +# Syntax Colouring Map for timing -# Datatypes (KEYWORD1) + +# Data types (KEYWORD1) microSeconds KEYWORD1 milliSeconds KEYWORD1 seconds KEYWORD1 + # Methods and Functions (KEYWORD2) now KEYWORD2 set KEYWORD2 -# Constants (LITERAL1) +# Constants (LITERAL1) +TIMING_LIB_VERSION LITERAL1 diff --git a/library.json b/library.json index 9e893f1..4dce1e0 100644 --- a/library.json +++ b/library.json @@ -18,5 +18,6 @@ "version": "0.2.2", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "timing.h" } diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index c3af44a..48d0594 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -29,6 +29,7 @@ // assertNAN(arg); // isnan(a) // assertNotNAN(arg); // !isnan(a) + #include #include "Arduino.h" @@ -46,7 +47,7 @@ unittest_teardown() unittest(test_constructor) { - fprintf(stderr, "VERSION: %s\n", TIMING_LIB_VERSION); + fprintf(stderr, "VERSION: %s\n", (char *) TIMING_LIB_VERSION); microSeconds mic; assertEqual(0, mic.getOffset()); diff --git a/timing.h b/timing.h index bb00a7c..ec11b3d 100644 --- a/timing.h +++ b/timing.h @@ -12,7 +12,8 @@ // 0.1.02 2015-03-02 move all to mymillis.h file so compiler can optimize // 0.2.0 2020-07-07 renamed to timing.h // 0.2.1 2021-01-09 added Arduino-CI + unit test -// 0.2.1 2021-05-27 added Arduino-lint +// 0.2.2 2021-05-27 added Arduino-lint +// #define TIMING_LIB_VERSION (F("0.2.2")) @@ -23,7 +24,7 @@ class microSeconds public: microSeconds() { set(0); } uint32_t now() { return micros() - _offset; } - void set(uint32_t val = 0UL) { _offset = micros() - val; } + void set(uint32_t value = 0UL) { _offset = micros() - value; } uint32_t getOffset() { return _offset; }; private: @@ -36,7 +37,7 @@ class milliSeconds public: milliSeconds() { set(0); }; uint32_t now() { return millis() - _offset; }; - void set(uint32_t val = 0UL) { _offset = millis() - val; }; + void set(uint32_t value = 0UL) { _offset = millis() - value; }; uint32_t getOffset() { return _offset; }; private: @@ -49,7 +50,7 @@ class seconds public: seconds() { set(0); } uint32_t now() { return millis()/1000UL - _offset; } - void set(uint32_t val = 0UL) { _offset = millis()/1000UL - val; } + void set(uint32_t value = 0UL) { _offset = millis()/1000UL - value; } uint32_t getOffset() { return _offset; }; private: @@ -58,3 +59,4 @@ class seconds // -- END OF FILE -- +