From 48cd21d816d232fca473867441572f15af0e31f5 Mon Sep 17 00:00:00 2001 From: Pekka Vainio Date: Mon, 1 Nov 2021 14:15:34 +0200 Subject: [PATCH] Add automatic self calibration --- scd30.go | 7 +++++++ scd30_test.go | 26 +++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/scd30.go b/scd30.go index e4ab0da..5ccb58e 100644 --- a/scd30.go +++ b/scd30.go @@ -139,6 +139,13 @@ func (dev SCD30) HasMeasurement() (bool, error) { } } +// SetAutomaticSelfCalibration, 1 on, 0 off +func (dev SCD30) SetAutomaticSelfCalibration(value uint16) error { + mutex.Lock() + defer mutex.Unlock() + return dev.sendCommandArg(0x5306, value) +} + func (dev SCD30) readData(len int) ([]byte, error) { data := make([]byte, len) diff --git a/scd30_test.go b/scd30_test.go index ec3d704..f366d78 100644 --- a/scd30_test.go +++ b/scd30_test.go @@ -1,9 +1,6 @@ package scd30 import ( - "encoding/binary" - "fmt" - "math" "testing" "periph.io/x/conn/v3/i2c/i2ctest" @@ -49,18 +46,17 @@ func TestSetTemperatureOffset(t *testing.T) { assertNoError(t, err) } -func printFloat(f float32) { - bits := math.Float32bits(f) - data := make([]byte, 4) - binary.BigEndian.PutUint32(data, bits) - var out []byte - crcdata := []byte{data[0], data[1]} - out = append(out, crcdata...) - out = append(out, crc(crcdata)) - crcdata = []byte{data[2], data[3]} - out = append(out, crcdata...) - out = append(out, crc(crcdata)) - fmt.Printf("f %f out %#v", f, out) +func TestSetAutomaticSelfCalibration(t *testing.T) { + + bus := &i2ctest.Playback{ + Ops: []i2ctest.IO{ + {Addr: addr, W: []byte{0x53, 0x06, 0x0, 0x0, 0x81}, R: nil}, + }, + } + + scd30, _ := Open(bus) + err := scd30.SetAutomaticSelfCalibration(0) + assertNoError(t, err) } func TestHasMeasurement(t *testing.T) {