-
Notifications
You must be signed in to change notification settings - Fork 11
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
T6713 CO2 Sensor Driver #355
base: master
Are you sure you want to change the base?
Changes from 3 commits
086f3e5
cf72f6d
cba9a50
9e5f480
9b64972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "T6713.h" | ||
|
||
/** | ||
* @brief Destroy the T6713 object. | ||
* As of now, the destructor does not need anything. | ||
* | ||
*/ | ||
T6713::~T6713() {} | ||
|
||
/** | ||
* @brief Gets the PPM (CO2 level) reading of the sensor | ||
* | ||
* @param outValue Reference to the int variable to be changed to the PPM value | ||
* @return mbed_error_status_t MBED_SUCCESS if the reading was successful, | ||
* otherwise the error status of the reading | ||
*/ | ||
mbed_error_status_t T6713::readPPM(int & ppmOut) { | ||
char data[4]; | ||
|
||
if (this->i2c.write(this->addr, READ_CO2_COMMAND, 5)) { | ||
return MBED_ERROR_WRITE_FAILED; | ||
} | ||
|
||
if (this->i2c.read(this->addr, data, 4)) { | ||
return MBED_ERROR_READ_FAILED; | ||
} | ||
|
||
ppmOut = (((data[2] & 0x3F) << 8) | data[3]); | ||
return MBED_SUCCESS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef _LIBRARY_DRIVER_T6713_H_ | ||
#define _LIBRARY_DRIVER_T6713_H_ | ||
|
||
// See | ||
// http://www.co2meters.com/Documentation/Manuals/Manual-AMP-0002-T6713-Sensor.pdf | ||
// for more detailed documentation of the sensor itself | ||
|
||
#include <mbed.h> | ||
|
||
// T6713 CO2 Sensor I2C default slave address | ||
const uint8_t DEFAULT_T6713_SLAVE_ADDRESS = 0x15 << 1; | ||
// Same command found in the T67XX CO2 Sensor Module documentation, see pg. 29 | ||
static const char READ_CO2_COMMAND[5] = {0x04, 0x13, 0x8B, 0x00, 0x01}; | ||
|
||
class T6713 { | ||
public: | ||
T6713(const T6713 &) = delete; | ||
T6713 & operator=(const T6713 &) = delete; | ||
|
||
/** | ||
* @brief Construct a new T6713 object | ||
* | ||
* @param i2c The I2C with which the driver works | ||
* @param addr The slave address of the sensor on the i2c, defaults to | ||
* DEFAULT_T6713_SLAVE_ADDRESS | ||
*/ | ||
T6713(I2C & i2c, uint8_t addr = DEFAULT_T6713_SLAVE_ADDRESS) : | ||
i2c(i2c), addr(addr) {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the constructor defined here and not the source? |
||
|
||
~T6713(); | ||
|
||
/** | ||
* @brief Gets the PPM (CO2 level) reading of the sensor | ||
* | ||
* @param outValue Reference to the int variable to be changed to the PPM | ||
* value | ||
* @return mbed_error_status_t MBED_SUCCESS if the reading was successful, | ||
* otherwise the error status of the reading | ||
*/ | ||
mbed_error_status_t readPPM(int & outValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use uint32_t for unsigned 32b integers. Aka specify the number of bits |
||
|
||
private: | ||
/** | ||
* @brief The I2C with which the driver works to read the sensor values | ||
* | ||
*/ | ||
I2C & i2c; | ||
/** | ||
* @brief The slave address of the sensor to which the I2C should read/write | ||
* | ||
*/ | ||
uint8_t addr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the address configurable? If so, make it an enum class of the allowable values, if not make it a static const member. |
||
}; | ||
|
||
#endif /* _LIBRARY_DRIVER_T6713_H_ */ |
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.
Have these as part of the class instead of the default namespace