-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add BMP388 / BMP3xx #461
Merged
Merged
Add BMP388 / BMP3xx #461
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
553d2b8
Add BMP388 / BMP3xx
tyeth 6ab38f2
CLang formatting
tyeth 8b78bd3
Rename file
tyeth 365d1d2
Refactor BMP380 to BMP3xx to match base driver
tyeth d06ca00
Rename symbol to match generic driver name
tyeth a69b1e8
Update description in file header
tyeth 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 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 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 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 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
131 changes: 131 additions & 0 deletions
131
src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP3XX.h
This file contains 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,131 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_BMP3XX.h | ||
* | ||
* Device driver for an AHT Humidity and Temperature sensor. | ||
tyeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* 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 2023 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_BMP3XX_H | ||
#define WipperSnapper_I2C_Driver_BMP3XX_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_BMP3XX.h> | ||
|
||
#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a sensor driver for the BMP3XX temperature | ||
and pressure sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_BMP3XX : public WipperSnapper_I2C_Driver { | ||
|
||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for an BMP3XX sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_BMP3XX(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an BMP3XX sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_BMP3XX() { delete _bmp3xx; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the BMP3XX sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_bmp3xx = new Adafruit_BMP3XX(); | ||
// attempt to initialize BMP3XX | ||
if (!_bmp3xx->begin_I2C(_sensorAddress, _i2c)) | ||
return false; | ||
|
||
// Set up oversampling and filter initialization | ||
_bmp3xx->setTemperatureOversampling(BMP3_OVERSAMPLING_8X); | ||
_bmp3xx->setPressureOversampling(BMP3_OVERSAMPLING_4X); | ||
_bmp3xx->setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3); | ||
_bmp3xx->setOutputDataRate(BMP3_ODR_50_HZ); | ||
|
||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the BMP3XX'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) { | ||
if (!_bmp3xx->performReading()) | ||
return false; | ||
tempEvent->temperature = _bmp3xx->temperature; | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@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) { | ||
if (!_bmp3xx->performReading()) | ||
return false; | ||
pressureEvent->pressure = _bmp3xx->pressure / 100.0F; | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Reads a the BMP3XX's altitude sensor into an event. | ||
@param altitudeEvent | ||
Pointer to an adafruit sensor event. | ||
@returns True if the sensor event was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAltitude(sensors_event_t *altitudeEvent) { | ||
if (!_bmp3xx->performReading()) | ||
return false; | ||
// TODO: update once we add an altitude sensor type | ||
// see https://github.com/adafruit/Adafruit_Sensor/issues/52 | ||
altitudeEvent->data[0] = _bmp3xx->readAltitude(SEALEVELPRESSURE_HPA); | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_BMP3XX *_bmp3xx; ///< BMP3XX object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_BMP3XX |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too and don;'t forget to change _i2c.cpp as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) Read my slightly slow mind, just committing and retesting now