cci: make Dev implement physic.SenseEnv

Remove unnecessary Sprintf() call.
pull/1/head
Marc-Antoine Ruel 8 years ago
parent 79423600fb
commit 0b285a6cb6

@ -277,6 +277,25 @@ func (d *Dev) GetTempHousing() (physic.Temperature, error) {
return v.Temperature(), nil 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. // GetFFCModeControl returns the internal state with regards to calibration.
func (d *Dev) GetFFCModeControl() (*FFCMode, error) { func (d *Dev) GetFFCModeControl() (*FFCMode, error) {
v := internal.FFCMode{} v := internal.FFCMode{}
@ -322,7 +341,7 @@ type cciConn struct {
} }
func (c *cciConn) String() string { func (c *cciConn) String() string {
return fmt.Sprintf("%s", &c.r) return c.r.String()
} }
// waitIdle waits for the busy bit to clear. // waitIdle waits for the busy bit to clear.
@ -559,5 +578,5 @@ const (
var sleep = time.Sleep var sleep = time.Sleep
var _ conn.Resource = &Dev{} var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{} var _ physic.SenseEnv = &Dev{}
var _ fmt.Stringer = &cciConn{} var _ fmt.Stringer = &cciConn{}

@ -11,6 +11,7 @@ import (
"periph.io/x/periph/conn/i2c" "periph.io/x/periph/conn/i2c"
"periph.io/x/periph/conn/i2c/i2ctest" "periph.io/x/periph/conn/i2c/i2ctest"
"periph.io/x/periph/conn/mmr" "periph.io/x/periph/conn/mmr"
"periph.io/x/periph/conn/physic"
"periph.io/x/periph/devices/lepton/internal" "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) { 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})) 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 { if _, err := d.GetFFCModeControl(); err != nil {

Loading…
Cancel
Save