![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
The DHT11 temperature and humidity sensor. More...
#include <DHT11.h>
Public Member Functions | |
| DHT11 (const bool isUsingPi5OrAbove, const unsigned int dhtPinNumber, const unsigned int maxTimings=85U) | |
| Builds a DHT11 on the given pin. More... | |
| virtual | ~DHT11 () |
| Destroys the sensor, turning it off first. More... | |
| virtual void | TurnOn () override |
| Turns the sensor on. More... | |
| virtual void | TurnOff () override |
| Turns the sensor off. More... | |
| virtual void | ProcessRawValues () override |
| Reads the sensor (rate-limited to ~once every 2 seconds) and, on a good read, feeds the temperature and humidity into their rolling averages. More... | |
| virtual std::string | ToString () const override |
| Serializes the sensor's current and averaged temperature (Celsius and Fahrenheit) and humidity to a string. More... | |
| unsigned int | GetDHTPinNumber () const |
| Gets the GPIO pin the sensor is wired to. More... | |
| unsigned int | GetMaxTimings () const |
| Gets the maximum number of signal transitions sampled per read (older bit-banged path). More... | |
| float | GetAverageHumidity () const |
| Gets the rolling-average humidity. More... | |
| float | GetCurrentHumidity () const |
| Gets the most recent humidity reading (not averaged). More... | |
| float | GetAverageTemperatureInCelsius () const |
| Gets the rolling-average temperature in Celsius. More... | |
| float | GetCurrentTemperatureInCelsius () const |
| Gets the most recent temperature reading in Celsius (not averaged). More... | |
| float | GetAverageTemperatureInFahrenheit () const |
| Gets the rolling-average temperature converted to Fahrenheit. More... | |
| float | GetCurrentTemperatureInFahrenheit () const |
| Gets the most recent temperature reading converted to Fahrenheit (not averaged). More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Private Attributes | |
| bool | myIsUsingPi5OrAbove |
| Whether to use the Pi 5+ kernel sysfs read path (true) or the older bit-banged GPIO read (false). More... | |
| unsigned int | myDHTPinNumber |
| The GPIO pin the sensor is wired to (older bit-banged path). More... | |
| unsigned int | myMaxTimings |
| Maximum signal transitions to sample per read (older bit-banged path). More... | |
| float | myCurrentHumidity |
| The most recent humidity reading (percent), or NaN if none yet. More... | |
| float | myCurrentTemperatureInCelsius |
| The most recent temperature reading (Celsius), or NaN if none yet. More... | |
| RollingAverage | myAverageHumidity |
| Rolling average of humidity readings. More... | |
| RollingAverage | myAverageTemperatureInCelsius |
| Rolling average of temperature readings (Celsius). More... | |
| std::chrono::steady_clock::time_point | myLastReadTime |
| When the last successful read happened (the sensor needs ~2s between reads). More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
The DHT11 temperature and humidity sensor.
Its readings tend to fluctuate, so they are averaged over time (via RollingAverage) for a stable value. Supports both the newer Pi 5+ kernel IIO read path and the older bit-banged GPIO read.
| RumPi::DHT11::DHT11 | ( | const bool | isUsingPi5OrAbove, |
| const unsigned int | dhtPinNumber, | ||
| const unsigned int | maxTimings = 85U |
||
| ) |
Builds a DHT11 on the given pin.
Chooses the read path from isUsingPi5OrAbove, and initializes the last-read time to a few seconds ago so the first read is allowed immediately.
| [in] | isUsingPi5OrAbove | true to use the Pi 5+ kernel read path; false for the older bit-banged read. |
| [in] | dhtPinNumber | The GPIO pin the sensor is wired to (older path). |
| [in] | maxTimings | Maximum signal transitions to sample per read (older path). |
|
virtual |
| float RumPi::DHT11::GetAverageHumidity | ( | ) | const |
Gets the rolling-average humidity.
| float RumPi::DHT11::GetAverageTemperatureInCelsius | ( | ) | const |
Gets the rolling-average temperature in Celsius.
| float RumPi::DHT11::GetAverageTemperatureInFahrenheit | ( | ) | const |
Gets the rolling-average temperature converted to Fahrenheit.
| float RumPi::DHT11::GetCurrentHumidity | ( | ) | const |
Gets the most recent humidity reading (not averaged).
| float RumPi::DHT11::GetCurrentTemperatureInCelsius | ( | ) | const |
Gets the most recent temperature reading in Celsius (not averaged).
| float RumPi::DHT11::GetCurrentTemperatureInFahrenheit | ( | ) | const |
Gets the most recent temperature reading converted to Fahrenheit (not averaged).
| unsigned int RumPi::DHT11::GetDHTPinNumber | ( | ) | const |
Gets the GPIO pin the sensor is wired to.
| unsigned int RumPi::DHT11::GetMaxTimings | ( | ) | const |
Gets the maximum number of signal transitions sampled per read (older bit-banged path).
|
overridevirtual |
Reads the sensor (rate-limited to ~once every 2 seconds) and, on a good read, feeds the temperature and humidity into their rolling averages.
Uses the Pi 5+ kernel sysfs path or the older bit-banged GPIO read depending on how the sensor was constructed; a failed or flaky read keeps the previous values.
Implements RumPi::BaseComponent.
|
overridevirtual |
Serializes the sensor's current and averaged temperature (Celsius and Fahrenheit) and humidity to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the sensor off.
The DHT11 needs no active teardown here, so this is a no-op.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the sensor on.
The DHT11 needs no active setup here, so this is a no-op.
Implements RumPi::BaseComponent.
|
private |
Rolling average of humidity readings.
|
private |
Rolling average of temperature readings (Celsius).
|
private |
The most recent humidity reading (percent), or NaN if none yet.
|
private |
The most recent temperature reading (Celsius), or NaN if none yet.
|
private |
The GPIO pin the sensor is wired to (older bit-banged path).
|
private |
Whether to use the Pi 5+ kernel sysfs read path (true) or the older bit-banged GPIO read (false).
|
private |
When the last successful read happened (the sensor needs ~2s between reads).
|
private |
Maximum signal transitions to sample per read (older bit-banged path).