GY-63_MS5611/libraries/MINMAX
2023-11-14 11:47:18 +01:00
..
.github 0.2.0 MINMAX + git hub actions 2023-02-22 10:38:14 +01:00
examples 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
test 0.2.0 MINMAX 2022-12-07 14:58:50 +01:00
.arduino-ci.yml 0.1.3 MINMAX 2022-11-17 17:36:35 +01:00
CHANGELOG.md 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
keywords.txt 0.2.0 MINMAX 2022-12-07 14:58:50 +01:00
library.json 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
library.properties 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
LICENSE 0.2.0 MINMAX + git hub actions 2023-02-22 10:38:14 +01:00
MINMAX.cpp 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
MINMAX.h 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00
README.md 0.2.1 MINMAX 2023-11-14 11:47:18 +01:00

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

MINMAX

Library for finding peaks (minimum and maximum) in a signal.

Description

The MINMAX library is a simple peak finder in a stream of floats.

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().

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.

The library has the option to auto-reset after a predefined number of add() calls.

Finally the library keeps track when the last peaks occurred.

Interface

#include "MINMAX.h"

Core

  • 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.
  • float minimum() returns last minimum. Can be higher than previous call due to reset() or autoReset(). 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 yet it will return 0.
  • lastValue() returns last value added.

AutoReset

  • uint32_t count() returns number of add() calls since last (auto)reset.
  • 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

  • lastMin() timestamp in millis() when minimum was last updated.
  • lastMax() timestamp in millis() when maximum was last updated.

Return flags add()

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

NOTE: After a reset() the next add() will return both MINMAX_MIN_CHANGED and MINMAX_MAX_CHANGED (0x03)

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.

Obsolete

  • void autoReset(uint32_t count) obsolete since 0.2.0 Replaced by void setAutoResetCount(uint32_t count)

Operation

The examples show the basic working of the functions.

Future

Must

  • documentation

Should

  • 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.

Could

  • Template class to allow other types
    • int32_t uint64_t double etc.
    • now you loose precision

Wont (unless)

  • thresholds, windowing + triggers (separate class?)
  • auto-reset after time? (would affect all functions ?)
    • need a uint32_t start;
    • need a uint32_t threshold;
    • millis() - start > threshold) => action.
    • should be tested for in every function call.

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,