summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-11-24 08:28:54 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-11-24 08:28:54 +0000
commit0ce7d5388d0fde470b73d876f70a762eda87cc2a (patch)
treed3a1b42af181fcf59a4205b672adb9a7af73d7b6
parenta3193e51a579dbe63f8307c94788996478dc7c80 (diff)
Toggle SENSOR_FINVALID based on sensor data validity
-rw-r--r--sys/dev/usb/uthum.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sys/dev/usb/uthum.c b/sys/dev/usb/uthum.c
index 0a63b861f71..f142becfd72 100644
--- a/sys/dev/usb/uthum.c
+++ b/sys/dev/usb/uthum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthum.c,v 1.1 2009/11/23 19:35:54 yuo Exp $ */
+/* $OpenBSD: uthum.c,v 1.2 2009/11/24 08:28:53 deraadt Exp $ */
/*
* Copyright (c) 2009 Yojiro UO <yuo@nui.org>
@@ -182,17 +182,20 @@ uthum_attach(struct device *parent, struct device *self, void *aux)
strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname,
sizeof(sc->sc_sensordev.xname));
- switch (sc->sc_sensortype){
+ switch (sc->sc_sensortype) {
case UTHUM_TYPE_SHT1x:
strlcpy(sc->sc_sensor[UTHUM_TEMP].desc, "temp",
sizeof(sc->sc_sensor[UTHUM_TEMP].desc));
sc->sc_sensor[UTHUM_TEMP].type = SENSOR_TEMP;
+ sc->sc_sensor[UTHUM_TEMP].status = SENSOR_S_UNKNOWN;
+ sc->sc_sensor[UTHUM_TEMP].flags = SENSOR_FINVALID;
strlcpy(sc->sc_sensor[UTHUM_HUMIDITY].desc, "humidity",
sizeof(sc->sc_sensor[UTHUM_HUMIDITY].desc));
sc->sc_sensor[UTHUM_HUMIDITY].type = SENSOR_PERCENT;
sc->sc_sensor[UTHUM_HUMIDITY].value = 0;
sc->sc_sensor[UTHUM_HUMIDITY].status = SENSOR_S_UNKNOWN;
+ sc->sc_sensor[UTHUM_HUMIDITY].flags = SENSOR_FINVALID;
sensor_attach(&sc->sc_sensordev, &sc->sc_sensor[UTHUM_TEMP]);
sensor_attach(&sc->sc_sensordev, &sc->sc_sensor[UTHUM_HUMIDITY]);
@@ -360,10 +363,12 @@ uthum_refresh(void *arg)
DPRINTF(("uthum: data read fail\n"));
sc->sc_sensor[UTHUM_TEMP].status = SENSOR_S_UNKNOWN;
sc->sc_sensor[UTHUM_HUMIDITY].status = SENSOR_S_UNKNOWN;
+ sc->sc_sensor[UTHUM_TEMP].flags |= SENSOR_FINVALID;
+ sc->sc_sensor[UTHUM_HUMIDITY].flags |= SENSOR_FINVALID;
return;
}
- switch (sc->sc_sensortype){
+ switch (sc->sc_sensortype) {
case UTHUM_TYPE_SHT1x:
temp_tick = (buf[0] * 256 + buf[1]) & 0x3fff;
humidity_tick = (buf[2] * 256 + buf[3]) & 0x0fff;
@@ -373,13 +378,15 @@ uthum_refresh(void *arg)
break;
default:
/* do nothing */
- break;
+ return;
}
sc->sc_sensor[UTHUM_TEMP].value = (temp * 10000) + 273150000;
sc->sc_sensor[UTHUM_TEMP].status = SENSOR_S_OK;
+ sc->sc_sensor[UTHUM_TEMP].flags &= ~SENSOR_FINVALID;
sc->sc_sensor[UTHUM_HUMIDITY].value = rh;
sc->sc_sensor[UTHUM_HUMIDITY].status = SENSOR_S_OK;
+ sc->sc_sensor[UTHUM_HUMIDITY].flags &= ~SENSOR_FINVALID;
}
/* return C-degree * 100 value */