Skip to content

Commit

Permalink
Add automatic self calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
pvainio committed Nov 1, 2021
1 parent 7116ab3 commit 48cd21d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
7 changes: 7 additions & 0 deletions scd30.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 11 additions & 15 deletions scd30_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package scd30

import (
"encoding/binary"
"fmt"
"math"
"testing"

"periph.io/x/conn/v3/i2c/i2ctest"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 48cd21d

Please sign in to comment.