Skip to content

Commit

Permalink
Merge pull request #4 from RobTillaart/main
Browse files Browse the repository at this point in the history
Add Arduino build-CI + badges in readme.md
  • Loading branch information
ripred committed Jun 28, 2023
2 parents 88537c8 + 43440a1 commit 935ced2
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico
13 changes: 13 additions & 0 deletions .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

name: Arduino-lint

on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict
17 changes: 17 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
runTest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
18 changes: 18 additions & 0 deletions .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: JSON check

on:
push:
paths:
- '**.json'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [1.6.1] - 2023-06-28
- add Arduino build-CI
- add unit test
- add LINT
- add badges to readme.md


## [1.6.0] - 2023-06-20
- add changelog.md
- improved performance **add()**
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

[![Arduino CI](https://github.com/ripred/Smooth/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/ripred/Smooth/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/ripred/Smooth/actions/workflows/arduino-lint.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ripred/Smooth/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/ripred/Smooth.svg?maxAge=3600)](https://github.com/ripred/Smooth/releases)


# Smooth Arduino Library

Keep smooth running averages without using arrays! No arrays. No Looping. Fast and Constant Time regardless of the sample window size!

Keep smooth running averages without using arrays! No arrays. No Looping. Fast and Constant Time regardless of the sample window size!

The sample size is adjustable at runtime. The average is available and accurate even before N samples have been received. The `Smooth` object uses 8 bytes of memory. That's it. No matter how large the window size. Perfect for smoothing and filtering signals from noisy devices **like accelerometers**!

update: added support for change, upper and lower bounds callbacks!
Expand Down Expand Up @@ -87,3 +96,4 @@ count: 37, sample: 3, average: 2
count: 38, sample: 3, average: 2
count: 39, sample: 2, average: 2
```
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Smooth
version=1.6.0
version=1.6.1
author=Trent M. Wyatt
maintainer=Trent M. Wyatt <robotics@trentwyatt.com>
sentence=Keep smooth running averages without using arrays! The sample size is adjustable at runtime.
Expand Down
2 changes: 1 addition & 1 deletion src/Smooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ double Smooth::add(double const val)
// num will change when num > set_size AND set_size has changed. (due to num = set_size)
if (prev_num != num)
{
// only one coef needed.
// only one coefficient needed.
val_coef = 1.0 / double(num);
// multiply is faster than divide, so reuse math
// run_coef = double(num - 1) * val_coef;
Expand Down
2 changes: 1 addition & 1 deletion src/Smooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* header file for Smooth averaging class
*
* version 1.6 - June, 2023 ++trent m. wyatt
* version 1.6.1 - June, 2023 ++trent m. wyatt
*
*/
#ifndef SMOOTH_H_INCL
Expand Down
124 changes: 124 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2023-06-28
// PURPOSE: unit tests for Smooth library
// https://github.com/RobTillaart/SIMON
//


// 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 "Smooth.h"


unittest_setup()
{
fprintf(stderr, "Arduino Smooth library\n");
}


unittest_teardown()
{
}


unittest(test_constructor)
{
Smooth sm(42);
assertEqual(42, sm.get_window());
assertEqual(0, sm.get_count());
assertEqualFloat(0, sm.get_avg(), 0.0001);

Smooth sm0(5, 0, 0);
assertEqual(5, sm0.get_window());
assertEqual(0, sm0.get_count());
assertEqualFloat(0, sm0.get_avg(), 0.0001);

Smooth sm1(7, 20);
assertEqual(7, sm1.get_window());
assertEqual(20, sm1.get_count());
assertEqualFloat(0, sm0.get_avg(), 0.0001);

Smooth sm2(15, 25, 10);
assertEqual(15, sm2.get_window());
assertEqual(25, sm2.get_count());
assertEqualFloat(10, sm2.get_avg(), 0.0001);
}


unittest(test_reset)
{
Smooth sm2(15, 25, 10);
assertEqual(15, sm2.get_window());
assertEqual(25, sm2.get_count());
assertEqualFloat(10, sm2.get_avg(), 0.0001);

sm2.reset(10);
assertEqual(10, sm2.get_window());
assertEqual(0, sm2.get_count());
assertEqualFloat(0, sm2.get_avg(), 0.0001);

sm2.reset(5, 4);
assertEqual(5, sm2.get_window());
assertEqual(4, sm2.get_count());
assertEqualFloat(0, sm2.get_avg(), 0.0001);

sm2.reset(5, 4356, -17.68);
assertEqual(5, sm2.get_window());
assertEqual(4356, sm2.get_count());
assertEqualFloat(-17.68, sm2.get_avg(), 0.0001);
}


unittest(test_avg)
{
Smooth sm(5, 0, 0);

assertEqual(5, sm.get_window());
assertEqual(0, sm.get_count());
assertEqualFloat(0, sm.get_avg(), 0.0001);

sm.add(10);
assertEqual(1, sm.get_count());
assertEqualFloat(10, sm.get_avg(), 0.0001);
assertEqualFloat(10, sm(), 0.0001);

sm.add(5);
assertEqual(2, sm.get_count());
assertEqualFloat(7.5, sm.get_avg(), 0.0001);
assertEqualFloat(7.5, sm(), 0.0001);
}




unittest_main()


// -- END OF FILE --

0 comments on commit 935ced2

Please sign in to comment.