68 lines
1.3 KiB
C
Raw Normal View History

2021-10-14 14:54:11 +02:00
#pragma once
//
// FILE: MINMAX.h
// AUTHOR: Rob Tillaart
2023-11-14 11:47:18 +01:00
// VERSION: 0.2.1
2021-10-14 14:54:11 +02:00
// DATE: 2021-10-14
// PURPOSE: MINMAX library - simple peak finder
2022-12-07 14:58:50 +01:00
// URL: https://github.com/RobTillaart/MINMAX
2021-10-14 14:54:11 +02:00
#include "Arduino.h"
2023-11-14 11:47:18 +01:00
#define MINMAX_LIB_VERSION (F("0.2.1"))
2021-12-21 19:57:20 +01:00
#define MINMAX_NO_CHANGE 0X00
#define MINMAX_MIN_CHANGED 0X01
#define MINMAX_MAX_CHANGED 0X02
#define MINMAX_RESET_DONE 0X80
2021-10-14 14:54:11 +02:00
class MINMAX
{
2021-11-08 21:19:42 +01:00
public:
2021-10-14 14:54:11 +02:00
2022-12-07 14:58:50 +01:00
MINMAX();
uint8_t add(const float value);
void reset();
// call back function when there is a change
void addCallBack( void (* func)(void) );
// set the auto reset at certain count
// count == 0 implies no auto reset.
void setAutoResetCount(uint32_t count);
uint32_t getAutoResetCount();
// last value added
float lastValue();
// number of elements added.
uint32_t count();
// peak values so far.
float minimum();
float maximum();
// timestamp of the last minimum and maximum change in milliseconds since start.
uint32_t lastMin();
uint32_t lastMax();
2021-11-08 21:19:42 +01:00
private:
2022-11-17 17:36:35 +01:00
float _lastValue;
2021-11-08 21:19:42 +01:00
float _minimum;
float _maximum;
uint32_t _count;
uint32_t _resetCount;
2022-11-17 17:36:35 +01:00
void (* _callback)(void);
uint32_t _lastMin;
uint32_t _lastMax;
2021-10-14 14:54:11 +02:00
};
2021-11-08 21:19:42 +01:00
2022-12-07 14:58:50 +01:00
// -- END OF FILE --
2021-11-08 21:19:42 +01:00