From a1c8b55557b65b33c0c3a38105b111fd6b777d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=B6hmke?= Date: Mon, 4 Oct 2021 15:53:45 +0200 Subject: [PATCH] proper handle DS18S20 conversion time --- ds18b20/ds18b20.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ds18b20/ds18b20.go b/ds18b20/ds18b20.go index 7a8b86c..0934e2f 100644 --- a/ds18b20/ds18b20.go +++ b/ds18b20/ds18b20.go @@ -75,6 +75,13 @@ func New(o onewire.Bus, addr onewire.Address, resolutionBits int) (*Dev, error) d := &Dev{onewire: onewire.Dev{Bus: o, Addr: addr}, resolution: resolutionBits} + if d.Family() == DS18S20 { + if resolutionBits != 12 { + return nil, errors.New("ds18b20: DS18S20 only supports 12 resolutionBits") + } + return d, nil + } + // Start by reading the scratchpad memory, this will tell us whether we can // talk to the device correctly and also how it's configured. spad, err := d.readScratchpad()