GY-63_MS5611/libraries/MINMAX/README.md

140 lines
4.6 KiB
Markdown
Raw Normal View History

2021-10-14 08:54:11 -04:00
2023-11-14 05:47:18 -05:00
2021-10-14 08:54:11 -04:00
[![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)
2023-11-14 05:47:18 -05:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MINMAX.svg)](https://github.com/RobTillaart/MINMAX/issues)
2021-10-14 08:54:11 -04:00
[![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)
2023-11-14 05:47:18 -05:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MINMAX.svg)](https://registry.platformio.org/libraries/robtillaart/MINMAX)
2021-10-14 08:54:11 -04:00
2021-11-08 15:19:42 -05:00
2021-10-14 08:54:11 -04:00
# MINMAX
2022-11-17 11:36:35 -05:00
Library for finding peaks (minimum and maximum) in a signal.
2021-10-14 08:54:11 -04:00
2021-11-08 15:19:42 -05:00
2021-10-14 08:54:11 -04:00
## Description
2022-12-07 08:58:50 -05:00
The MINMAX library is a simple peak finder in a stream of floats.
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
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 which is returned.
If a peak is found, it will be used as the new **minimum()** or **maximum()**
until a call to **reset()**.
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
The library can **reset()** the minimum and maximum to 0 to start again.
The first **add()** after the **reset()** will set the minimum and maximum
to the value added.
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
The library has the option to auto-reset after a predefined number of **add()** calls.
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
Finally the library keeps track when the last peaks occurred.
2022-11-17 11:36:35 -05:00
2021-10-14 08:54:11 -04:00
## Interface
2023-11-14 05:47:18 -05:00
```cpp
#include "MINMAX.h"
```
2022-12-07 08:58:50 -05:00
#### Core
2023-11-14 05:47:18 -05:00
- **MINMAX()** Constructor,
2021-11-08 15:19:42 -05:00
- **uint8_t add(float value)** add next value. Returns status (bit flags), see table below.
2021-10-14 08:54:11 -04:00
- **void reset()** resets the minimum and maximum to 0.
2022-12-07 08:58:50 -05:00
- **float minimum()** returns last minimum. Can be higher than previous call due to **reset()** or **autoReset()**.
2022-11-17 11:36:35 -05:00
If no call to **add()** is made yet it will return 0.
2022-12-07 08:58:50 -05:00
- **float maximum()** returns last maximum. Can be lower than previous call due to **reset()** or **autoReset()**.
2022-11-17 11:36:35 -05:00
If no call to **add()** is made yet it will return 0.
2022-12-07 08:58:50 -05:00
- **lastValue()** returns last value added.
#### AutoReset
2021-11-08 15:19:42 -05:00
- **uint32_t count()** returns number of **add()** calls since last (auto)reset.
2022-12-07 08:58:50 -05:00
- **void setAutoResetCount(uint32_t count)** sets an auto-reset moment after count calls to **add()**.
There will be at least one value processed.
When count is set to 0, there will be no autoReset.
- **uint32_t getAutoResetCount()** returns set value.
#### Timestamps
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
- **lastMin()** timestamp in millis() when minimum was last updated.
- **lastMax()** timestamp in millis() when maximum was last updated.
#### Return flags add()
2021-10-14 08:54:11 -04:00
2022-11-17 11:36:35 -05:00
Return flags of **add()** - is a bit mask.
2021-12-21 13:57:20 -05:00
2022-11-17 11:36:35 -05:00
| 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 |
2021-10-14 08:54:11 -04:00
2022-11-17 11:36:35 -05:00
NOTE: After a reset() the next add() will return both MINMAX_MIN_CHANGED and MINMAX_MAX_CHANGED (0x03)
2021-10-14 08:54:11 -04:00
2022-12-07 08:58:50 -05:00
NOTE: After an autoReset in add() it will return 0x83.
#### CallBack
- **void addCallBack( void (\* func)(void) )** add a function to be called
when the minimum or the maximum has changed.
See examples.
2021-10-14 08:54:11 -04:00
2021-11-08 15:19:42 -05:00
## Obsolete
2022-12-07 08:58:50 -05:00
- **void autoReset(uint32_t count)** obsolete since 0.2.0
2023-11-14 05:47:18 -05:00
Replaced by **void setAutoResetCount(uint32_t count)**
2021-11-08 15:19:42 -05:00
2021-10-14 08:54:11 -04:00
## Operation
The examples show the basic working of the functions.
## Future
2023-11-14 05:47:18 -05:00
#### Must
- documentation
#### Should
2022-11-17 11:36:35 -05:00
2022-12-07 08:58:50 -05:00
- separate call back for MINMAX_MIN_CHANGED and MINMAX_MAX_CHANGED
- add getLastEvent()?
- add AVG **average()** **sum()**
- like a digital multimeter (DMM)
- **sum()** would be sufficient as average can be derived.
2022-11-17 11:36:35 -05:00
2023-11-14 05:47:18 -05:00
#### Could
2022-12-07 08:58:50 -05:00
- Template class to allow other types
- int32_t uint64_t double etc.
- now you loose precision
2023-11-14 05:47:18 -05:00
#### Wont (unless)
2021-10-14 08:54:11 -04:00
- thresholds, windowing + triggers (separate class?)
2021-11-08 15:19:42 -05:00
- auto-reset after time? (would affect all functions ?)
- need a uint32_t start;
- need a uint32_t threshold;
- millis() - start > threshold) => action.
2022-12-07 08:58:50 -05:00
- should be tested for in every function call.
2023-11-14 05:47:18 -05:00
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,
2021-10-14 08:54:11 -04:00