From 07ca36ac5a57dbb4508a8181c65ea8b5fe2cea02 Mon Sep 17 00:00:00 2001 From: Yannis Huber Date: Wed, 1 Jul 2020 11:08:26 +0200 Subject: [PATCH] tmp102: add Connected func to check for device --- tmp102/tmp102.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tmp102/tmp102.go b/tmp102/tmp102.go index 5c568d4..ac6c80b 100644 --- a/tmp102/tmp102.go +++ b/tmp102/tmp102.go @@ -35,6 +35,18 @@ func (d *Device) Configure(cfg Config) { d.address = cfg.Address } +// Connected checks if the config register can be read and that the configuration is correct. +func (d *Device) Connected() bool { + configData := make([]byte, 2) + err := d.bus.ReadRegister(d.address, RegConfiguration, configData) + // Check the reset configuration values. + if err != nil || configData[0] != 0x60 || configData[1] != 0xA0 { + return false + } + return true + +} + // Reads the temperature from the sensor and returns it in celsius milli degrees (°C/1000). func (d *Device) ReadTemperature() (temperature int32, err error) {