DHT22Gen3_RK
Public Types | Public Member Functions | Protected Attributes | Friends
DHTSample Class Reference

Class for encapsulating the results to a call to getSample() More...

#include <DHT22Gen3_RK.h>

Public Types

enum  SampleResult { SampleResult::SUCCESS = 0, SampleResult::ERROR, SampleResult::TOO_MANY_RETRIES, SampleResult::BUSY }
 Enumeration for result codes from the getSample() request. More...
 

Public Member Functions

 DHTSample ()
 Constructor. More...
 
virtual ~DHTSample ()
 Destructor.
 
void clear ()
 Clears the results. More...
 
bool isValidChecksum () const
 Returns true if the checksum in bytes is valid. More...
 
float getTempC () const
 Gets the temperature in degrees Celsius. More...
 
float getTempF () const
 Gets the temperature in degrees Fahrenheit.
 
float getHumidity () const
 Gets the humidity in percent RH (0-100) as a floating point number. More...
 
float getDewPointC () const
 Gets the dew point in degrees Celsius. More...
 
float getDewPointF () const
 Gets the dew point in degrees Fahrenheit. More...
 
SampleResult getSampleResult () const
 Gets the sample result value (0 = success, non-zero = error) More...
 
int getTries () const
 Gets the number of retries. More...
 
DHTSamplewithSuccess ()
 Sets the sample result to SUCCESS.
 
bool isSuccess () const
 Returns true if getSample() was successful. More...
 
DHTSamplewithBusy ()
 Sets the sample result to BUSY.
 
bool isBusy () const
 Returns true if getSample() failed because another call was in progress.
 
DHTSamplewithError ()
 Sets the sample result to ERROR.
 
bool isError () const
 Returns true if getSample() failed because of an internal error.
 
DHTSamplewithTooManyRetries ()
 Sets the sample result to TOO_MANY_RETRIES.
 
bool isTooManyRetries () const
 Returns true if getSample() failed because a valid result was not obtained in the maximum number of retries.
 
DHTSamplewithSensorType (DHTSensorType *sensorType)
 Sets the data format of bytes.
 
uint8_t operator[] (size_t index) const
 Get a byte from the bytes array.
 

Protected Attributes

SampleResult sampleResult = SampleResult::ERROR
 Result code. 0 is success, error are non-zero.
 
DHTSensorTypesensorType = 0
 Sensor type for this sample.
 
uint8_t bytes [5] = {0}
 Raw bytes of data from DHT22.
 
int tries = 0
 Number of retries. Normally 1 for the initial try, will be greater for retries.
 

Friends

class DHT22Gen3
 

Detailed Description

Class for encapsulating the results to a call to getSample()

Member Enumeration Documentation

◆ SampleResult

Enumeration for result codes from the getSample() request.

Success is 0. All other codes are errors

Enumerator
SUCCESS 

Success (including valid checksum)

ERROR 

An internal error (problem with the I2S peripheral, etc.)

TOO_MANY_RETRIES 

After the specified number of retries, could not get a valid result.

BUSY 

Called getSample() before the previous call completed.

Constructor & Destructor Documentation

◆ DHTSample()

DHTSample::DHTSample ( )

Constructor.

You normally don't need to construct one of these; it's filled in for you by getSample()

Member Function Documentation

◆ clear()

void DHTSample::clear ( )

Clears the results.

Sets the result to ERROR, zeros the bytes, sets tries to 0

◆ getDewPointC()

float DHTSample::getDewPointC ( ) const

Gets the dew point in degrees Celsius.

The value is undefined is isSuccess() is not true. You you check that before relying on this value.

◆ getDewPointF()

float DHTSample::getDewPointF ( ) const

Gets the dew point in degrees Fahrenheit.

The value is undefined is isSuccess() is not true. You you check that before relying on this value.

◆ getHumidity()

float DHTSample::getHumidity ( ) const

Gets the humidity in percent RH (0-100) as a floating point number.

The value is undefined is isSuccess() is not true. You you check that before relying on this value.

◆ getSampleResult()

SampleResult DHTSample::getSampleResult ( ) const
inline

Gets the sample result value (0 = success, non-zero = error)

You may want to use isSuccess(), isBusy(), isError(), or isTooManyRetries() instead.

◆ getTempC()

float DHTSample::getTempC ( ) const

Gets the temperature in degrees Celsius.

The value is undefined is isSuccess() is not true. You you check that before relying on this value.

◆ getTries()

int DHTSample::getTries ( ) const
inline

Gets the number of retries.

Returns
1 in the normal case. If a checksum error occurred, numbers > 1 indicate retries, up to the configured number of maxRetries

◆ isSuccess()

bool DHTSample::isSuccess ( ) const
inline

Returns true if getSample() was successful.

The call completed successfully and the checksum passed. The temperature and humidity values should be valid.

◆ isValidChecksum()

bool DHTSample::isValidChecksum ( ) const

Returns true if the checksum in bytes is valid.

You normally should check isSuccess() since that will only be set if the checksum is valid and normally don't need to call this directly.


The documentation for this class was generated from the following files: