mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.3 MINMAX
This commit is contained in:
parent
5c081a6e56
commit
88a726341f
@ -1,3 +1,18 @@
|
||||
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:
|
||||
@ -8,4 +23,5 @@ compile:
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
32
libraries/MINMAX/CHANGELOG.md
Normal file
32
libraries/MINMAX/CHANGELOG.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Change Log MINMAX
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.3] - 2022-11-17
|
||||
- add RP2040 in build-CI
|
||||
- add changelog.md
|
||||
- edit readme.md
|
||||
- add callback()
|
||||
- add lastValue()
|
||||
- add lastMin() && lastMax() - timestamps of the peaks
|
||||
- add example callback()
|
||||
|
||||
|
||||
## [0.1.2] - 2021-12-21
|
||||
- update library.json
|
||||
- update license
|
||||
- minor edits
|
||||
- defined constants
|
||||
|
||||
## [0.1.1] - 2021-11-09
|
||||
- update readme, parameters
|
||||
- add getAutoResetCount()
|
||||
- rename setAutoResetCount()
|
||||
|
||||
## [0.1.0] - 2021-10-14
|
||||
- initial version.
|
||||
|
@ -2,22 +2,15 @@
|
||||
//
|
||||
// FILE: MINMAX.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// DATE: 2021-10-14
|
||||
// PURPOSE: MINMAX library - simple peak finder
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-10-14 initial version
|
||||
// 0.1.1 2021-11-09 update readme, parameters
|
||||
// add getAutoResetCount()
|
||||
// rename setAutoResetCount()
|
||||
// 0.1.2 2021-12-21 update library.json, license, minor edits
|
||||
// defined constants
|
||||
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define MINMAX_LIB_VERSION (F("0.1.2"))
|
||||
#define MINMAX_LIB_VERSION (F("0.1.3"))
|
||||
|
||||
#define MINMAX_NO_CHANGE 0X00
|
||||
#define MINMAX_MIN_CHANGED 0X01
|
||||
@ -33,12 +26,14 @@ public:
|
||||
{
|
||||
reset();
|
||||
_resetCount = 0;
|
||||
_callback = NULL;
|
||||
}
|
||||
|
||||
|
||||
uint8_t add(const float value)
|
||||
{
|
||||
uint8_t rv = MINMAX_NO_CHANGE;
|
||||
_lastValue = value;
|
||||
if ((_resetCount != 0) && (_resetCount == _count))
|
||||
{
|
||||
reset();
|
||||
@ -47,29 +42,41 @@ public:
|
||||
if ((value < _minimum) || (_count == 0))
|
||||
{
|
||||
_minimum = value;
|
||||
_lastMin = millis();
|
||||
rv |= MINMAX_MIN_CHANGED;
|
||||
}
|
||||
if ((value > _maximum) || (_count == 0))
|
||||
{
|
||||
_maximum = value;
|
||||
_lastMax = millis();
|
||||
rv |= MINMAX_MAX_CHANGED;
|
||||
}
|
||||
_count++;
|
||||
if ((rv != MINMAX_NO_CHANGE) && (_callback != NULL)) _callback();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void reset()
|
||||
{
|
||||
_lastValue = 0;
|
||||
_minimum = 0;
|
||||
_maximum = 0;
|
||||
_count = 0;
|
||||
_lastMin = 0;
|
||||
_lastMax = 0;
|
||||
}
|
||||
|
||||
|
||||
void autoReset(uint32_t count) // obsolete 0.2.0
|
||||
void addCallBack( void (* func)(void) )
|
||||
{
|
||||
_resetCount = count;
|
||||
_callback = func;
|
||||
};
|
||||
|
||||
|
||||
void autoReset(uint32_t count) // obsolete 0.2.0
|
||||
{
|
||||
setAutoResetCount(count);
|
||||
};
|
||||
|
||||
|
||||
@ -85,16 +92,24 @@ public:
|
||||
};
|
||||
|
||||
|
||||
float lastValue() { return _lastValue; };
|
||||
float minimum() { return _minimum; };
|
||||
float maximum() { return _maximum; };
|
||||
uint32_t count() { return _count; };
|
||||
uint32_t lastMin() { return _lastMin; };
|
||||
uint32_t lastMax() { return _lastMax; };
|
||||
|
||||
|
||||
private:
|
||||
float _lastValue;
|
||||
float _minimum;
|
||||
float _maximum;
|
||||
uint32_t _count;
|
||||
uint32_t _resetCount;
|
||||
void (* _callback)(void);
|
||||
|
||||
uint32_t _lastMin;
|
||||
uint32_t _lastMax;
|
||||
|
||||
};
|
||||
|
||||
|
@ -8,47 +8,51 @@
|
||||
|
||||
# MINMAX
|
||||
|
||||
Library for finding peaks (minimum and maximum) in signal.
|
||||
Library for finding peaks (minimum and maximum) in a 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
|
||||
The **add()** function indicates after adding a number if 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 until a reset.
|
||||
If a peak is found, it will be used as the new reference until a call to **reset()**.
|
||||
|
||||
|
||||
The library can reset the minimum and maximum to 0 to start again.
|
||||
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.
|
||||
|
||||
lastMin() timestamp in millis() when minimum was last updated.
|
||||
lastMax() timestamp in millis() when maximum was last updated.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
- **MINMAX** Constructor
|
||||
- **MINMAX** Constructor,
|
||||
- **uint8_t add(float value)** add next value. Returns status (bit flags), see table below.
|
||||
- **void reset()** resets the minimum and maximum to 0.
|
||||
- **void setAutoResetCount(uint32_t count)** sets an auto-reset moment after count calls to **add()**.
|
||||
There will be at least one value processed.
|
||||
- **uint32_t getAutoResetCount()** returns set value.
|
||||
- **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.
|
||||
If no call to **add()** is made yet 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.
|
||||
If no call to **add()** is made yet it will return 0.
|
||||
- **uint32_t count()** returns number of **add()** calls since last (auto)reset.
|
||||
|
||||
|
||||
Return flags of **add()** - is a bitmask
|
||||
Return flags of **add()** - is a bit mask.
|
||||
|
||||
| flag | value | description |
|
||||
|:-------------------|:-----:|:----------------|
|
||||
| MINMAX_NO_CHANGE | 0x00 | no change |
|
||||
| MINMAX_MIN_CHANGED | 0x01 | minimum changed |
|
||||
| MINMAX_MAX_CHANGED | 0x02 | maximum changed |
|
||||
| MINMAX_RESET_DONE | 0x80 | reset done |
|
||||
| flag | value | description |
|
||||
|:---------------------|:-------:|:------------------|
|
||||
| MINMAX_NO_CHANGE | 0x00 | no change |
|
||||
| MINMAX_MIN_CHANGED | 0x01 | minimum changed |
|
||||
| MINMAX_MAX_CHANGED | 0x02 | maximum changed |
|
||||
| MINMAX_RESET_DONE | 0x80 | reset done |
|
||||
|
||||
NOTE: After a reset() the next add() will return both MINMAX_MIN_CHANGED and MINMAX_MAX_CHANGED (0x03)
|
||||
|
||||
|
||||
## Obsolete
|
||||
@ -63,7 +67,13 @@ The examples show the basic working of the functions.
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
- update documentation.
|
||||
|
||||
#### should
|
||||
- move code to .cpp (0.2.0)
|
||||
|
||||
#### could
|
||||
- define FLAGS
|
||||
- add call back functions?
|
||||
- thresholds, windowing + triggers (separate class?)
|
||||
@ -74,5 +84,5 @@ The examples show the basic working of the functions.
|
||||
- Template class to allow other types
|
||||
- int32_t uint64_t double etc.
|
||||
- now you loose precision
|
||||
-
|
||||
- add AVG **average()** \_sum / \_count (like a DMM)
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
//
|
||||
// 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);
|
||||
mm.addCallBack(display);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int r = random(10001) - 5000;
|
||||
mm.add(r);
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
Serial.print(mm.count());
|
||||
Serial.print("\t");
|
||||
Serial.print(mm.minimum());
|
||||
Serial.print("\t");
|
||||
Serial.print(mm.maximum());
|
||||
Serial.print("\n");
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MINMAX.git"
|
||||
},
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MINMAX
|
||||
version=0.1.2
|
||||
version=0.1.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=MINMAX library for Arduino.
|
||||
|
@ -26,8 +26,6 @@
|
||||
#include "Arduino.h"
|
||||
#include "MINMAX.h"
|
||||
|
||||
#define A0 0
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
@ -70,6 +68,9 @@ unittest(test_reset)
|
||||
{
|
||||
mm.add(i);
|
||||
}
|
||||
assertEqual(0, mm.minimum());
|
||||
assertEqual(9, mm.maximum());
|
||||
assertEqual(10, mm.count());
|
||||
mm.reset();
|
||||
assertEqual(0, mm.minimum());
|
||||
assertEqual(0, mm.maximum());
|
||||
@ -93,6 +94,18 @@ unittest(test_autoReset)
|
||||
}
|
||||
|
||||
|
||||
unittest(test_lastValue)
|
||||
{
|
||||
MINMAX mm;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
mm.add(i);
|
||||
}
|
||||
assertEqual(9, mm.lastValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
Loading…
Reference in New Issue
Block a user