Skip to content

Commit a91acf3

Browse files
committed
0.1.0 RunningMinMax
1 parent 95af1b8 commit a91acf3

20 files changed

Lines changed: 844 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
- due
21+
- zero
22+
- leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
- mega2560
27+
- rpipico
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v6
10+
- uses: arduino/arduino-lint-action@v2
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
steps:
10+
- uses: actions/checkout@v6
11+
- uses: ruby/setup-ruby@v1
12+
with:
13+
ruby-version: 2.6
14+
- run: |
15+
gem install arduino_ci
16+
arduino_ci.rb
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
paths:
9+
- '**.json'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- uses: actions/checkout@v6
17+
- name: json-syntax-check
18+
uses: limitusus/json-syntax-check@v2
19+
with:
20+
pattern: "\\.json$"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log RunningMinMax
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2026-02-01
10+
- initial version
11+

libraries/RunningMinMax/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026-2026 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/RunningMinMax/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/RunningMinMax/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/RunningMinMax/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/RunningMinMax/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/RunningMinMax/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/RunningMinMax/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/RunningMinMax.svg)](https://github.com/RobTillaart/RunningMinMax/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/RunningMinMax/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/RunningMinMax.svg?maxAge=3600)](https://github.com/RobTillaart/RunningMinMax/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/RunningMinMax.svg)](https://registry.platformio.org/libraries/robtillaart/RunningMinMax)
10+
11+
12+
# RunningMinMax
13+
14+
Arduino library for a running Minimum and Maximum.
15+
16+
17+
## Description
18+
19+
**Experimental**
20+
21+
RunningMinMax stores values in a ring buffer and can return the minimum,
22+
maximum and the average of the buffer.
23+
The first implementation is not optimized.
24+
25+
The library can be used e.g. to have an indication for the maximum
26+
volume for a VU meter.
27+
28+
The library does not store timestamps of the samples (yet), that might
29+
be a function in the future.
30+
31+
Feedback as always welcome.
32+
33+
34+
### Related
35+
36+
- https://github.com/RobTillaart/Correlation
37+
- https://github.com/RobTillaart/GST - Golden standard test metrics
38+
- https://github.com/RobTillaart/Histogram
39+
- https://github.com/RobTillaart/infiniteAverage
40+
- https://github.com/RobTillaart/RunningAngle
41+
- https://github.com/RobTillaart/RunningAverage
42+
- https://github.com/RobTillaart/RunningMedian
43+
- https://github.com/RobTillaart/RunningMinMax
44+
- https://github.com/RobTillaart/statHelpers - combinations & permutations
45+
- https://github.com/RobTillaart/Statistic
46+
- https://github.com/RobTillaart/Student
47+
48+
For printing floats in scientific or engineering format
49+
50+
https://github.com/RobTillaart/printHelpers
51+
52+
53+
## Interface
54+
55+
```cpp
56+
#include "RunningMinMax.h"
57+
```
58+
59+
60+
### Constructor
61+
62+
- **RunningMinMax(const uint8_t size)** Constructor, dynamically allocates memory.
63+
- **~RunningMinMax()** Destructor.
64+
- **uint8_t getSize()** returns size of internal array.
65+
- **uint8_t getCount()** returns current used elements, getCount() <= getSize().
66+
- **bool isFull()** returns true if the internal buffer is 100% filled.
67+
68+
69+
### Base functions
70+
71+
- **clear()** resets internal buffer and variables, effectively empty the buffer.
72+
- **add(const float value)** adds a new value to internal buffer,
73+
optionally replacing the oldest element if the buffer is full.
74+
- **float getAverage()** returns average of the values in the internal buffer.
75+
- **float getMaximum()** get the largest values in the buffer.
76+
- **float getMinimum()** get the smallest value in the buffer.
77+
78+
79+
## Future
80+
81+
#### Must
82+
83+
- improve documentation.
84+
- test
85+
- keep it a simple class.
86+
87+
#### Should
88+
89+
- check for optimizations.
90+
91+
#### Could
92+
93+
- check for optimizations.
94+
- add examples
95+
- extend unit tests
96+
97+
#### Wont
98+
99+
100+
## Support
101+
102+
If you appreciate my libraries, you can support the development and maintenance.
103+
Improve the quality of the libraries by providing issues and Pull Requests, or
104+
donate through PayPal or GitHub sponsors.
105+
106+
Thank you,
107+
108+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// FILE: RunningMinMax.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// DATE: 2026-02-01
6+
// PURPOSE: Arduino library for a running Minimum and Maximum.
7+
// URL: https://github.com/RobTillaart/RunningMinMax
8+
9+
10+
#include "RunningMinMax.h"
11+
12+
13+
RunningMinMax::RunningMinMax(const uint8_t size)
14+
{
15+
_count = 0;
16+
_size = size;
17+
if (_size == 0) _size = 1;
18+
if (_size > RMM_MAX_SIZE) _size = RMM_MAX_SIZE;
19+
20+
_values = (float *) malloc(_size * sizeof(float));
21+
}
22+
23+
24+
RunningMinMax::~RunningMinMax()
25+
{
26+
if (_values) free(_values);
27+
}
28+
29+
30+
// resets all internal counters
31+
void RunningMinMax::reset()
32+
{
33+
_count = 0;
34+
_index = 0;
35+
}
36+
37+
38+
// adds a new value to the data-set
39+
// or overwrites the oldest if full.
40+
void RunningMinMax::add(float value)
41+
{
42+
_values[_index++] = value;
43+
if (_index >= _size) _index = 0; // wrap around
44+
if (_count < _size) _count++;
45+
}
46+
47+
48+
float RunningMinMax::getAverage()
49+
{
50+
if (_count == 0) return NAN;
51+
52+
float sum = 0;
53+
for (uint8_t i = 0; i < _count; i++)
54+
{
55+
sum += _values[i];
56+
}
57+
return sum / _count;
58+
}
59+
60+
61+
float RunningMinMax::getMinimum()
62+
{
63+
if (_count == 0) return NAN;
64+
65+
float minimum = _values[0];
66+
for (uint8_t i = 1; i < _count; i++)
67+
{
68+
if (_values[i] < minimum) minimum = _values[i];
69+
}
70+
return minimum;
71+
}
72+
73+
74+
float RunningMinMax::getMaximum()
75+
{
76+
if (_count == 0) return NAN;
77+
78+
float maximum = _values[0];
79+
for (uint8_t i = 1; i < _count; i++)
80+
{
81+
if (_values[i] > maximum) maximum = _values[i];
82+
}
83+
return maximum;
84+
}
85+
86+
87+
88+
// -- END OF FILE --
89+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
//
3+
// FILE: RunningMinMax.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// DATE: 2026-02-01
7+
// PURPOSE: Arduino library for a running Minimum and Maximum.
8+
// URL: https://github.com/RobTillaart/RunningMinMax
9+
10+
11+
#include "Arduino.h"
12+
13+
#define RUNNING_MINMAX_LIB_VERSION (F("0.1.0"))
14+
15+
const int RMM_MAX_SIZE = 250;
16+
17+
18+
class RunningMinMax
19+
{
20+
public:
21+
// # elements in the internal buffer
22+
explicit RunningMinMax(const uint8_t size);
23+
~RunningMinMax();
24+
25+
// resets internal buffer and variables
26+
void reset();
27+
// adds a new value to internal buffer, optionally replacing the oldest element.
28+
void add(const float value);
29+
30+
float getAverage();
31+
float getMinimum();
32+
float getMaximum();
33+
34+
uint8_t getSize() { return _size; };
35+
uint8_t getCount() { return _count; };
36+
bool isFull() { return (_count == _size); }
37+
38+
protected:
39+
uint8_t _size; // max number of values
40+
uint8_t _count; // current number of values <= size
41+
uint8_t _index; // next index to add
42+
float * _values; //
43+
};
44+
45+
46+
// -- END OF FILE --
47+

0 commit comments

Comments
 (0)