| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: uthum.c,v 1.2 2010/02/24 17:34:56 plunky Exp $ */ | | 1 | /* $NetBSD: uthum.c,v 1.3 2010/03/06 04:39:16 cnst Exp $ */ |
2 | /* $OpenBSD: uthum.c,v 1.6 2010/01/03 18:43:02 deraadt Exp $ */ | | 2 | /* $OpenBSD: uthum.c,v 1.6 2010/01/03 18:43:02 deraadt Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 2009 Yojiro UO <yuo@nui.org> | | 5 | * Copyright (c) 2009 Yojiro UO <yuo@nui.org> |
6 | * | | 6 | * |
7 | * Permission to use, copy, modify, and distribute this software for any | | 7 | * Permission to use, copy, modify, and distribute this software for any |
8 | * purpose with or without fee is hereby granted, provided that the above | | 8 | * purpose with or without fee is hereby granted, provided that the above |
9 | * copyright notice and this permission notice appear in all copies. | | 9 | * copyright notice and this permission notice appear in all copies. |
10 | * | | 10 | * |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCAIMS ALL WARRANTIES | | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCAIMS ALL WARRANTIES |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| @@ -157,27 +157,28 @@ USB_ATTACH(uthum) | | | @@ -157,27 +157,28 @@ USB_ATTACH(uthum) |
157 | sc->sc_sensortype = uthum_check_sensortype(sc); | | 157 | sc->sc_sensortype = uthum_check_sensortype(sc); |
158 | | | 158 | |
159 | /* attach sensor */ | | 159 | /* attach sensor */ |
160 | sc->sc_sme = sysmon_envsys_create(); | | 160 | sc->sc_sme = sysmon_envsys_create(); |
161 | sc->sc_sme->sme_name = device_xname(self); | | 161 | sc->sc_sme->sme_name = device_xname(self); |
162 | | | 162 | |
163 | switch (sc->sc_sensortype) { | | 163 | switch (sc->sc_sensortype) { |
164 | case UTHUM_TYPE_SHT1x: | | 164 | case UTHUM_TYPE_SHT1x: |
165 | (void)strlcpy(sc->sc_sensor[UTHUM_TEMP].desc, "temp", | | 165 | (void)strlcpy(sc->sc_sensor[UTHUM_TEMP].desc, "temp", |
166 | sizeof(sc->sc_sensor[UTHUM_TEMP].desc)); | | 166 | sizeof(sc->sc_sensor[UTHUM_TEMP].desc)); |
167 | sc->sc_sensor[UTHUM_TEMP].units = ENVSYS_STEMP; | | 167 | sc->sc_sensor[UTHUM_TEMP].units = ENVSYS_STEMP; |
168 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; | | 168 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; |
169 | | | 169 | |
170 | (void)strlcpy(sc->sc_sensor[UTHUM_HUMIDITY].desc, "humidity", | | 170 | (void)strlcpy(sc->sc_sensor[UTHUM_HUMIDITY].desc, |
| | | 171 | "relative humidity", |
171 | sizeof(sc->sc_sensor[UTHUM_HUMIDITY].desc)); | | 172 | sizeof(sc->sc_sensor[UTHUM_HUMIDITY].desc)); |
172 | sc->sc_sensor[UTHUM_HUMIDITY].units = ENVSYS_INTEGER; | | 173 | sc->sc_sensor[UTHUM_HUMIDITY].units = ENVSYS_INTEGER; |
173 | sc->sc_sensor[UTHUM_HUMIDITY].value_cur = 0; | | 174 | sc->sc_sensor[UTHUM_HUMIDITY].value_cur = 0; |
174 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SINVALID; | | 175 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SINVALID; |
175 | | | 176 | |
176 | sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[UTHUM_TEMP]); | | 177 | sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[UTHUM_TEMP]); |
177 | sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[UTHUM_HUMIDITY]); | | 178 | sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[UTHUM_HUMIDITY]); |
178 | sc->sc_num_sensors = 2; | | 179 | sc->sc_num_sensors = 2; |
179 | DPRINTF(("sensor type: SHT1x\n")); | | 180 | DPRINTF(("sensor type: SHT1x\n")); |
180 | break; | | 181 | break; |
181 | case UTHUM_TYPE_TEMPER: | | 182 | case UTHUM_TYPE_TEMPER: |
182 | (void)strlcpy(sc->sc_sensor[UTHUM_TEMP].desc, "temp", | | 183 | (void)strlcpy(sc->sc_sensor[UTHUM_TEMP].desc, "temp", |
183 | sizeof(sc->sc_sensor[UTHUM_TEMP].desc)); | | 184 | sizeof(sc->sc_sensor[UTHUM_TEMP].desc)); |
| @@ -336,27 +337,27 @@ uthum_refresh(struct sysmon_envsys *sme, | | | @@ -336,27 +337,27 @@ uthum_refresh(struct sysmon_envsys *sme, |
336 | if (uthum_read_data(sc, CMD_GETDATA, buf, sizeof(buf), 1000) != 0) { | | 337 | if (uthum_read_data(sc, CMD_GETDATA, buf, sizeof(buf), 1000) != 0) { |
337 | DPRINTF(("uthum: data read fail\n")); | | 338 | DPRINTF(("uthum: data read fail\n")); |
338 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; | | 339 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; |
339 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SINVALID; | | 340 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SINVALID; |
340 | return; | | 341 | return; |
341 | } | | 342 | } |
342 | | | 343 | |
343 | temp_tick = (buf[0] * 256 + buf[1]) & 0x3fff; | | 344 | temp_tick = (buf[0] * 256 + buf[1]) & 0x3fff; |
344 | humidity_tick = (buf[2] * 256 + buf[3]) & 0x0fff; | | 345 | humidity_tick = (buf[2] * 256 + buf[3]) & 0x0fff; |
345 | | | 346 | |
346 | temp = uthum_sht1x_temp(temp_tick); | | 347 | temp = uthum_sht1x_temp(temp_tick); |
347 | rh = uthum_sht1x_rh(humidity_tick, temp); | | 348 | rh = uthum_sht1x_rh(humidity_tick, temp); |
348 | | | 349 | |
349 | sc->sc_sensor[UTHUM_HUMIDITY].value_cur = rh; | | 350 | sc->sc_sensor[UTHUM_HUMIDITY].value_cur = rh / 1000; |
350 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SVALID; | | 351 | sc->sc_sensor[UTHUM_HUMIDITY].state = ENVSYS_SVALID; |
351 | break; | | 352 | break; |
352 | case UTHUM_TYPE_TEMPER: | | 353 | case UTHUM_TYPE_TEMPER: |
353 | if (uthum_read_data(sc, CMD_GETTEMP, buf, sizeof(buf), 0) != 0) { | | 354 | if (uthum_read_data(sc, CMD_GETTEMP, buf, sizeof(buf), 0) != 0) { |
354 | DPRINTF(("uthum: data read fail\n")); | | 355 | DPRINTF(("uthum: data read fail\n")); |
355 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; | | 356 | sc->sc_sensor[UTHUM_TEMP].state = ENVSYS_SINVALID; |
356 | return; | | 357 | return; |
357 | } | | 358 | } |
358 | temp_tick = (buf[0] * 256 + buf[1]) & 0xffff; | | 359 | temp_tick = (buf[0] * 256 + buf[1]) & 0xffff; |
359 | temp = uthum_sht1x_temp(temp_tick); | | 360 | temp = uthum_sht1x_temp(temp_tick); |
360 | break; | | 361 | break; |
361 | default: | | 362 | default: |
362 | /* do nothing */ | | 363 | /* do nothing */ |