Skip to content

Commit

Permalink
update build-CI, readme.md, badges (#2)
Browse files Browse the repository at this point in the history
* update build-CI, readme.md, badges
  • Loading branch information
RobTillaart authored Nov 19, 2021
1 parent 12c20a7 commit aaf5a70
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 48 deletions.
8 changes: 6 additions & 2 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

10 changes: 7 additions & 3 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 36 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

1 change: 1 addition & 0 deletions examples/microSeconds/microSeconds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ uint64_t fibonaci(uint32_t n)


// -- END OF FILE --

3 changes: 2 additions & 1 deletion examples/seconds/seconds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -84,3 +84,4 @@ int nextPrime()


// -- END OF FILE --

9 changes: 6 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"version": "0.2.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "timing.h"
}
3 changes: 2 additions & 1 deletion test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)


#include <ArduinoUnitTests.h>

#include "Arduino.h"
Expand All @@ -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());
Expand Down
10 changes: 6 additions & 4 deletions timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -58,3 +59,4 @@ class seconds


// -- END OF FILE --

0 comments on commit aaf5a70

Please sign in to comment.