From 0ea95c21b3c3ccb2883c515b7f47cd3552d3183a Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 3 Jan 2012 10:45:03 -0800 Subject: [PATCH] Added api for reading out tmp100 x100 temps --- platform/z1/dev/tmp102.c | 30 ++++++++++++++++++------------ platform/z1/dev/tmp102.h | 5 +++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/platform/z1/dev/tmp102.c b/platform/z1/dev/tmp102.c index 724cf57a5..9bf4691d2 100644 --- a/platform/z1/dev/tmp102.c +++ b/platform/z1/dev/tmp102.c @@ -160,13 +160,8 @@ tmp102_read_temp_raw (void) return rd; } -/*---------------------------------------------------------------------------*/ -/* Simple Read temperature. Return is an integer with temperature in 1deg. precision - Return value is a signed 8 bit integer. -*/ - -int8_t -tmp102_read_temp_simple (void) +int16_t +tmp102_read_temp_x100(void) { int16_t raw = 0; int8_t rd = 0; @@ -181,9 +176,10 @@ tmp102_read_temp_simple (void) abstemp = raw; } - /* Integer part of the temperature value */ - temp_int = (abstemp >> 8) * sign; - + /* Integer part of the temperature value and percents*/ + temp_int = (abstemp >> 8) * sign * 100; + temp_int += ((abstemp & 0xff) * 100) / 0x100; + /* See test-tmp102.c on how to print values of temperature with decimals fractional part in 1/10000 of degree temp_frac = ((abstemp >>4) % 16) * 625; @@ -191,6 +187,16 @@ tmp102_read_temp_simple (void) Data could be multiplied by 64 (<< 6) to trade-off precision for speed */ - rd = (int8_t) (temp_int); - return rd; + return temp_int; +} + +/*---------------------------------------------------------------------------*/ +/* Simple Read temperature. Return is an integer with temperature in 1deg. precision + Return value is a signed 8 bit integer. +*/ + +int8_t +tmp102_read_temp_simple (void) +{ + return (int8_t) tmp102_read_temp_x100() / 100; } diff --git a/platform/z1/dev/tmp102.h b/platform/z1/dev/tmp102.h index bcaaeb556..db6fd5112 100644 --- a/platform/z1/dev/tmp102.h +++ b/platform/z1/dev/tmp102.h @@ -72,6 +72,11 @@ u16_t tmp102_read_temp_raw(); */ int8_t tmp102_read_temp_simple(); +/* Read only integer part of the temperature in 1deg. precision. + no args needed +*/ +int16_t tmp102_read_temp_x100(); + /* -------------------------------------------------------------------------- */ /* Reference definitions */ /* TMP102 slave address */