A library for ADT7410 I2C connecting temperature sensor module.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KuADT7410.cpp Source File

KuADT7410.cpp

00001 #include "KuADT7410.h"
00002 
00003 const int KU_ADT7410_TEMP_REG_ADDR = 0x00;
00004 const int KU_ADT7410_STATUS_REG_ADDR = 0x02;
00005 const int KU_ADT7410_CONFIG_REG_ADDR = 0x03;
00006 const int KU_ADT7410_RESET_REG_ADDR = 0x2F;
00007 
00008 KuADT7410::KuADT7410(I2C &i2c_, int i2c_address_) : i2c(i2c_), i2c_address(i2c_address_)
00009 {
00010     reset();
00011 }
00012 
00013 KuADT7410::~KuADT7410()
00014 {
00015 }
00016 
00017 float KuADT7410::get_temp() {
00018     char wdata[1] = {KU_ADT7410_TEMP_REG_ADDR};
00019     i2c.write(i2c_address, wdata, 1);
00020     char rdata[2] = {0,0};
00021     i2c.read(i2c_address, rdata, 2);
00022     int16_t temp_raw = (rdata[0] << 8) | rdata[1];
00023     temp_raw /= 8;
00024     return temp_raw / 16.0f;
00025 }
00026 
00027 unsigned char KuADT7410::get_status() {
00028     char wdata[1] = {KU_ADT7410_STATUS_REG_ADDR};
00029     i2c.write(i2c_address, wdata, 1);
00030     char rdata[1] = {0};
00031     i2c.read(i2c_address, rdata, 1);
00032     return rdata[0];
00033 }
00034 
00035 void KuADT7410::reset()
00036 {
00037     char data[1] = {KU_ADT7410_RESET_REG_ADDR};
00038     i2c.write(i2c_address, data, 1);
00039     wait(0.25);
00040 }