switch from fmt.Stringer to conn.Resource

- conn.Resource is a superset of fmt.Stringer.
- lirc: implement conn.Resource.
pull/1/head
Marc-Antoine Ruel 8 years ago
parent 34b6d1d3d2
commit e8b2fc3174

@ -504,4 +504,3 @@ var doSleep = time.Sleep
var _ conn.Resource = &Dev{}
var _ physic.SenseEnv = &Dev{}
var _ fmt.Stringer = &Dev{}

@ -313,7 +313,6 @@ func (e busError) BusError() bool { return true }
var sleep = time.Sleep
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{}
const (
cmdReset = 0xf0 // reset ds248x

@ -160,10 +160,19 @@ type Dev struct {
serial uint64
}
// String implements conn.Resource.
func (d *Dev) String() string {
return d.c.String()
}
// Halt implements conn.Resource.
//
// Halt stops the camera.
func (d *Dev) Halt() error {
// TODO(maruel): Doc says it won't restart. Yo.
return d.c.run(oemPowerDown)
}
// Init initializes the FLIR Lepton in raw 14 bits mode, enables telemetry as
// header.
func (d *Dev) Init() error {
@ -209,12 +218,6 @@ func (d *Dev) WaitIdle() (StatusBit, error) {
return d.c.waitIdle()
}
// Halt stops the camera.
func (d *Dev) Halt() error {
// TODO(maruel): Doc says it won't restart. Yo.
return d.c.run(oemPowerDown)
}
// GetStatus return the status of the camera as known by the camera itself.
func (d *Dev) GetStatus() (*Status, error) {
var v internal.Status
@ -568,4 +571,3 @@ var sleep = time.Sleep
var _ conn.Resource = &Dev{}
var _ physic.SenseEnv = &Dev{}
var _ fmt.Stringer = &cciConn{}

@ -447,4 +447,3 @@ func equalUint16(a, b []uint16) bool {
}
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{}

@ -14,6 +14,7 @@ import (
"strings"
"sync"
"periph.io/x/periph/conn"
"periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/conn/ir"
)
@ -44,10 +45,18 @@ type Conn struct {
pendingList map[string][]string // list of remotes and associated keys being created.
}
// String implements conn.Resource.
func (c *Conn) String() string {
return "lirc"
}
// Halt implements conn.Resource.
//
// It has no effect.
func (c *Conn) Halt() error {
return nil
}
// Close closes the socket to lirc. It is not a requirement to close before
// process termination.
func (c *Conn) Close() error {
@ -264,4 +273,4 @@ func getPins() (int, int) {
}
var _ ir.Conn = &Conn{}
var _ fmt.Stringer = &Conn{}
var _ conn.Resource = &Conn{}

@ -208,4 +208,3 @@ func (d *Dev) sleepHalfCycle() {
var spin = cpu.Nanospin
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{}

@ -256,4 +256,3 @@ func (i *I2C) sleepHalfCycle() {
}
var _ i2c.Bus = &I2C{}
var _ fmt.Stringer = &I2C{}

@ -279,5 +279,5 @@ func (s *spiConn) unassertCS() error {
return nil
}
var _ spi.Conn = &spiConn{}
var _ spi.PortCloser = &SPI{}
var _ fmt.Stringer = &SPI{}

@ -239,4 +239,3 @@ func delayMs(ms int) {
}
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{}

@ -134,11 +134,19 @@ type Dev struct {
spiDev spi.Conn
}
// String implements conn.Resource.
func (r *Dev) String() string {
return fmt.Sprintf("Mifare MFRC522 [bus: %v, reset pin: %s, irq pin: %s]",
r.spiDev, r.resetPin.Name(), r.irqPin.Name())
}
// Halt implements conn.Resource.
//
// It soft-stops the chip - PowerDown bit set, command IDLE
func (r *Dev) Halt() error {
return r.devWrite(commands.CommandReg, 16)
}
// SetOperationtimeout updates the device timeout for card operations.
//
// Effectively that sets the maximum time the RFID device will wait for IRQ
@ -165,11 +173,6 @@ func (r *Dev) Reset() error {
return r.devWrite(commands.CommandReg, commands.PCD_RESETPHASE)
}
// Halt soft-stops the chip - PowerDown bit set, command IDLE
func (r *Dev) Halt() error {
return r.devWrite(commands.CommandReg, 16)
}
// SetAntenna configures the antenna state, on/off.
func (r *Dev) SetAntenna(state bool) error {
if state {
@ -754,10 +757,9 @@ var sequenceCommands = struct {
},
}
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &Dev{}
var _ fmt.Stringer = &BlocksAccess{}
func wrapf(format string, a ...interface{}) error {
return fmt.Errorf("mfrc522: "+format, a...)
}
var _ conn.Resource = &Dev{}
var _ fmt.Stringer = &BlocksAccess{}

Loading…
Cancel
Save