28#include "grmcdorman/device/Device.h"
29#include "grmcdorman/device/Accumulator.h"
31namespace grmcdorman::device
57 explicit AbstractAnalog(
const __FlashStringHelper *device_name,
const __FlashStringHelper *device_identifier,
58 float defaultScale = 1.0f,
float defaultOffset = 0.0f,
bool invert =
false);
60 void setup()
override;
62 bool publish(DynamicJsonDocument &json)
const override;
81 return last_raw_value;
97 DynamicJsonDocument
as_json()
const override;
121 uint32_t current_polling_seconds = 0;
122 float last_raw_value = 0;
Abstract analog device.
Definition: AbstractAnalog.h:46
void setup() override
Setup the device.
Definition: AbstractAnalog.cpp:44
bool publish(DynamicJsonDocument &json) const override
Publish the value and attributes.
Definition: AbstractAnalog.cpp:67
FloatSetting offset
Scaling.
Definition: AbstractAnalog.h:112
AbstractAnalog(const __FlashStringHelper *device_name, const __FlashStringHelper *device_identifier, float defaultScale=1.0f, float defaultOffset=0.0f, bool invert=false)
Construct a new Basic Analog object.
Definition: AbstractAnalog.cpp:29
void loop() override
Main loop.
Definition: AbstractAnalog.cpp:54
uint32_t last_read_millis
Timestamp of last read.
Definition: AbstractAnalog.h:115
ToggleSetting invertReading
Whether to invert the reading.
Definition: AbstractAnalog.h:113
float get_last_reading() const
Last computed reading.
Definition: AbstractAnalog.h:69
float get_current_average() const
Get the last average reading.
Definition: AbstractAnalog.h:92
constexpr static uint32_t statusReadInterval
Default read interval. Chosen such that there should be 5 readings per 30 seconds.
Definition: AbstractAnalog.h:116
Accumulator< float, 5 > sensor_reading
Reading.
Definition: AbstractAnalog.h:117
virtual float transform_raw_reading(int reading)=0
Transform the raw reading into the reported value.
FloatSetting scale
Offset.
Definition: AbstractAnalog.h:111
UnsignedIntegerSetting readInterval
How often to request a reading.
Definition: AbstractAnalog.h:114
float raw_value() const
Last raw value (no scale or offset applied).
Definition: AbstractAnalog.h:79
DynamicJsonDocument as_json() const override
Get the values, as a JSON document.
Definition: AbstractAnalog.cpp:79
A class to handle accumulating values.
Definition: Accumulator.h:54
The generic device interface.
Definition: Device.h:46