at42qt1070: code style changes

Run .clang-format on the header and source files
Add missing braces

Signed-off-by: Wouter van Verre <wouter.van.verre@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Wouter van Verre 2015-06-16 12:05:31 +01:00 committed by Mihai Tudor Panu
parent 32921ff2b1
commit f64c710c12
2 changed files with 174 additions and 163 deletions

View File

@ -38,16 +38,14 @@ AT42QT1070::AT42QT1070(int bus, uint8_t address)
m_addr = address; m_addr = address;
// setup our i2c link // setup our i2c link
if ( !(m_i2c = mraa_i2c_init(bus)) ) if (!(m_i2c = mraa_i2c_init(bus))) {
{
cerr << __FUNCTION__ << ": mraa_i2c_init() failed." << endl; cerr << __FUNCTION__ << ": mraa_i2c_init() failed." << endl;
return; return;
} }
mraa_result_t rv; mraa_result_t rv;
if ( (rv = mraa_i2c_address(m_i2c, m_addr)) != MRAA_SUCCESS) if ((rv = mraa_i2c_address(m_i2c, m_addr)) != MRAA_SUCCESS) {
{
cerr << __FUNCTION__ << ": Could not initialize i2c bus. " << endl; cerr << __FUNCTION__ << ": Could not initialize i2c bus. " << endl;
mraa_result_print(rv); mraa_result_print(rv);
return; return;
@ -56,7 +54,6 @@ AT42QT1070::AT42QT1070(int bus, uint8_t address)
m_buttonStates = false; m_buttonStates = false;
m_calibrating = false; m_calibrating = false;
m_overflow = false; m_overflow = false;
} }
AT42QT1070::~AT42QT1070() AT42QT1070::~AT42QT1070()
@ -64,12 +61,12 @@ AT42QT1070::~AT42QT1070()
mraa_i2c_stop(m_i2c); mraa_i2c_stop(m_i2c);
} }
bool AT42QT1070::writeByte(uint8_t reg, uint8_t byte) bool
AT42QT1070::writeByte(uint8_t reg, uint8_t byte)
{ {
mraa_result_t rv = mraa_i2c_write_byte_data(m_i2c, byte, reg); mraa_result_t rv = mraa_i2c_write_byte_data(m_i2c, byte, reg);
if (rv != MRAA_SUCCESS) if (rv != MRAA_SUCCESS) {
{
cerr << __FUNCTION__ << ": mraa_i2c_write_byte() failed." << endl; cerr << __FUNCTION__ << ": mraa_i2c_write_byte() failed." << endl;
mraa_result_print(rv); mraa_result_print(rv);
return false; return false;
@ -78,12 +75,12 @@ bool AT42QT1070::writeByte(uint8_t reg, uint8_t byte)
return true; return true;
} }
bool AT42QT1070::writeWord(uint8_t reg, uint16_t word) bool
AT42QT1070::writeWord(uint8_t reg, uint16_t word)
{ {
mraa_result_t rv = mraa_i2c_write_word_data(m_i2c, word, reg); mraa_result_t rv = mraa_i2c_write_word_data(m_i2c, word, reg);
if (rv != MRAA_SUCCESS) if (rv != MRAA_SUCCESS) {
{
cerr << __FUNCTION__ << ": mraa_i2c_write_word() failed." << endl; cerr << __FUNCTION__ << ": mraa_i2c_write_word() failed." << endl;
mraa_result_print(rv); mraa_result_print(rv);
return false; return false;
@ -92,28 +89,30 @@ bool AT42QT1070::writeWord(uint8_t reg, uint16_t word)
return true; return true;
} }
uint8_t AT42QT1070::readByte(uint8_t reg) uint8_t
AT42QT1070::readByte(uint8_t reg)
{ {
return mraa_i2c_read_byte_data(m_i2c, reg); return mraa_i2c_read_byte_data(m_i2c, reg);
} }
uint16_t AT42QT1070::readWord(uint8_t reg) uint16_t
AT42QT1070::readWord(uint8_t reg)
{ {
return mraa_i2c_read_word_data(m_i2c, reg); return mraa_i2c_read_word_data(m_i2c, reg);
} }
void AT42QT1070::updateState() void
AT42QT1070::updateState()
{ {
uint8_t stat = readByte(REG_DETSTATUS); uint8_t stat = readByte(REG_DETSTATUS);
// if we are calibrating, don't change anything // if we are calibrating, don't change anything
if (stat & DET_CALIBRATE) if (stat & DET_CALIBRATE) {
{
m_calibrating = true; m_calibrating = true;
return; return;
} } else {
else
m_calibrating = false; m_calibrating = false;
}
if (stat & DET_OVERFLOW) if (stat & DET_OVERFLOW)
m_overflow = true; m_overflow = true;
@ -121,25 +120,25 @@ void AT42QT1070::updateState()
m_overflow = false; m_overflow = false;
// if a touch is occurring, read the button states // if a touch is occurring, read the button states
if (stat & DET_TOUCH) if (stat & DET_TOUCH) {
{
uint8_t keys = readByte(REG_KEYSTATUS); uint8_t keys = readByte(REG_KEYSTATUS);
// high bit is reserved, filter it out // high bit is reserved, filter it out
m_buttonStates = keys & ~0x80; m_buttonStates = keys & ~0x80;
} } else {
else
m_buttonStates = 0; m_buttonStates = 0;
}
} }
bool AT42QT1070::reset() bool
AT42QT1070::reset()
{ {
// write a non-zero value to the reset register // write a non-zero value to the reset register
return writeByte(REG_RESET, 0xff); return writeByte(REG_RESET, 0xff);
} }
bool AT42QT1070::calibrate() bool
AT42QT1070::calibrate()
{ {
// write a non-zero value to the calibrate register // write a non-zero value to the calibrate register
return writeByte(REG_CALIBRATE, 0xff); return writeByte(REG_CALIBRATE, 0xff);
} }

View File

@ -32,15 +32,15 @@
#define AT42QT1070_I2C_BUS 0 #define AT42QT1070_I2C_BUS 0
#define AT42QT1070_DEFAULT_I2C_ADDR 0x1b #define AT42QT1070_DEFAULT_I2C_ADDR 0x1b
namespace upm { namespace upm
{
/** /**
* @brief Atmel AT42QT1070 QTouch sensor library * @brief Atmel AT42QT1070 QTouch sensor library
* @defgroup at42qt1070 libupm-at42qt1070 * @defgroup at42qt1070 libupm-at42qt1070
* @ingroup seeed i2c touch * @ingroup seeed i2c touch
*/ */
/** /**
* @library at42qt1070 * @library at42qt1070
* @sensor at42qt1070 * @sensor at42qt1070
* @comname AT42QT1070 QTouch Sensor * @comname AT42QT1070 QTouch Sensor
@ -59,11 +59,12 @@ namespace upm {
* @image html at42qt1070.jpg * @image html at42qt1070.jpg
* @snippet at42qt1070.cxx Interesting * @snippet at42qt1070.cxx Interesting
*/ */
class AT42QT1070 { class AT42QT1070
{
public: public:
// registers // registers
typedef enum { REG_CHIPID = 0, typedef enum {
REG_CHIPID = 0,
REG_FWVERS = 1, REG_FWVERS = 1,
REG_DETSTATUS = 2, // detection status REG_DETSTATUS = 2, // detection status
@ -131,7 +132,8 @@ namespace upm {
} AT42QT1070_REG_T; } AT42QT1070_REG_T;
// detection register bits // detection register bits
typedef enum { DET_TOUCH = 0x01, typedef enum {
DET_TOUCH = 0x01,
// 0x02-0x20 reserved // 0x02-0x20 reserved
DET_OVERFLOW = 0x40, DET_OVERFLOW = 0x40,
DET_CALIBRATE = 0x80 DET_CALIBRATE = 0x80
@ -199,14 +201,22 @@ namespace upm {
* *
* @return true if overflow indicated * @return true if overflow indicated
*/ */
bool isOverflowed() { return m_overflow; }; bool
isOverflowed()
{
return m_overflow;
};
/** /**
* return the calibrating indicator * return the calibrating indicator
* *
* @return true if calibration is in progress * @return true if calibration is in progress
*/ */
bool isCalibrating() { return m_calibrating; }; bool
isCalibrating()
{
return m_calibrating;
};
/** /**
* Issue a reset command * Issue a reset command
@ -227,7 +237,11 @@ namespace upm {
* *
* @returns the button states * @returns the button states
*/ */
uint8_t getButtons() { return m_buttonStates; }; uint8_t
getButtons()
{
return m_buttonStates;
};
private: private:
uint8_t m_buttonStates; uint8_t m_buttonStates;
@ -236,7 +250,5 @@ namespace upm {
mraa_i2c_context m_i2c; mraa_i2c_context m_i2c;
uint8_t m_addr; uint8_t m_addr;
}; };
} }