diff --git a/devices/lepton/cci/cci.go b/devices/lepton/cci/cci.go index f40a7a8..d46fd1b 100644 --- a/devices/lepton/cci/cci.go +++ b/devices/lepton/cci/cci.go @@ -277,6 +277,25 @@ func (d *Dev) GetTempHousing() (physic.Temperature, error) { return v.Temperature(), nil } +// Sense implements physic.SenseEnv. It returns the housing temperature. +func (d *Dev) Sense(e *physic.Env) error { + var err error + e.Temperature, err = d.GetTempHousing() + return err +} + +// SenseContinuous implements physic.SenseEnv. +func (d *Dev) SenseContinuous(time.Duration) (<-chan physic.Env, error) { + // TODO(maruel): Manually poll in a loop via time.NewTicker, or better + // leverage the frames being read. + return nil, errors.New("cci: not implemented") +} + +// Precision implements physic.SenseEnv. +func (d *Dev) Precision(e *physic.Env) { + e.Temperature = 10 * physic.MilliKelvin +} + // GetFFCModeControl returns the internal state with regards to calibration. func (d *Dev) GetFFCModeControl() (*FFCMode, error) { v := internal.FFCMode{} @@ -322,7 +341,7 @@ type cciConn struct { } func (c *cciConn) String() string { - return fmt.Sprintf("%s", &c.r) + return c.r.String() } // waitIdle waits for the busy bit to clear. @@ -559,5 +578,5 @@ const ( var sleep = time.Sleep var _ conn.Resource = &Dev{} -var _ fmt.Stringer = &Dev{} +var _ physic.SenseEnv = &Dev{} var _ fmt.Stringer = &cciConn{} diff --git a/devices/lepton/cci/cci_test.go b/devices/lepton/cci/cci_test.go index ff90e12..f20ce8f 100644 --- a/devices/lepton/cci/cci_test.go +++ b/devices/lepton/cci/cci_test.go @@ -11,6 +11,7 @@ import ( "periph.io/x/periph/conn/i2c" "periph.io/x/periph/conn/i2c/i2ctest" "periph.io/x/periph/conn/mmr" + "periph.io/x/periph/conn/physic" "periph.io/x/periph/devices/lepton/internal" ) @@ -205,6 +206,42 @@ func TestGetTempHousing_fail(t *testing.T) { } } +func TestSense(t *testing.T) { + bus, d := getDev(getOps([]byte{0x0, 0x4, 0x2, 0x10}, []byte{0, 0})) + e := physic.Env{} + if err := d.Sense(&e); err != nil { + t.Fatal(err) + } + if e.Temperature != 0 { + t.Fatal(e) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + +func TestSenseContinuous(t *testing.T) { + bus, d := getDev(nil) + if _, err := d.SenseContinuous(time.Second); err == nil { + t.Fatal("implemented?") + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + +func TestPrecision(t *testing.T) { + bus, d := getDev(nil) + e := physic.Env{} + d.Precision(&e) + if e.Temperature != 10*physic.MilliKelvin { + t.Fatal(e) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + func TestGetFFCModeControl(t *testing.T) { bus, d := getDev(getOps([]byte{0x0, 0x4, 0x2, 0x3c}, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) if _, err := d.GetFFCModeControl(); err != nil {