Skip to content
Prev Previous commit
Next Next commit
Created DHT22.h and DHT22.cpp driver files for Temp/RH sensor
  • Loading branch information
Stanlist committed Feb 18, 2022
commit 4667f7fdc6add18b0ce1a92058a75e8782bcff74
32 changes: 32 additions & 0 deletions libs/sensors/include/DHT22.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "Sensor.h"
#include "mbed.h"

namespace Sensor {
class DHT22 final : public Sensor {
public:
DHT22(PinName data);

// Returns internal humidity value (and temperature? Since all transmitted at the same time...)
float read() override;

// Returns internal temperature reading *Probably irrelevant?
float alternateRead() override;

// Returns whether sensor responds to request?
bool getStatus() const override;

// irrelevant probably
[[nodiscard]] bool reset() override;

// Requests relative humidity and temperature data from sensor
[[nodiscard]] bool update() override;

private:
mutable DigitalInOut m_data;
bool updateData();

float m_humidity, m_temperature;
};
} // namespace Sensor
25 changes: 25 additions & 0 deletions libs/sensors/src/DHT22.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "DHT22.h"

using namespace Sensor;

DHT22::DHT22(PinName data) : m_data(data) {}

// Returns internal humidity value (and temperature? Since all transmitted at the same time...)
float DHT22::read() {
// Not sure what the mutex is used for, maybe ask later?
return m_humidity;
}

float DHT22::alternateRead() {
return m_temperature;
}

// bool DHT22::getStatus() {}

// bool DHT22::reset() {}

bool DHT22::update() {
// need to probably use the DigitalInOut type for getting the data from the sensor
// Setup a 2 second loop of sorts? or 80 microseconds? Refer to Arduino code
// Needs to check if 2 seconds have been passed already since last call
}