RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
DHT11.h
Go to the documentation of this file.
1#pragma once
2#include <stdio.h>
3#include <iostream>
4#include <fstream>
5#include <chrono>
6#include <math.h>
7#include <wiringPi.h>
8#include "BaseComponent.h"
9#include "../Data/RollingAverage.h"
10
11namespace RumPi
12{
21 class DHT11 : public BaseComponent
22 {
23 private:
26
28 unsigned int myDHTPinNumber;
29
31 unsigned int myMaxTimings;
32
35
38
41
44
46 std::chrono::steady_clock::time_point myLastReadTime;
47
48 public:
64 DHT11(const bool isUsingPi5OrAbove, const unsigned int dhtPinNumber, const unsigned int maxTimings = 85U);
65
77 virtual ~DHT11();
78
89 virtual void TurnOn() override;
90
101 virtual void TurnOff() override;
102
115 virtual void ProcessRawValues() override;
116
129 virtual std::string ToString() const override;
130
143 unsigned int GetDHTPinNumber() const;
144
157 unsigned int GetMaxTimings() const;
158
171 float GetAverageHumidity() const;
172
185 float GetCurrentHumidity() const;
186
199 float GetAverageTemperatureInCelsius() const;
200
213 float GetCurrentTemperatureInCelsius() const;
214
228
242 };
243} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
The DHT11 temperature and humidity sensor.
Definition: DHT11.h:22
std::chrono::steady_clock::time_point myLastReadTime
When the last successful read happened (the sensor needs ~2s between reads).
Definition: DHT11.h:46
float GetAverageHumidity() const
Gets the rolling-average humidity.
Definition: DHT11.cpp:369
bool myIsUsingPi5OrAbove
Whether to use the Pi 5+ kernel sysfs read path (true) or the older bit-banged GPIO read (false).
Definition: DHT11.h:25
float GetCurrentTemperatureInFahrenheit() const
Gets the most recent temperature reading converted to Fahrenheit (not averaged).
Definition: DHT11.cpp:461
virtual std::string ToString() const override
Serializes the sensor's current and averaged temperature (Celsius and Fahrenheit) and humidity to a s...
Definition: DHT11.cpp:96
float GetAverageTemperatureInCelsius() const
Gets the rolling-average temperature in Celsius.
Definition: DHT11.cpp:403
unsigned int myDHTPinNumber
The GPIO pin the sensor is wired to (older bit-banged path).
Definition: DHT11.h:28
DHT11(const bool isUsingPi5OrAbove, const unsigned int dhtPinNumber, const unsigned int maxTimings=85U)
Builds a DHT11 on the given pin.
Definition: DHT11.cpp:24
float GetCurrentHumidity() const
Gets the most recent humidity reading (not averaged).
Definition: DHT11.cpp:386
virtual void TurnOff() override
Turns the sensor off.
Definition: DHT11.cpp:79
float GetAverageTemperatureInFahrenheit() const
Gets the rolling-average temperature converted to Fahrenheit.
Definition: DHT11.cpp:443
float GetCurrentTemperatureInCelsius() const
Gets the most recent temperature reading in Celsius (not averaged).
Definition: DHT11.cpp:426
virtual void TurnOn() override
Turns the sensor on.
Definition: DHT11.cpp:64
float myCurrentTemperatureInCelsius
The most recent temperature reading (Celsius), or NaN if none yet.
Definition: DHT11.h:37
RollingAverage myAverageHumidity
Rolling average of humidity readings.
Definition: DHT11.h:40
virtual void ProcessRawValues() override
Reads the sensor (rate-limited to ~once every 2 seconds) and, on a good read, feeds the temperature a...
Definition: DHT11.cpp:123
unsigned int GetMaxTimings() const
Gets the maximum number of signal transitions sampled per read (older bit-banged path).
Definition: DHT11.cpp:352
RollingAverage myAverageTemperatureInCelsius
Rolling average of temperature readings (Celsius).
Definition: DHT11.h:43
unsigned int GetDHTPinNumber() const
Gets the GPIO pin the sensor is wired to.
Definition: DHT11.cpp:335
virtual ~DHT11()
Destroys the sensor, turning it off first.
Definition: DHT11.cpp:49
unsigned int myMaxTimings
Maximum signal transitions to sample per read (older bit-banged path).
Definition: DHT11.h:31
float myCurrentHumidity
The most recent humidity reading (percent), or NaN if none yet.
Definition: DHT11.h:34
Maintains a rolling (moving) average over a fixed-length window of recent readings using a circular b...
Definition: RollingAverage.h:14
RumPi is the library's top-level facade.
Definition: AlertManager.h:6