-
Notifications
You must be signed in to change notification settings - Fork 54
add(component): SPA06-003 Temp+Pressure sensor #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/components/i2c/drivers/WipperSnapper_I2C_Driver_SPA06_003.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_SPA06_003.h | ||
* | ||
* Device driver for an SPA06-003 Pressure and Temperature sensor. | ||
* | ||
* Adafruit invests time and resources providing this open source code, | ||
* please support Adafruit and open-source hardware by purchasing | ||
* products from Adafruit! | ||
* | ||
* Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_SPA06_003_H | ||
#define WipperSnapper_I2C_Driver_SPA06_003_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_SPA06_003.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a sensor driver for the SPA06-003 PT sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_SPA06_003 : public WipperSnapper_I2C_Driver { | ||
|
||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for an SPA06-003 sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_SPA06_003(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an SPA06-003 sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_SPA06_003() { delete _spa06_003; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the SPA06-003 sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_spa06_003 = new Adafruit_SPA06_003(); | ||
// attempt to initialize SPA06-003 | ||
if (!_spa06_003->begin(_sensorAddress, _i2c)) | ||
return false; | ||
|
||
_spa06_003_temp = _spa06_003->getTemperatureSensor(); | ||
_spa06_003_pressure = _spa06_003->getPressureSensor(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the SPA06-003's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemp(sensors_event_t *tempEvent) { | ||
bool success = false; | ||
if (_spa06_003_temp == NULL) | ||
return false; | ||
success = _spa06_003_temp->getEvent(tempEvent); | ||
if (tempEvent->temperature > 85.0 || tempEvent->temperature < -40.0) { | ||
success = false; | ||
} | ||
return success; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Reads a pressure sensor and converts | ||
the reading into the expected SI unit. | ||
@param pressureEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the sensor event was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventPressure(sensors_event_t *pressureEvent) { | ||
bool success = false; | ||
if (_spa06_003_pressure == NULL || _spa06_003->isPresDataReady() == false) { | ||
return false; | ||
} | ||
success = _spa06_003_pressure->getEvent(pressureEvent); | ||
if (pressureEvent->pressure < 300.0 || pressureEvent->pressure > 1100.0) { | ||
success = false; | ||
} | ||
return success; | ||
} | ||
|
||
protected: | ||
Adafruit_SPA06_003 *_spa06_003 = nullptr; ///< SPA06-003 object | ||
Adafruit_Sensor *_spa06_003_temp = { | ||
tyeth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
0}; ///< Ptr to an adafruit_sensor representing the temperature | ||
Adafruit_Sensor *_spa06_003_pressure = { | ||
0}; ///< Ptr to an adafruit_sensor representing the pressure | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_SPA06_003_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.