NW_Readings
Fixed-capacity store for one measurement’s readings, with statistics. More…
#include <NW_Readings.h>
Public Functions
| Name | |
|---|---|
| void | reset() |
| void | append(T v) |
| uint16_t | count() const |
| T | last() const The newest reading (meaningful only if count() > 0). |
| const T * | data() const The readings, in storage order (not chronological after a wrap; statistics do not care). |
| float | mean() const |
| float | std() const Sample standard deviation (n-1); 0 for a single reading. |
| float | sterr() const Standard error of the mean, std / sqrt(n); 0 for a single reading. |
| float | median() const Median: copies the readings once and insertion-sorts (n <= CAPACITY). |
| constexpr uint16_t | capacity() |
Public Attributes
| Name | |
|---|---|
| constexpr float | NW_READINGS_EMPTY returned by the statistics when count() == 0: the file sentinel |
Detailed Description
template <typename T ,
uint16_t CAPACITY>
class NW_Readings;
Fixed-capacity store for one measurement’s readings, with statistics.
Template Parameters:
- T element type (int16_t, uint16_t, uint32_t, float)
- CAPACITY number of readings kept
One storage path (LIBRARY-DESIGN, decided 2026-09-22): every acquisition appends here; the scalar getter of a library returns last(); the statistics are computed from the array on demand, so a batch logged through logReading() has its statistics without a second acquisition. Appending past CAPACITY overwrites the oldest reading (the newest CAPACITY readings are kept). No heap. mean/std/sterr are two-pass in float, exact enough for CAPACITY up to a few hundred; median copies the array once onto the stack (CAPACITY * sizeof(T) bytes), so keep CAPACITY modest on small AVRs.
Public Functions Documentation
function reset
inline void reset()
function append
inline void append(
T v
)
function count
inline uint16_t count() const
function last
inline T last() const
The newest reading (meaningful only if count() > 0).
function data
inline const T * data() const
The readings, in storage order (not chronological after a wrap; statistics do not care).
function mean
inline float mean() const
function std
inline float std() const
Sample standard deviation (n-1); 0 for a single reading.
function sterr
inline float sterr() const
Standard error of the mean, std / sqrt(n); 0 for a single reading.
function median
inline float median() const
Median: copies the readings once and insertion-sorts (n <= CAPACITY).
function capacity
static inline constexpr uint16_t capacity()
Public Attributes Documentation
variable NW_READINGS_EMPTY
static constexpr float NW_READINGS_EMPTY = NW_ERROR;
returned by the statistics when count() == 0: the file sentinel
Updated on 2026-09-23 at 22:42:22 +0000