From be7188af99b2bcc68462d6f4abb3c9746f9e84dc Mon Sep 17 00:00:00 2001 From: miod Date: Sun, 2 Apr 2023 17:03:14 +0000 Subject: [PATCH] Add support for TEMPerGold 3.4 to ugold(4). ok landry@ --- share/man/man4/ugold.4 | 5 +++-- sys/dev/usb/ugold.c | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/share/man/man4/ugold.4 b/share/man/man4/ugold.4 index 41ec170b5f1..d2f4b307849 100644 --- a/share/man/man4/ugold.4 +++ b/share/man/man4/ugold.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ugold.4,v 1.6 2021/04/05 16:26:06 landry Exp $ +.\" $OpenBSD: ugold.4,v 1.7 2023/04/02 17:03:14 miod Exp $ .\" .\" Copyright (c) 2013 Takayoshi SASANO .\" Copyright (c) 2013 Martin Pieuchot @@ -16,7 +16,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 5 2021 $ +.Dd $Mdocdate: April 2 2023 $ .Dt UGOLD 4 .Os .Sh NAME @@ -36,6 +36,7 @@ driver: .It Li "RDing TEMPer1V1.2" Ta "1 Temperature" .It Li "RDing TEMPerV1.4" Ta "1 Temperature" .It Li "RDing TEMPerGold_V3.1" Ta "1 Temperature" +.It Li "RDing TEMPerGold_V3.4" Ta "1 Temperature" .It Li "RDing TEMPerHUM1V1.0" Ta "1 Temperature and 1 Humidity" .It Li "RDing TEMPerHUM1V1.2" Ta "1 Temperature and 1 Humidity" .It Li "RDing TEMPer1F_H1V1.5F" Ta "1 Temperature and 1 Humidity" diff --git a/sys/dev/usb/ugold.c b/sys/dev/usb/ugold.c index c14f4571f76..14a0cbb687d 100644 --- a/sys/dev/usb/ugold.c +++ b/sys/dev/usb/ugold.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ugold.c,v 1.21 2022/01/09 05:43:00 jsg Exp $ */ +/* $OpenBSD: ugold.c,v 1.22 2023/04/02 17:03:14 miod Exp $ */ /* * Copyright (c) 2013 Takayoshi SASANO @@ -86,6 +86,7 @@ const struct usb_devno ugold_devs[] = { { USB_VENDOR_MICRODIA, USB_PRODUCT_MICRODIA_TEMPER }, { USB_VENDOR_MICRODIA, USB_PRODUCT_MICRODIA_TEMPERHUM }, { USB_VENDOR_PCSENSORS, USB_PRODUCT_PCSENSORS_TEMPER }, + { USB_VENDOR_WCH2, USB_PRODUCT_WCH2_TEMPER }, }; int ugold_match(struct device *, void *, void *); @@ -151,6 +152,7 @@ ugold_attach(struct device *parent, struct device *self, void *aux) break; case USB_PRODUCT_MICRODIA_TEMPERHUM: case USB_PRODUCT_PCSENSORS_TEMPER: + case USB_PRODUCT_WCH2_TEMPER: sc->sc_hdev.sc_intr = ugold_si700x_intr; break; default: @@ -184,6 +186,7 @@ ugold_attach(struct device *parent, struct device *self, void *aux) break; case USB_PRODUCT_MICRODIA_TEMPERHUM: case USB_PRODUCT_PCSENSORS_TEMPER: + case USB_PRODUCT_WCH2_TEMPER: /* 1 temperature and 1 humidity sensor */ sc->sc_sensor[UGOLD_INNER].type = SENSOR_TEMP; strlcpy(sc->sc_sensor[UGOLD_INNER].desc, "inner", @@ -388,6 +391,9 @@ ugold_si700x_type(struct ugold_softc *sc, uint8_t *buf, u_int len) } else if (memcmp(buf, "ld_V3.1 ", len) == 0) { sc->sc_type = UGOLD_TYPE_GOLD; printf("gold (temperature only)\n"); + } else if (memcmp(buf, "ld_V3.4 ", len) == 0) { + sc->sc_type = UGOLD_TYPE_GOLD; + printf("gold (temperature only)\n"); } else { sc->sc_type = -1; printf("unknown\n"); @@ -418,13 +424,15 @@ ugold_si700x_intr(struct uhidev *addr, void *ibuf, u_int len) } break; case UGOLD_CMD_DATA: - if (buf[1] != 4 && buf[1] != 64) + if (buf[1] != 4 && buf[1] != 64 && buf[1] != 128) printf("%s: invalid data length (%d bytes)\n", sc->sc_hdev.sc_dev.dv_xname, buf[1]); + if (buf[1] < 4) + break; temp = ugold_si700x_temp(sc->sc_type, buf[2], buf[3]); sc->sc_sensor[UGOLD_INNER].value = (temp * 1000) + 273150000; sc->sc_sensor[UGOLD_INNER].flags &= ~SENSOR_FINVALID; - if (sc->sc_type != UGOLD_TYPE_GOLD) { + if (sc->sc_type != UGOLD_TYPE_GOLD && buf[1] >= 6) { rhum = ugold_si700x_rhum(sc->sc_type, buf[4], buf[5], temp); sc->sc_sensor[UGOLD_HUM].value = rhum; sc->sc_sensor[UGOLD_HUM].flags &= ~SENSOR_FINVALID; -- 2.20.1