|
esp8266_web_settings beta
|
A basic analog device. More...
#include <grmcdorman/device/BasicAnalog.h>
Public Member Functions | |
| BasicAnalog (const __FlashStringHelper *units, bool allowUserAdjust, float defaultScale=1.0f, float defaultOffset=0.0f, bool invert=false) | |
| Construct a new Basic Analog object. More... | |
| virtual String | get_status () const |
| Get a status report. More... | |
Public Member Functions inherited from grmcdorman::device::AbstractAnalog | |
| 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. More... | |
| void | setup () override |
| Setup the device. More... | |
| void | loop () override |
| Main loop. More... | |
| bool | publish (DynamicJsonDocument &json) const override |
| Publish the value and attributes. More... | |
| float | get_last_reading () const |
| Last computed reading. More... | |
| float | raw_value () const |
| Last raw value (no scale or offset applied). More... | |
| float | get_current_average () const |
| Get the last average reading. More... | |
| DynamicJsonDocument | as_json () const override |
| Get the values, as a JSON document. More... | |
Public Member Functions inherited from grmcdorman::device::Device | |
| Device (const __FlashStringHelper *device_name, const __FlashStringHelper *device_identifier) | |
| Construct a new Device object. More... | |
| virtual | ~Device () |
| Destroy the Device object. | |
| const __FlashStringHelper * | name () const |
| Get the device name; used for UI names and IDs. More... | |
| virtual const __FlashStringHelper * | identifier () const |
| Get the device identifier. More... | |
| virtual void | set_defaults () |
| Set defaults, if necessary. More... | |
| virtual void | set_devices (const std::vector< Device * > &list) |
| For devices that support it, add devices to manage. More... | |
| const definition_list_t & | get_definitions () const |
| Get the definitions list. More... | |
| const ::grmcdorman::SettingInterface::settings_list_t & | get_settings () const |
| Get the settings list. More... | |
| bool | is_enabled () const |
| Get whether this device is enabled. More... | |
| void | set_enabled (bool state) |
| Set whether this device is enabled. More... | |
| void | set (const String &setting, const String &value) |
| If possible, set a setting's value. More... | |
| String | get (const String &setting) const |
| Get a setting value, as a string. More... | |
| virtual bool | get_is_published () const |
| Get whether the device readings have been published. More... | |
| void | set_is_published () |
| Set the device as having published readings. More... | |
| void | clear_is_published () |
| Set the device as not having published readings. | |
Protected Member Functions | |
| virtual float | transform_raw_reading (int reading) override |
| Transform the raw reading into the reported value. More... | |
Protected Member Functions inherited from grmcdorman::device::Device | |
| void | initialize (definition_list_t &&definition_list, ::grmcdorman::SettingInterface::settings_list_t &&setting_list) |
| Initialize the definition and setting lists. More... | |
Protected Attributes | |
| NoteSetting | title |
| Device tab title. | |
| InfoSettingHtml | device_status |
| Last update. | |
Protected Attributes inherited from grmcdorman::device::AbstractAnalog | |
| FloatSetting | scale |
| Offset. | |
| FloatSetting | offset |
| Scaling. | |
| ToggleSetting | invertReading |
| Whether to invert the reading. | |
| UnsignedIntegerSetting | readInterval |
| How often to request a reading. | |
| uint32_t | last_read_millis = 0 |
| Timestamp of last read. | |
| Accumulator< float, 5 > | sensor_reading |
| Reading. | |
Protected Attributes inherited from grmcdorman::device::Device | |
| ToggleSetting | enabled |
| Whether this device is enabled. | |
Additional Inherited Members | |
Public Types inherited from grmcdorman::device::Device | |
| typedef std::vector< const Definition * > | definition_list_t |
| The type containing a list of Definition objects. | |
Static Public Member Functions inherited from grmcdorman::device::Device | |
| static void | set_system_identifiers (const __FlashStringHelper *firmware_name_value, const String &system_identifier_value=String()) |
| Set the system identifier values. More... | |
| static const __FlashStringHelper * | get_firmware_name () |
| Get the firmware prefix. More... | |
| static const String & | get_system_identifier () |
| Get the system identifier. More... | |
Static Public Attributes inherited from grmcdorman::device::Device | |
| static constexpr int | D0 = 16 |
| D0 is GPIO16, HIGH at boot, not suitable for most usages. | |
| static constexpr int | D1 = 5 |
| D1 is GPIO5; often used as SCL. | |
| static constexpr int | D2 = 4 |
| D2 is GPIO4; often used as SDA. | |
| static constexpr int | D3 = 0 |
| D3 is GPIO0; pulled up; connected to FLASH button; not for input. | |
| static constexpr int | D4 = 2 |
| D4 is GPIO2; pulled up; HIGH at boot; on-board LED; not for input. | |
| static constexpr int | D5 = 14 |
| D5 is GPIO14; SPI (SCLK) | |
| static constexpr int | D6 = 12 |
| D6 is GPIO12; SPI (MISO) | |
| static constexpr int | D7 = 13 |
| D7 is GPIO13; SPI (MOSI) | |
| static constexpr int | D8 = 15 |
| D8 is GPIO15; pulled to GND; SPI (CS); not recommended. | |
| static const ExclusiveOptionSetting::names_list_t | data_line_names { FPSTR("D1"), FPSTR("D2"), FPSTR("D3"), FPSTR("D5"), FPSTR("D6"), FPSTR("D7")} |
Names for each configurable data line; see settingsMap. | |
Static Protected Member Functions inherited from grmcdorman::device::Device | |
| static int | index_to_dataline (int index) |
| Convert a data line index to a ESP data line. More... | |
| static int | dataline_to_index (int dataLine) |
| Convert a data line to an index. More... | |
Static Protected Attributes inherited from grmcdorman::device::AbstractAnalog | |
| constexpr static uint32_t | statusReadInterval = (30 / 5) * 1000 |
| Default read interval. Chosen such that there should be 5 readings per 30 seconds. | |
Static Protected Attributes inherited from grmcdorman::device::Device | |
| static const int | settingsMap [6] |
| The set of data lines usable for communication. More... | |
A basic analog device.
This device reads A0; the value can be transformed by a scale and an offset before reporting. The value can also be inverted (i.e. 1/value).
This can be used for devices like potentiometers or photoresistors; anything where the input is linear. Note that thermistors do not have a linear response; there is a seperate class - ThermistorSensor for handling them.
Appropriate scaling and offsets can be applied, possibly with inversion, to convert the raw reading to a range of interest.
The raw reading has a range of 0 to 1024 on ESP8266. The maximum value may correspond to 1V, or 3.3V on the A0 (ADC) pin. You can determine this maximum by using a potentiometer connected across the +3.3V and GND, with the middle connection to the A0. If the reading reaches the maximum (1023 or 1024) when the potentiometer is only about 1/3 turned and remains at that value for the rest of the range, then your ADC has a maximum value of 1.0V.
If the application requires fixed scaling, pass false as the second parameter to the constructor so that the scaling cannot be changed.
|
explicit |
Construct a new Basic Analog object.
| units | Units. Required for publishing to MQTT/Home Assistant. |
| allowUserAdjust | If true, the user can adust scaling/offset/inversion in the UI, and the values are saved. |
| defaultScale | Default scaling value. |
| defaultOffset | Default offset value. |
| invert | If true, invert the reading before applying scale and offset. |
|
virtual |
Get a status report.
This is also used for the device_status info message, with the exception of various disabled states.
Reimplemented from grmcdorman::device::Device.
|
inlineoverrideprotectedvirtual |
Transform the raw reading into the reported value.
This can, for example, transform the raw A0 value into volts, or transform a thermistor value in to degrees Celcius.
Do not apply the scaling, offset, and invert values in this method; they will be automatically applied on the returned value.
| reading | The raw reading. |
Implements grmcdorman::device::AbstractAnalog.