Skip to content
Snippets Groups Projects
Commit 55d18c0b authored by Juerg Beringer's avatar Juerg Beringer Committed by Elisabetta Pianori
Browse files

Support HYT271 sensor

parent 3cb8a51c
No related branches found
No related tags found
6 merge requests!308Bring main and devel back in sync,!300playing with fixing divergence between devel and main,!287Updates for Julabo Chiller,!285Julabo Chiller Added with Fixed Pipeline Compatibility,!269Merge devel into main: largest change is code formatting checker and enforcement in CI,!203Support HYT271 sensor
...@@ -31,6 +31,7 @@ target_sources(DevCom ...@@ -31,6 +31,7 @@ target_sources(DevCom
HIH4000.cpp HIH4000.cpp
HTS221.cpp HTS221.cpp
SHT85.cpp SHT85.cpp
HYT271.cpp
Si7021.cpp Si7021.cpp
NTCSensor.cpp NTCSensor.cpp
PtSensor.cpp PtSensor.cpp
......
#include "HYT271.h"
#include "DeviceComRegistry.h"
REGISTER_DEVCOM(HYT271, ClimateSensor)
#include <unistd.h>
#include <math.h>
#include "NotSupportedException.h"
#include "ChecksumException.h"
HYT271::HYT271(std::shared_ptr<I2CCom> i2c)
: m_i2c(i2c)
{ }
HYT271::~HYT271()
{ }
void HYT271::init()
{ }
void HYT271::reset()
{ }
void HYT271::read()
{
m_i2c->write_reg8(0x00); // Send any value to start measurement
usleep(120e3); // Conversion time is between 60ms to 100ms
std::vector<uint8_t> data(4);
m_i2c->read_block(data);
if ((data[0] & 0x40) != 0) {
// Got no new data - try re-reading after waiting a bit longer
usleep(200e3);
m_i2c->read_block(data);
}
if ((data[0] & 0x40) != 0) {
// Something is wrong
throw ComIOException("failed to read new data from HYT271 sensor");
}
m_humidity = ((data[0] & 0x3f) << 8 | data[1]) * (100.0 / (pow(2,14)-1.));
m_temperature = ((data[2] << 8 | (data[3] & 0xfc)) >> 2) * (165.0 / (pow(2,14)-1.)) - 40.;
}
uint HYT271::status() const
{ return m_status; }
float HYT271::temperature() const
{ return m_temperature; }
float HYT271::humidity() const
{ return m_humidity; }
float HYT271::pressure() const
{ throw NotSupportedException("HYT271 does not have a pressure sensor"); return 0; }
#ifndef HYT271_H
#define HYT271_H
#include "ClimateSensor.h"
#include "I2CCom.h"
#include "ComIOException.h"
#include <memory>
/**
* The HYT271 climate sensor.
* [Datasheet](https://www.ist-ag.com/sites/default/files/DHHYT271_E.pdf)
*/
class HYT271 : public ClimateSensor
{
public:
HYT271(std::shared_ptr<I2CCom> i2c);
virtual ~HYT271();
virtual void init();
virtual void reset();
virtual void read();
virtual unsigned status() const;
virtual float temperature() const;
virtual float humidity() const;
virtual float pressure() const;
private:
std::shared_ptr<I2CCom> m_i2c;
int m_status;
float m_temperature;
float m_humidity;
};
#endif // HYT271_H
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "HTS221.h" #include "HTS221.h"
#include "Si7021.h" #include "Si7021.h"
#include "SHT85.h" #include "SHT85.h"
#include "HYT271.h"
#include "HIH4000.h" #include "HIH4000.h"
#include "HIH6130.h" #include "HIH6130.h"
...@@ -1164,6 +1165,10 @@ void register_devcom(py::module& m) { ...@@ -1164,6 +1165,10 @@ void register_devcom(py::module& m) {
.def(py::init<std::shared_ptr<I2CCom>>()) .def(py::init<std::shared_ptr<I2CCom>>())
.def("status", &SHT85::status); .def("status", &SHT85::status);
py::class_<HYT271, PySensor_w_status<HYT271>, ClimateSensor, std::shared_ptr<HYT271>>(m, "HYT271")
.def(py::init<std::shared_ptr<I2CCom>>())
.def("status", &HYT271::status);
py::class_<HIH4000, PySensor<HIH4000>, ClimateSensor, std::shared_ptr<HIH4000>>(m, "HIH4000") py::class_<HIH4000, PySensor<HIH4000>, ClimateSensor, std::shared_ptr<HIH4000>>(m, "HIH4000")
.def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>>()) .def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>>())
.def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>, float>()) .def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>, float>())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment