diff --git a/src/at42qt1070/at42qt1070.cxx b/src/at42qt1070/at42qt1070.cxx index fed9f382..9452f2f4 100644 --- a/src/at42qt1070/at42qt1070.cxx +++ b/src/at42qt1070/at42qt1070.cxx @@ -62,6 +62,32 @@ AT42QT1070::AT42QT1070(int bus, uint8_t address) m_overflow = false; } +AT42QT1070::AT42QT1070(std::string initStr) : mraaIo(initStr) +{ + mraa_io_descriptor* descs = mraaIo.getMraaDescriptors(); + + if(!descs->i2cs) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_init() failed"); + } + else { + if( !(m_i2c = descs->i2cs[0]) ) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_init() failed"); + + } + } + + if (readChipID() != 0x2E) { + throw std::runtime_error("Chip ID does not match the expected value (2Eh)"); + } + + m_buttonStates = 0; + m_calibrating = false; + m_overflow = false; + +} + AT42QT1070::~AT42QT1070() { mraa_i2c_stop(m_i2c); diff --git a/src/at42qt1070/at42qt1070.hpp b/src/at42qt1070/at42qt1070.hpp index 825ebdd3..19b239c5 100644 --- a/src/at42qt1070/at42qt1070.hpp +++ b/src/at42qt1070/at42qt1070.hpp @@ -28,6 +28,7 @@ #include #include +#include #define AT42QT1070_I2C_BUS 0 #define AT42QT1070_DEFAULT_I2C_ADDR 0x1b @@ -149,6 +150,13 @@ class AT42QT1070 */ AT42QT1070(int bus, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR); + /** + * Instantiates AT42QT1070 QTouch Sensor based on a given string. + * + * @param initStr string containing specific information for AT42QT1070 initialization. + */ + AT42QT1070(std::string initStr); + /** * AT42QT1070 destructor */ @@ -309,6 +317,7 @@ class AT42QT1070 bool m_overflow; mraa_i2c_context m_i2c; + mraa::MraaIo mraaIo; uint8_t m_addr; }; }