Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:7e1b9c699bac, committed 2014-07-20
- Comitter:
- kunichiko
- Date:
- Sun Jul 20 14:25:01 2014 +0000
- Commit message:
- Initial version.
Changed in this revision
KuADT7410.cpp | Show annotated file Show diff for this revision Revisions of this file |
KuADT7410.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 7e1b9c699bac KuADT7410.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KuADT7410.cpp Sun Jul 20 14:25:01 2014 +0000 @@ -0,0 +1,40 @@ +#include "KuADT7410.h" + +const int KU_ADT7410_TEMP_REG_ADDR = 0x00; +const int KU_ADT7410_STATUS_REG_ADDR = 0x02; +const int KU_ADT7410_CONFIG_REG_ADDR = 0x03; +const int KU_ADT7410_RESET_REG_ADDR = 0x2F; + +KuADT7410::KuADT7410(I2C &i2c_, int i2c_address_) : i2c(i2c_), i2c_address(i2c_address_) +{ + reset(); +} + +KuADT7410::~KuADT7410() +{ +} + +float KuADT7410::get_temp() { + char wdata[1] = {KU_ADT7410_TEMP_REG_ADDR}; + i2c.write(i2c_address, wdata, 1); + char rdata[2] = {0,0}; + i2c.read(i2c_address, rdata, 2); + int16_t temp_raw = (rdata[0] << 8) | rdata[1]; + temp_raw /= 8; + return temp_raw / 16.0f; +} + +unsigned char KuADT7410::get_status() { + char wdata[1] = {KU_ADT7410_STATUS_REG_ADDR}; + i2c.write(i2c_address, wdata, 1); + char rdata[1] = {0}; + i2c.read(i2c_address, rdata, 1); + return rdata[0]; +} + +void KuADT7410::reset() +{ + char data[1] = {KU_ADT7410_RESET_REG_ADDR}; + i2c.write(i2c_address, data, 1); + wait(0.25); +} \ No newline at end of file
diff -r 000000000000 -r 7e1b9c699bac KuADT7410.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KuADT7410.h Sun Jul 20 14:25:01 2014 +0000 @@ -0,0 +1,44 @@ +#ifndef KU_ADT7410_H +#define KU_ADT7410_H + +#include "mbed.h" + +/** + * A library for ADT7410 I2C connecting temperature sensor module. + */ +class KuADT7410 { +private: + I2C &i2c; + int i2c_address; + +public: + + /** + * Constractor of ADT7410 driver. + * @param i2c I2C object + * @param i2c_address Target's I2C address (LSB is used for R/W flag). + */ + explicit KuADT7410(I2C &i2c, int i2c_address = 0x48 << 1); + + /** + * Destractor + */ + ~KuADT7410(); + + /** + * Reset target device. + */ + void reset(); + + /** + * Get temperature + */ + float get_temp(); + + /** + * Get status + */ + unsigned char get_status(); +}; + +#endif \ No newline at end of file