Skip to content

Commit

Permalink
Arduino ci (#1)
Browse files Browse the repository at this point in the history
* add Arduino-CI
* add unit tests
  • Loading branch information
RobTillaart committed Jan 11, 2021
1 parent 3939ed7 commit bbd6200
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
libraries:
- "printHelpers"
13 changes: 13 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
arduino_ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2011-2020 Rob Tillaart
Copyright (c) 2011-2021 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# timing

[![Arduino CI](https://github.com/RobTillaart/timing/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![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


## Description

A request often made on the Arduino forum and otherwise is an option to reset
Expand All @@ -12,6 +18,7 @@ To implement this only a 4 byte offset is needed.

These classes make it easy to make a simple stopwatch.


## Interface

The library has 3 classes that are very similar.
Expand All @@ -26,6 +33,7 @@ The interface of all three are very similar, so only one is described
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.
- **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.
Expand All @@ -37,10 +45,25 @@ Depending on e.g. interrupts millis and micros can drift.
| milliSeconds | 49 days, 17:02:47.297 |
| microSeconds | 00 days 01:11:34.967296 |


## Future

idea to give it a clock print layout

- seconds.toClock() -> DD 12:34:56
- milliSeconds.toClock(3) -> 12:23:45.123
- milliSeconds.toClock(1) -> 12:23:45.1
- microSeconds.toCLock() -> 12:23:45.123456 ???

- rounding effect, describe


## Operation

See examples


## Todo

- test on ESP32

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/timing"
},
"version":"0.2.0",
"version":"0.2.1",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=timing
version=0.2.0
version=0.2.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library with wrapper classes for seconds millis micros.
Expand Down
74 changes: 74 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-01-09
// PURPOSE: unit tests for the timing libraty
// https://github.com/RobTillaart/timing
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//

// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);

// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)

#include <ArduinoUnitTests.h>

#include "Arduino.h"
#include "timing.h"


unittest_setup()
{
}

unittest_teardown()
{
}


unittest(test_constructor)
{
fprintf(stderr, "VERSION: %s\n", TIMING_LIB_VERSION);

microSeconds mic;
assertEqual(0, mic.getOffset());
mic.set(100);
assertEqual(4294967196, mic.getOffset()); // max uint32_t - 100

milliSeconds mil;
assertEqual(0, mil.getOffset());
mil.set(100);
assertEqual(4294967196, mil.getOffset());

seconds sec;
assertEqual(0, sec.getOffset());
sec.set(100);
assertEqual(4294967196, sec.getOffset());

fprintf(stderr, "%d\n", mic.now());
fprintf(stderr, "%d\n", mil.now());
fprintf(stderr, "%d\n", sec.now());

}

unittest_main()

// --------
20 changes: 10 additions & 10 deletions timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
// PURPOSE: Arduino library with wrapper classes for seconds millis micros
// URL: https://github.com/RobTillaart/timing
//
// HISTORY:
// 0.1.00 - 2011-01-04 initial version
// 0.1.01 - 2011-07-19 lib version
// 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
// HISTORY:
// 0.1.00 2011-01-04 initial version
// 0.1.01 2011-07-19 lib version
// 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

// IDEAS
// char * toClock();
// seconds.toClock() -> DD 12:34:56
// milliSeconds.toClock() -> 12:23:45.123
// microSeconds.toCLock() -> ???

#define TIMING_LIB_VERSION (F("0.2.1"))

class microSeconds
{
public:
microSeconds() { set(0); }
uint32_t now() { return micros() - _offset; }
void set(uint32_t val = 0UL) { _offset = micros() - val; }
uint32_t getOffset() { return _offset; };

private:
uint32_t _offset = 0UL;
Expand All @@ -37,6 +35,7 @@ class milliSeconds
milliSeconds() { set(0); };
uint32_t now() { return millis() - _offset; };
void set(uint32_t val = 0UL) { _offset = millis() - val; };
uint32_t getOffset() { return _offset; };

private:
uint32_t _offset = 0UL;
Expand All @@ -49,6 +48,7 @@ class seconds
seconds() { set(0); }
uint32_t now() { return millis()/1000UL - _offset; }
void set(uint32_t val = 0UL) { _offset = millis()/1000UL - val; }
uint32_t getOffset() { return _offset; };

private:
uint32_t _offset = 0UL;
Expand Down

0 comments on commit bbd6200

Please sign in to comment.