Skip to content

Commit 2a75f7a

Browse files
committed
Merge branch 'add-offline-drivers-2025-04-04' into latest-fixes-20250506
2 parents 0887141 + 1617c18 commit 2a75f7a

File tree

7 files changed

+209
-6
lines changed

7 files changed

+209
-6
lines changed

.github/workflows/build-clang-doxy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ jobs:
523523
run: |
524524
git clone --quiet https://github.com/pstolarz/OneWireNg.git /home/runner/Arduino/libraries/OneWireNg
525525
git clone --quiet https://github.com/pstolarz/Arduino-Temperature-Control-Library.git /home/runner/Arduino/libraries/Arduino-Temperature-Control-Library
526-
git clone --quiet https://github.com/brentru/Adafruit_SPIFlash.git /home/runner/Arduino/libraries/Adafruit_SPIFlash
527526
git clone --quiet https://github.com/adafruit/Adafruit_TinyUSB_Arduino /home/runner/Arduino/libraries/Adafruit_TinyUSB_Arduino
528527
- name: Download stable Nanopb
529528
id: download-nanopb

platformio.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ lib_deps =
8484

8585
; Common build environment for ESP32 platform
8686
[common:esp32]
87-
; platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
88-
; platform = https://github.com/pioarduino/platform-espressif32#develop
89-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
87+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20/platform-espressif32.zip
9088
lib_ignore = WiFiNINA, WiFi101
9189
monitor_filters = esp32_exception_decoder, time
9290
; upload_speed = 921600

src/components/i2c/controller.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
123123
const char *driver_name) -> drvBase * {
124124
return new drvHtu21d(i2c, addr, mux_channel, driver_name);
125125
}},
126+
{"htu31d",
127+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
128+
const char *driver_name) -> drvBase * {
129+
return new drvHtu31d(i2c, addr, mux_channel, driver_name);
130+
}},
126131
{"ina219",
127132
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
128133
const char *driver_name) -> drvBase * {
@@ -223,6 +228,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
223228
const char *driver_name) -> drvBase * {
224229
return new drvScd30(i2c, addr, mux_channel, driver_name);
225230
}},
231+
{"sgp30",
232+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
233+
const char *driver_name) -> drvBase * {
234+
return new drvSgp30(i2c, addr, mux_channel, driver_name);
235+
}},
226236
{"sgp40",
227237
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
228238
const char *driver_name) -> drvBase * {

src/components/i2c/controller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "drivers/drvDs2484.h"
3131
#include "drivers/drvEns160.h"
3232
#include "drivers/drvHts221.h"
33+
#include "drivers/drvHtu31d.h"
3334
#include "drivers/drvHtu21d.h"
3435
#include "drivers/drvIna219.h"
3536
#include "drivers/drvLc709203f.h"
@@ -50,6 +51,7 @@
5051
#include "drivers/drvScd30.h"
5152
#include "drivers/drvScd4x.h"
5253
#include "drivers/drvSen5x.h"
54+
#include "drivers/drvSgp30.h"
5355
#include "drivers/drvSgp40.h"
5456
#include "drivers/drvSht3x.h"
5557
#include "drivers/drvSht4x.h"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*!
2+
* @file drvHtu31d.h
3+
*
4+
* Device driver for an HTU31D Humidity and Temperature sensor.
5+
*/
6+
7+
#ifndef DRV_HTU31D_H
8+
#define DRV_HTU31D_H
9+
10+
#include "drvBase.h"
11+
#include <Adafruit_HTU31D.h>
12+
13+
/**************************************************************************/
14+
/*!
15+
@brief Class that provides a sensor driver for the HTU31D humidity and
16+
temperature sensor.
17+
*/
18+
/**************************************************************************/
19+
class drvHtu31d : public drvBase {
20+
21+
public:
22+
/*******************************************************************************/
23+
/*!
24+
@brief Constructor for an HTU31D sensor.
25+
@param i2c
26+
The I2C interface.
27+
@param sensorAddress
28+
7-bit device address.
29+
@param mux_channel
30+
The I2C multiplexer channel.
31+
@param driver_name
32+
The name of the driver.
33+
*/
34+
/*******************************************************************************/
35+
drvHtu31d(TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
36+
const char *driver_name)
37+
: drvBase(i2c, sensorAddress, mux_channel, driver_name) {
38+
// Initialization handled by drvBase constructor
39+
}
40+
41+
/*******************************************************************************/
42+
/*!
43+
@brief Destructor for an HTU31D sensor.
44+
*/
45+
/*******************************************************************************/
46+
~drvHtu31d() { delete _htu31d; }
47+
48+
/*******************************************************************************/
49+
/*!
50+
@brief Initializes the HTU31D sensor and begins I2C.
51+
@returns True if initialized successfully, False otherwise.
52+
53+
*/
54+
/*******************************************************************************/
55+
bool begin() {
56+
// attempt to initialize the HTU31D using the I2C interface
57+
_htu31d = new Adafruit_HTU31D();
58+
return _htu31d->begin(_address, _i2c);
59+
}
60+
61+
/*******************************************************************************/
62+
/*!
63+
@brief Gets the HTU31D's current temperature.
64+
@param tempEvent
65+
Pointer to an Adafruit_Sensor event.
66+
@returns True if the temperature was obtained successfully, False
67+
otherwise.
68+
*/
69+
/*******************************************************************************/
70+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
71+
return _htu31d->getEvent(nullptr, tempEvent);
72+
}
73+
74+
/*******************************************************************************/
75+
/*!
76+
@brief Gets the HTU31D's current humidity.
77+
@param humidEvent
78+
Pointer to an Adafruit_Sensor event.
79+
@returns True if the humidity was obtained successfully, False
80+
otherwise.
81+
*/
82+
/*******************************************************************************/
83+
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
84+
return _htu31d->getEvent(humidEvent, nullptr);
85+
}
86+
87+
protected:
88+
Adafruit_HTU31D *_htu31d; ///< Pointer to an HTU31D object
89+
};
90+
#endif // DRV_HTU31D_H

src/components/i2c/drivers/drvSgp30.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*!
2+
* @file drvSgp30.h
3+
*
4+
* Device driver for the SGP30 VOC/gas 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_SGP30_H
17+
#define DRV_SGP30_H
18+
19+
#include "drvBase.h"
20+
#include <Adafruit_SGP30.h>
21+
#include <Wire.h>
22+
23+
/**************************************************************************/
24+
/*!
25+
@brief Class that provides a driver interface for the SGP30 sensor.
26+
*/
27+
/**************************************************************************/
28+
class drvSgp30 : public drvBase {
29+
public:
30+
/*******************************************************************************/
31+
/*!
32+
@brief Constructor for a SGP30 sensor.
33+
@param i2c
34+
The I2C interface.
35+
@param sensorAddress
36+
7-bit device address.
37+
@param mux_channel
38+
The I2C multiplexer channel.
39+
@param driver_name
40+
The name of the driver.
41+
*/
42+
/*******************************************************************************/
43+
drvSgp30(TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
44+
const char *driver_name)
45+
: drvBase(i2c, sensorAddress, mux_channel, driver_name) {
46+
// Initialization handled by drvBase constructor
47+
}
48+
49+
/*******************************************************************************/
50+
/*!
51+
@brief Initializes the SGP30 sensor and begins I2C.
52+
@returns True if initialized successfully, False otherwise.
53+
*/
54+
/*******************************************************************************/
55+
bool begin() override {
56+
_sgp30 = new Adafruit_SGP30();
57+
if (!_sgp30->begin(_i2c)) {
58+
return false;
59+
}
60+
61+
// TODO: update to use setCalibration() and pass in temp/humidity
62+
63+
return true;
64+
}
65+
66+
/*******************************************************************************/
67+
/*!
68+
@brief Gets the sensor's current equivalent/estimated CO2 value.
69+
@param co2Event
70+
Pointer to an Adafruit_Sensor event.
71+
@returns True if the temperature was obtained successfully, False
72+
otherwise.
73+
*/
74+
/*******************************************************************************/
75+
bool getEventECO2(sensors_event_t *co2Event) {
76+
bool result = _sgp30->IAQmeasure();
77+
if (result) {
78+
co2Event->eCO2 = (float)_sgp30->eCO2;
79+
}
80+
return result;
81+
}
82+
83+
/*******************************************************************************/
84+
/*!
85+
@brief Gets the SGP30's current VOC reading.
86+
@param vocIndexEvent
87+
Adafruit Sensor event for VOC Index (1-500, 100 is normal)
88+
@returns True if the sensor value was obtained successfully, False
89+
otherwise.
90+
*/
91+
/*******************************************************************************/
92+
bool getEventVOCIndex(sensors_event_t *vocIndexEvent) {
93+
bool result = _sgp30->IAQmeasure();
94+
if (result) {
95+
vocIndexEvent->voc_index = (float)_sgp30->TVOC;
96+
}
97+
return result;
98+
}
99+
100+
protected:
101+
Adafruit_SGP30 *_sgp30; ///< SGP30 driver object
102+
};
103+
104+
#endif // WipperSnapper_I2C_Driver_SGP30

src/components/i2c/drivers/drvSgp40.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class drvSgp40 : public drvBase {
9999
}
100100

101101
protected:
102-
Adafruit_SGP40 *_sgp40; ///< SEN5X driver object
102+
Adafruit_SGP40 *_sgp40; ///< SGP40 driver object
103103
};
104104

105-
#endif // WipperSnapper_I2C_Driver_SEN5X
105+
#endif // WipperSnapper_I2C_Driver_SGP40

0 commit comments

Comments
 (0)