From 755258c98493d6b2267d62df099f076ca9f65f03 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@1b90f75b-8b96-4784-87c0-14078182fce6> Date: Mon, 18 Aug 2008 04:17:47 +0000 Subject: [PATCH] spurious temperature readings don't get passed to user code...need to do something about spurious clock readings next git-svn-id: https://svn.salfter.gotdns.org/svn/a2bfc/trunk@147 1b90f75b-8b96-4784-87c0-14078182fce6 --- ow-temp.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ow-temp.c b/ow-temp.c index 37721dc..c8a51a9 100644 --- a/ow-temp.c +++ b/ow-temp.c @@ -24,7 +24,9 @@ short ow_temp_read(unsigned char* devid, unsigned char format) { unsigned char data[8]; - short rawtemp; + static int lasttemp=-32767; + int newtemp; + int rawtemp; unsigned char i; if (!ow_temp_idcheck(devid)) @@ -40,17 +42,27 @@ short ow_temp_read(unsigned char* devid, unsigned char format) for (i=0; i<8; i++) data[i]=ow_readbyte(); - rawtemp=(short)(data[0]+((int)data[1]<<8)); + rawtemp=((int)data[0]+((int)data[1]<<8)); errno=0; switch (format) { case OW_TEMP_FAHRENHEIT: - return (rawtemp*9+8)/80+32; + newtemp=(rawtemp*9+8)/80+32; + break; case OW_TEMP_CELSIUS: - return (rawtemp+8)>>4; + newtemp=(rawtemp+8)>>4; + break; case OW_TEMP_RAW: default: - return rawtemp; + return (short)rawtemp; + } + /* 17 Aug 08: filter out garbage readings */ + if ((newtemp-lasttemp>3 || newtemp-lasttemp<-3) && lasttemp!=-32767) + return (short)lasttemp; + else + { + lasttemp=newtemp; + return (short)newtemp; } }