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
This commit is contained in:
22
ow-temp.c
22
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user