0.1.0 MINMAX

This commit is contained in:
rob tillaart 2021-10-14 14:54:11 +02:00
parent afcf767988
commit 5ad7d7b253
14 changed files with 499 additions and 0 deletions

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

21
libraries/MINMAX/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021-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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

76
libraries/MINMAX/MINMAX.h Normal file
View File

@ -0,0 +1,76 @@
#pragma once
//
// FILE: MINMAX.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2021-10-14
// PURPOSE: MINMAX library - simple peak finder
//
// HISTORY:
// 0.1.0 2021-10-14 initial version
#include "Arduino.h"
#define MINMAX_LIB_VERSION (F("0.1.0"))
class MINMAX
{
public:
MINMAX()
{
reset();
_resetCount = 0;
}
uint8_t add(float f)
{
uint8_t rv = 0;
if ((_resetCount != 0) && (_resetCount == _count))
{
reset();
rv |= 0x80;
}
if ((f < _minimum) || (_count == 0))
{
_minimum = f;
rv |= 0x01;
}
if ((f > _maximum) || (_count == 0))
{
_maximum = f;
rv |= 0x02;
}
_count++;
return rv;
}
void reset()
{
_minimum = 0;
_maximum = 0;
_count = 0;
}
void autoReset(uint32_t cnt) { _resetCount = cnt; };
float minimum() { return _minimum; };
float maximum() { return _maximum; };
uint32_t count() { return _count; };
private:
float _minimum;
float _maximum;
uint32_t _count;
uint32_t _resetCount;
};
// -- END OF FILE --

View File

@ -0,0 +1,61 @@
[![Arduino CI](https://github.com/RobTillaart/MINMAX/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/MINMAX/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MINMAX/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/MINMAX/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MINMAX/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MINMAX/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MINMAX.svg?maxAge=3600)](https://github.com/RobTillaart/MINMAX/releases)
# MINMAX
Library for finding peaks (minimum and maximum) in signal.
## Description
The MINMAX library is a simple peak finder in a stream of floats.
It indicates if after adding a number the minimum and/or the maximum value has been changed by means of a bit flag that is returned. If a peak is found, it will be used as the new reference untila a reset.
The library can reset the minimum and maximum to 0 to start again.
The library has also the option to auto-reset after a predefined number of **add()** calls.
## Interface
- **MINMAX** Constructor
- **uint8_t add(float f)** add next value. Returns status (bit flags), see table below.
- **void reset()** resets the minimum and maximum to 0.
- **void autoReset(uint32_t cnt)** sets an auto-reset moment after cnt calls to **add()**.
There will be at least one value processed.
- **float minimum()** returns last minimum. Can be higher than previous call due to **reset()** or **autoReset()**.
If no call to **add()** is made it will return 0.
- **float maximum()** returns last maximum. Can be lower than previous call due to **reset()** or **autoReset()**.
If no call to **add()** is made it will return 0.
- **uint32_t count()** returns nr of **add()** calls since last (auto)reset.
Return values of **add()**
| flag | description |
|:----:|:----------------|
| 0x00 | no change |
| 0x01 | minimum changed |
| 0x02 | maximum changed |
| 0x80 | reset done |
## Operation
The examples show the basic working of the functions.
## Future
- update documentation
- define FLAGS
- add call back functions?
- thresholds, windowing + triggers (separate class?)
- auto-reset after time? (would affect all functions)
-

View File

@ -0,0 +1,45 @@
//
// FILE: minmax_autoreset.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-10-14
// URL: https://github.com/RobTillaart/minmax
#include "MINMAX.h"
MINMAX mm;
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
mm.autoReset(10000);
}
void loop()
{
int r = random(10001) - 5000;
mm.add(r);
if (mm.count() % 1000 == 0)
{
Serial.print(mm.count());
Serial.print("\t");
Serial.print(mm.minimum());
Serial.print("\t");
Serial.print(mm.maximum());
Serial.print("\n");
}
}
// -- END OF FILE --

View File

@ -0,0 +1,46 @@
//
// FILE: minmax_demot.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-10-14
// URL: https://github.com/RobTillaart/minmax
#include "MINMAX.h"
MINMAX mm;
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
mm.reset();
}
void loop()
{
int r = random(1000) - 500;
mm.add(r);
if (mm.count() % 100 == 0)
{
Serial.print(mm.count());
Serial.print("\t");
Serial.print(mm.minimum());
Serial.print("\t");
Serial.print(mm.maximum());
Serial.print("\n");
mm.reset();
}
}
// -- END OF FILE --

View File

@ -0,0 +1,43 @@
//
// FILE: minmax_new.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-10-14
// URL: https://github.com/RobTillaart/minmax
#include "MINMAX.h"
MINMAX mm;
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
mm.autoReset(10000);
}
void loop()
{
int r = random(10001) - 5000;
if (mm.add(r) != 0x00) // changed minimum or maximum or reset
{
Serial.print(mm.count());
Serial.print("\t");
Serial.print(mm.minimum());
Serial.print("\t");
Serial.print(mm.maximum());
Serial.print("\n");
}
}
// -- END OF FILE --

View File

@ -0,0 +1,18 @@
# Syntax Colouring Map For MINMAX
# Data types (KEYWORD1)
MINMAX KEYWORD1
# Methods and Functions (KEYWORD2)
add KEYWORD2
reset KEYWORD2
autoreset KEYWORD2
minimum KEYWORD2
maximum KEYWORD2
count KEYWORD2
# Constants (LITERAL1)
MINMAX_LIB_VERSION LITERAL1

View File

@ -0,0 +1,22 @@
{
"name": "MINMAX",
"keywords": "minimum, maximum, autoreset",
"description": "MINMAX library for Arduino. Simple peak finder ( minimum and maximum) in signal.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/MINMAX.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
}

View File

@ -0,0 +1,11 @@
name=MINMAX
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=MINMAX library for Arduino.
paragraph=simple peak finder ( minimum and maximum) in signal.
category=Signal Input/Output
url=https://github.com/RobTillaart/MINMAX
architectures=*
includes=MINMAX.h
depends=

View File

@ -0,0 +1,97 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-10-14
// PURPOSE: unit tests for the MINMAX library
// https://github.com/RobTillaart/MINMAX
//
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "MINMAX.h"
#define A0 0
unittest_setup()
{
}
unittest_teardown()
{
}
unittest(test_add)
{
fprintf(stderr, "MINMAX_LIB_VERSION: %s\n", (char *) MINMAX_LIB_VERSION);
MINMAX mm;
for (int i = 0; i < 1000; i++)
{
mm.add(i);
}
assertEqual(0, mm.minimum());
assertEqual(999, mm.maximum());
assertEqual(1000, mm.count());
}
unittest(test_reset)
{
fprintf(stderr, "MINMAX_LIB_VERSION: %s\n", (char *) MINMAX_LIB_VERSION);
MINMAX mm;
for (int i = 0; i < 10; i++)
{
mm.add(i);
}
mm.reset();
assertEqual(0, mm.minimum());
assertEqual(0, mm.maximum());
assertEqual(0, mm.count());
}
unittest(test_autoReset)
{
fprintf(stderr, "MINMAX_LIB_VERSION: %s\n", (char *) MINMAX_LIB_VERSION);
MINMAX mm;
mm.autoReset(10);
for (int i = 0; i < 15; i++)
{
mm.add(i);
}
assertEqual(10, mm.minimum());
assertEqual(14, mm.maximum());
assertEqual(5, mm.count());
}
unittest_main()
// -- END OF FILE --