Skip to content

Commit 4f5323f

Browse files
Copilottyeth
andcommitted
Add TMP119 I2C temperature sensor driver (Claude_Opus4.6)
New driver WipperSnapper_I2C_Driver_TMP119.h with read-caching pattern, explicit configuration pinning (continuous mode, 8x averaging), and registration in WipperSnapper_I2C.h/.cpp. TMP119 uses the existing Adafruit_TMP117 library (no new deps needed). Companion Wippersnapper_Components PR needed for component definition: - components/i2c/tmp119/definition.json - components/i2c/tmp119/image.jpg Co-authored-by: tyeth <6692083+tyeth@users.noreply.github.com> Agent-Logs-Url: https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/sessions/d1416072-178e-41c3-978c-dce3bda05fbe
1 parent e80b041 commit 4f5323f

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
657657
_tmp117->configureDriver(msgDeviceInitReq);
658658
drivers.push_back(_tmp117);
659659
WS_DEBUG_PRINTLN("TMP117 Initialized Successfully!");
660+
} else if (strcmp("tmp119", msgDeviceInitReq->i2c_device_name) == 0) {
661+
_tmp119 = new WipperSnapper_I2C_Driver_TMP119(this->_i2c, i2cAddress);
662+
if (!_tmp119->begin()) {
663+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize TMP119!");
664+
_busStatusResponse =
665+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
666+
return false;
667+
}
668+
_tmp119->configureDriver(msgDeviceInitReq);
669+
drivers.push_back(_tmp119);
670+
WS_DEBUG_PRINTLN("TMP119 Initialized Successfully!");
660671
} else if (strcmp("tsl2591", msgDeviceInitReq->i2c_device_name) == 0) {
661672
_tsl2591 = new WipperSnapper_I2C_Driver_TSL2591(this->_i2c, i2cAddress);
662673
if (!_tsl2591->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "drivers/WipperSnapper_I2C_Driver_SPA06_003.h"
8181
#include "drivers/WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor.h"
8282
#include "drivers/WipperSnapper_I2C_Driver_TMP117.h"
83+
#include "drivers/WipperSnapper_I2C_Driver_TMP119.h"
8384
#include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
8485
#include "drivers/WipperSnapper_I2C_Driver_VCNL4020.h"
8586
#include "drivers/WipperSnapper_I2C_Driver_VCNL4040.h"
@@ -196,6 +197,7 @@ class WipperSnapper_Component_I2C {
196197
WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr;
197198
WipperSnapper_I2C_Driver_NAU7802 *_nau7802 = nullptr;
198199
WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
200+
WipperSnapper_I2C_Driver_TMP119 *_tmp119 = nullptr;
199201
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
200202
WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr;
201203
WipperSnapper_I2C_Driver_VCNL4040 *_vcnl4040 = nullptr;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_TMP119.h
3+
*
4+
* Device driver for the TMP119 high-accuracy temperature 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+
#ifndef WipperSnapper_I2C_Driver_TMP119_H
16+
#define WipperSnapper_I2C_Driver_TMP119_H
17+
18+
#include "WipperSnapper_I2C_Driver.h"
19+
#include <Adafruit_TMP119.h>
20+
21+
/**************************************************************************/
22+
/*!
23+
@brief Class that provides a driver interface for the TMP119 sensor.
24+
*/
25+
/**************************************************************************/
26+
class WipperSnapper_I2C_Driver_TMP119 : public WipperSnapper_I2C_Driver {
27+
28+
public:
29+
/*******************************************************************************/
30+
/*!
31+
@brief Constructor for a TMP119 sensor.
32+
@param i2c
33+
The I2C interface.
34+
@param sensorAddress
35+
7-bit device address.
36+
*/
37+
/*******************************************************************************/
38+
WipperSnapper_I2C_Driver_TMP119(TwoWire *i2c, uint16_t sensorAddress)
39+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
40+
_i2c = i2c;
41+
_sensorAddress = sensorAddress;
42+
}
43+
44+
/*******************************************************************************/
45+
/*!
46+
@brief Destructor for a TMP119 sensor.
47+
*/
48+
/*******************************************************************************/
49+
~WipperSnapper_I2C_Driver_TMP119() { delete _tmp119; }
50+
51+
/*******************************************************************************/
52+
/*!
53+
@brief Initializes the TMP119 sensor and begins I2C.
54+
@returns True if initialized successfully, False otherwise.
55+
*/
56+
/*******************************************************************************/
57+
bool begin() {
58+
_tmp119 = new Adafruit_TMP119();
59+
if (!_tmp119->begin((uint8_t)_sensorAddress, _i2c))
60+
return false;
61+
// Pin defaults explicitly so future library changes don't silently
62+
// alter WipperSnapper behavior.
63+
_tmp119->setMeasurementMode(TMP117_MODE_CONTINUOUS);
64+
_tmp119->setAveragedSampleCount(TMP117_AVERAGE_8X);
65+
return true;
66+
}
67+
68+
/*******************************************************************************/
69+
/*!
70+
@brief Gets the TMP119's current temperature.
71+
@param tempEvent
72+
Pointer to an Adafruit_Sensor event.
73+
@returns True if the temperature was obtained successfully, False
74+
otherwise.
75+
*/
76+
/*******************************************************************************/
77+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
78+
if (!_readSensor())
79+
return false;
80+
*tempEvent = _cachedTemp;
81+
return true;
82+
}
83+
84+
protected:
85+
Adafruit_TMP119 *_tmp119 = nullptr; ///< TMP119 driver object
86+
unsigned long _lastRead = 0; ///< Last sensor read time in ms
87+
sensors_event_t _cachedTemp = {0}; ///< Cached temperature event
88+
89+
/*******************************************************************************/
90+
/*!
91+
@brief Reads the TMP119 sensor data, caching the result so only
92+
the first call per cycle performs the I2C transaction.
93+
@returns True if sensor data is available, False otherwise.
94+
*/
95+
/*******************************************************************************/
96+
bool _readSensor() {
97+
if (_lastRead != 0 && millis() - _lastRead < 1000)
98+
return true; // use cached value
99+
if (!_tmp119->getEvent(&_cachedTemp))
100+
return false;
101+
_lastRead = millis();
102+
return true;
103+
}
104+
};
105+
106+
#endif // WipperSnapper_I2C_Driver_TMP119_H

0 commit comments

Comments
 (0)