Skip to content

Commit

Permalink
Added check for valid data before returning.
Browse files Browse the repository at this point in the history
Make sure the temperature are within spec; +/- 200 for temperature and 0..100
for humidity.  If the data is not correct, retry twice.

It appears that there is some initial data in the buffer that is not temp or
humidity when a computer is first booted up.  This retry mechanism clears out
the buffer until there is reasonable data in the pipe.
  • Loading branch information
rca committed Mar 21, 2011
1 parent 8535775 commit c3e2b08
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lascar.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ get_reading_r(HIDInterface* hid, char* packet,

*hum = get_hum((unsigned)packet[1]);

return ret;
/* check to make sure the values found are within spec, otherwise retry */
if(*temp >= -200.0 && *temp <= 200.0 && *hum >= 0.0 && *hum <= 100.0) {
return ret;
} else if(retries) {
/* if the values were bad, try another two times before giving up */
/*fprintf(stderr,
"Bad values for temp (%.1f) and hum (%.1f)\n", temp, hum);*/
return get_reading_r(hid, packet, temp, hum, get_f, 2);
} else {
return HID_RET_NOT_FOUND;
}
}

HIDInterface* init_termo(HIDInterface* hid) {
Expand Down

0 comments on commit c3e2b08

Please sign in to comment.