From ce1ffb1fb8885c4f4b10903112860e3ab1c61d9b Mon Sep 17 00:00:00 2001 From: mglocker Date: Mon, 4 Dec 2023 05:28:25 +0000 Subject: [PATCH] Make the TEMPer{1,2} devices display minus degC. From the NetBSD driver. ok deraadt@ --- sys/dev/usb/uthum.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/dev/usb/uthum.c b/sys/dev/usb/uthum.c index 7888ee8b2c5..ce118a5e593 100644 --- a/sys/dev/usb/uthum.c +++ b/sys/dev/usb/uthum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthum.c,v 1.38 2022/01/09 05:43:02 jsg Exp $ */ +/* $OpenBSD: uthum.c,v 1.39 2023/12/04 05:28:25 mglocker Exp $ */ /* * Copyright (c) 2009, 2010 Yojiro UO @@ -742,8 +742,16 @@ uthum_refresh_temperntc(struct uthum_softc *sc, int sensor) int uthum_ds75_temp(uint8_t msb, uint8_t lsb) { + int val; + /* DS75: 12bit precision mode : 0.0625 degrees Celsius ticks */ - return (msb * 100) + ((lsb >> 4) * 25 / 4); + + val = (msb << 8) | lsb; + if (val >= 32768) + val = val - 65536; + val = (val * 100) >> 8; + + return val; } /* return C-degree * 100 value */ -- 2.20.1