Skip to content

Commit

Permalink
PCSensor_Temper: Don't print out out-of-range values
Browse files Browse the repository at this point in the history
Signed-off-by: Jason S. McMullan <jason.mcmullan@gmail.com>
  • Loading branch information
ezrec committed May 15, 2011
1 parent 949419c commit a3aabc1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/PCsensor_Temper.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ static int temp_read(struct usb_dev_handle *usb, int16_t *val)
*/ */
tmp = ((uint16_t)((buff[0]<<8) | buff[1])); tmp = ((uint16_t)((buff[0]<<8) | buff[1]));


if (tmp == 0 || tmp == ~0)
return -EAGAIN;

/* msb means the temperature is negative -- less than 0 Celsius -- and in 2'complement form. /* msb means the temperature is negative -- less than 0 Celsius -- and in 2'complement form.
* We can't be sure that the host uses 2's complement to store negative numbers * We can't be sure that the host uses 2's complement to store negative numbers
* so if the temperature is negative, we 'manually' get its magnitude * so if the temperature is negative, we 'manually' get its magnitude
Expand All @@ -136,7 +139,7 @@ static int PCsensor_Temper_update(struct usense_device *dev, void *priv)
err = temp_read(temper->usb, &temp); err = temp_read(temper->usb, &temp);
if (err < 0) { if (err < 0) {
fprintf(stderr, "%s: Can't read temperature\n", usense_device_name(dev)); fprintf(stderr, "%s: Can't read temperature\n", usense_device_name(dev));
return -EINVAL; return err;
} else { } else {
/* Kelvin */ /* Kelvin */
char buff[48]; char buff[48];
Expand Down

0 comments on commit a3aabc1

Please sign in to comment.