Skip to content

Commit 33b202e

Browse files
committed
Add OMRON D6T-1A
1 parent 5546bd0 commit 33b202e

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

src/components/i2c/controller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ static const std::map<std::string, FnCreateI2CSensorDriver> I2cFactorySensor = {
103103
const char *driver_name) -> drvBase * {
104104
return new drvDps310(i2c, addr, mux_channel, driver_name);
105105
}},
106+
{"d6t1a",
107+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
108+
const char *driver_name) -> drvBase * {
109+
return new drvD6t1a(i2c, addr, mux_channel, driver_name);
110+
}},
106111
{"ds2484",
107112
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
108113
const char *driver_name) -> drvBase * {
@@ -346,6 +351,7 @@ static const std::map<std::string, FnCreateI2CSensorDriver> I2cFactorySensor = {
346351

347352
static const std::unordered_map<uint16_t, std::vector<const char *>>
348353
map_address_to_drivers = {
354+
{0x0A, {"d6t1a"}},
349355
{0x0B, {"lc709203f"}},
350356
{0x12, {"pmsa003i"}},
351357
{0x13, {"vncl4020"}},

src/components/i2c/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "drivers/drvBmp280.h"
2828
#include "drivers/drvBmp3xx.h"
2929
#include "drivers/drvDps310.h"
30+
#include "drivers/drvD6t1a.h"
3031
#include "drivers/drvDs2484.h"
3132
#include "drivers/drvEns160.h"
3233
#include "drivers/drvHts221.h"

src/components/i2c/drivers/drvD6t1a.h

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*!
2+
* @file drvD6t1a.h
3+
*
4+
* Device driver for the OMRON D6T-1A Non-contact Thermal sensor.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2025 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
16+
#ifndef DRV_D6T1A_H
17+
#define DRV_D6T1A_H
18+
#include "drvBase.h"
19+
#include <OmronD6T.h>
20+
21+
/*!
22+
@brief Class that provides a sensor driver for the D6T1A temperature sensor.
23+
*/
24+
class drvD6t1a : public drvBase {
25+
26+
public:
27+
/*!
28+
@brief Constructor for a D6T1A sensor.
29+
@param i2c
30+
The I2C interface.
31+
@param sensorAddress
32+
7-bit device address.
33+
@param mux_channel
34+
The I2C multiplexer channel.
35+
@param driver_name
36+
The name of the driver.
37+
*/
38+
drvD6t1a(TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
39+
const char *driver_name)
40+
: drvBase(i2c, sensorAddress, mux_channel, driver_name) {
41+
_i2c = i2c;
42+
_address = sensorAddress;
43+
_i2c_mux_channel = mux_channel;
44+
strncpy(_name, driver_name, sizeof(_name) - 1);
45+
_name[sizeof(_name) - 1] = '\0';
46+
_deviceTemp = NAN;
47+
_objectTemp = NAN;
48+
_lastRead = 0;
49+
_d6t1a = nullptr;
50+
}
51+
52+
/*!
53+
@brief Destructor for a D6T1A sensor.
54+
*/
55+
~drvD6t1a() { delete _d6t1a; }
56+
57+
/*!
58+
@brief Initializes the D6T1A sensor and begins I2C.
59+
@returns True if initialized successfully, False otherwise.
60+
*/
61+
bool begin() override {
62+
_d6t1a = new OmronD6T(OmronD6T::D6T_1A, _i2c);
63+
if (!_d6t1a->begin(_address))
64+
return false;
65+
return true;
66+
}
67+
68+
/*!
69+
@brief Checks if sensor was read within last 200ms.
70+
@returns True if the sensor was recently read, False otherwise.
71+
*/
72+
bool HasBeenReadInLast200ms() {
73+
return _lastRead != 0 && (millis() - _lastRead < 200);
74+
}
75+
76+
/*!
77+
@brief Reads the sensor.
78+
@returns True if the sensor was read successfully, False otherwise.
79+
*/
80+
bool ReadSensorData() {
81+
if (HasBeenReadInLast200ms())
82+
return true;
83+
84+
_d6t1a->read();
85+
_deviceTemp = (float)_d6t1a->ambientTempC();
86+
_objectTemp = (float)_d6t1a->objectTempC(0, 0);
87+
_lastRead = millis();
88+
return true;
89+
}
90+
91+
/*!
92+
@brief Gets the D6T1A's current ambient temperature.
93+
@param tempEvent
94+
Pointer to an Adafruit_Sensor event.
95+
@returns True if the temperature was obtained successfully, False otherwise.
96+
*/
97+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
98+
if (ReadSensorData() && !isnan(_deviceTemp)) {
99+
tempEvent->temperature = _deviceTemp;
100+
return true;
101+
}
102+
return false;
103+
}
104+
105+
/*!
106+
@brief Gets the D6T1A's object temperature.
107+
@param tempEvent
108+
Pointer to an Adafruit_Sensor event.
109+
@returns True if the temperature was obtained successfully, False otherwise.
110+
*/
111+
bool getEventObjectTemp(sensors_event_t *tempEvent) {
112+
if (ReadSensorData() && !isnan(_objectTemp)) {
113+
tempEvent->temperature = _objectTemp;
114+
return true;
115+
}
116+
return false;
117+
}
118+
119+
void ConfigureDefaultSensorTypes() override {
120+
_default_sensor_types_count = 2;
121+
_default_sensor_types[0] =
122+
wippersnapper_sensor_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE;
123+
_default_sensor_types[1] =
124+
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE;
125+
}
126+
127+
protected:
128+
float _deviceTemp; ///< Device temperature in Celsius
129+
float _objectTemp; ///< Object temperature in Celsius
130+
uint32_t _lastRead; ///< Last time the sensor was read in milliseconds
131+
OmronD6T *_d6t1a; ///< D6T1A object
132+
};
133+
134+
#endif // DRV_D6T1A_H

0 commit comments

Comments
 (0)