core: Refactor GPIO drivers for new Driver creation signatures
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
ce773955b4
commit
93772e1c37
|
@ -18,16 +18,15 @@ type AnalogSensorDriver struct {
|
|||
}
|
||||
|
||||
// NewAnalogSensorDriver returns a new AnalogSensorDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewAnalogSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *AnalogSensorDriver {
|
||||
func NewAnalogSensorDriver(a AnalogReader, pin string, v ...time.Duration) *AnalogSensorDriver {
|
||||
d := &AnalogSensorDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Eventer: gobot.NewEventer(),
|
||||
|
@ -85,6 +84,9 @@ func (a *AnalogSensorDriver) Halt() (errs []error) {
|
|||
// Name returns the AnalogSensorDrivers name
|
||||
func (a *AnalogSensorDriver) Name() string { return a.name }
|
||||
|
||||
// SetName sets the AnalogSensorDrivers name
|
||||
func (a *AnalogSensorDriver) SetName(n string) { a.name = n }
|
||||
|
||||
// Pin returns the AnalogSensorDrivers pin
|
||||
func (a *AnalogSensorDriver) Pin() string { return a.pin }
|
||||
|
||||
|
|
|
@ -12,11 +12,10 @@ import (
|
|||
var _ gobot.Driver = (*AnalogSensorDriver)(nil)
|
||||
|
||||
func TestAnalogSensorDriver(t *testing.T) {
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor(), "1")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
d = NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1", 30*time.Second)
|
||||
d = NewAnalogSensorDriver(newGpioTestAdaptor(), "1", 30*time.Second)
|
||||
gobottest.Assert(t, d.interval, 30*time.Second)
|
||||
|
||||
testAdaptorAnalogRead = func() (val int, err error) {
|
||||
|
@ -32,7 +31,7 @@ func TestAnalogSensorDriver(t *testing.T) {
|
|||
func TestAnalogSensorDriverStart(t *testing.T) {
|
||||
sem := make(chan bool, 1)
|
||||
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor(), "1")
|
||||
|
||||
testAdaptorAnalogRead = func() (val int, err error) {
|
||||
val = 0
|
||||
|
@ -94,7 +93,7 @@ func TestAnalogSensorDriverStart(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAnalogSensorDriverHalt(t *testing.T) {
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
d := NewAnalogSensorDriver(newGpioTestAdaptor(), "1")
|
||||
go func() {
|
||||
<-d.halt
|
||||
}()
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package gpio
|
||||
|
||||
import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
)
|
||||
|
||||
// ButtonDriver Represents a digital Button
|
||||
|
@ -17,13 +18,12 @@ type ButtonDriver struct {
|
|||
}
|
||||
|
||||
// NewButtonDriver returns a new ButtonDriver with a polling interval of
|
||||
// 10 Milliseconds given a DigitalReader, name and pin.
|
||||
// 10 Milliseconds given a DigitalReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
||||
func NewButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *ButtonDriver {
|
||||
func NewButtonDriver(a DigitalReader, pin string, v ...time.Duration) *ButtonDriver {
|
||||
b := &ButtonDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Active: false,
|
||||
|
@ -79,6 +79,9 @@ func (b *ButtonDriver) Halt() (errs []error) {
|
|||
// Name returns the ButtonDrivers name
|
||||
func (b *ButtonDriver) Name() string { return b.name }
|
||||
|
||||
// SetName sets the ButtonDrivers name
|
||||
func (b *ButtonDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// Pin returns the ButtonDrivers pin
|
||||
func (b *ButtonDriver) Pin() string { return b.pin }
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ var _ gobot.Driver = (*ButtonDriver)(nil)
|
|||
const BUTTON_TEST_DELAY = 150
|
||||
|
||||
func initTestButtonDriver() *ButtonDriver {
|
||||
return NewButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
return NewButtonDriver(newGpioTestAdaptor(), "1")
|
||||
}
|
||||
|
||||
func TestButtonDriverHalt(t *testing.T) {
|
||||
|
@ -26,11 +26,10 @@ func TestButtonDriverHalt(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestButtonDriver(t *testing.T) {
|
||||
d := NewButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
d := NewButtonDriver(newGpioTestAdaptor(), "1")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
d = NewButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1", 30*time.Second)
|
||||
d = NewButtonDriver(newGpioTestAdaptor(), "1", 30*time.Second)
|
||||
gobottest.Assert(t, d.interval, 30*time.Second)
|
||||
}
|
||||
|
||||
|
|
|
@ -136,10 +136,9 @@ type BuzzerDriver struct {
|
|||
BPM float64
|
||||
}
|
||||
|
||||
// NewBuzzerDriver return a new BuzzerDriver given a DigitalWriter, name and pin.
|
||||
func NewBuzzerDriver(a DigitalWriter, name string, pin string) *BuzzerDriver {
|
||||
// NewBuzzerDriver return a new BuzzerDriver given a DigitalWriter and pin.
|
||||
func NewBuzzerDriver(a DigitalWriter, pin string) *BuzzerDriver {
|
||||
l := &BuzzerDriver{
|
||||
name: name,
|
||||
pin: pin,
|
||||
connection: a,
|
||||
high: false,
|
||||
|
@ -158,6 +157,9 @@ func (l *BuzzerDriver) Halt() (errs []error) { return }
|
|||
// Name returns the BuzzerDrivers name
|
||||
func (l *BuzzerDriver) Name() string { return l.name }
|
||||
|
||||
// SetName sets the BuzzerDrivers name
|
||||
func (l *BuzzerDriver) SetName(n string) { l.name = n }
|
||||
|
||||
// Pin returns the BuzzerDrivers name
|
||||
func (l *BuzzerDriver) Pin() string { return l.pin }
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ type DirectPinDriver struct {
|
|||
gobot.Commander
|
||||
}
|
||||
|
||||
// NewDirectPinDriver return a new DirectPinDriver given a Connection, name and pin.
|
||||
// NewDirectPinDriver return a new DirectPinDriver given a Connection and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "DigitalRead" - See DirectPinDriver.DigitalRead
|
||||
|
@ -23,9 +23,8 @@ type DirectPinDriver struct {
|
|||
// "AnalogWrite" - See DirectPinDriver.AnalogWrite
|
||||
// "PwmWrite" - See DirectPinDriver.PwmWrite
|
||||
// "ServoWrite" - See DirectPinDriver.ServoWrite
|
||||
func NewDirectPinDriver(a gobot.Connection, name string, pin string) *DirectPinDriver {
|
||||
func NewDirectPinDriver(a gobot.Connection, pin string) *DirectPinDriver {
|
||||
d := &DirectPinDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Commander: gobot.NewCommander(),
|
||||
|
@ -58,6 +57,9 @@ func NewDirectPinDriver(a gobot.Connection, name string, pin string) *DirectPinD
|
|||
// Name returns the DirectPinDrivers name
|
||||
func (d *DirectPinDriver) Name() string { return d.name }
|
||||
|
||||
// SetName sets the DirectPinDrivers name
|
||||
func (d *DirectPinDriver) SetName(n string) { d.name = n }
|
||||
|
||||
// Pin returns the DirectPinDrivers pin
|
||||
func (d *DirectPinDriver) Pin() string { return d.pin }
|
||||
|
||||
|
|
|
@ -28,17 +28,16 @@ func initTestDirectPinDriver(conn gobot.Connection) *DirectPinDriver {
|
|||
testAdaptorServoWrite = func() (err error) {
|
||||
return errors.New("write error")
|
||||
}
|
||||
return NewDirectPinDriver(conn, "bot", "1")
|
||||
return NewDirectPinDriver(conn, "1")
|
||||
}
|
||||
|
||||
func TestDirectPinDriver(t *testing.T) {
|
||||
var ret map[string]interface{}
|
||||
var err interface{}
|
||||
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, d.Pin(), "1")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
ret = d.Command("DigitalRead")(nil).(map[string]interface{})
|
||||
|
||||
|
@ -61,17 +60,17 @@ func TestDirectPinDriver(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverStart(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Start()), 0)
|
||||
}
|
||||
|
||||
func TestDirectPinDriverHalt(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Halt()), 0)
|
||||
}
|
||||
|
||||
func TestDirectPinDriverOff(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Refute(t, d.DigitalWrite(0), nil)
|
||||
|
||||
d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
|
||||
|
@ -79,7 +78,7 @@ func TestDirectPinDriverOff(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverOn(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Refute(t, d.DigitalWrite(1), nil)
|
||||
|
||||
d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
|
||||
|
@ -87,7 +86,7 @@ func TestDirectPinDriverOn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverDigitalWrite(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Refute(t, d.DigitalWrite(1), nil)
|
||||
|
||||
d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
|
||||
|
@ -95,7 +94,7 @@ func TestDirectPinDriverDigitalWrite(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverDigitalRead(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
ret, err := d.DigitalRead()
|
||||
gobottest.Assert(t, ret, 1)
|
||||
|
||||
|
@ -105,7 +104,7 @@ func TestDirectPinDriverDigitalRead(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverAnalogRead(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
ret, err := d.AnalogRead()
|
||||
gobottest.Assert(t, ret, 80)
|
||||
|
||||
|
@ -115,14 +114,14 @@ func TestDirectPinDriverAnalogRead(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDirectPinDriverPwmWrite(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Refute(t, d.PwmWrite(1), nil)
|
||||
|
||||
d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
|
||||
gobottest.Assert(t, d.PwmWrite(1), ErrPwmWriteUnsupported)
|
||||
}
|
||||
func TestDirectPinDriverDigitalWrie(t *testing.T) {
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestDirectPinDriver(newGpioTestAdaptor())
|
||||
gobottest.Refute(t, d.ServoWrite(1), nil)
|
||||
|
||||
d = initTestDirectPinDriver(&gpioTestBareAdaptor{})
|
||||
|
|
|
@ -9,15 +9,15 @@ type GroveRelayDriver struct {
|
|||
*RelayDriver
|
||||
}
|
||||
|
||||
// NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter, name and pin.
|
||||
// NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Toggle" - See RelayDriver.Toggle
|
||||
// "On" - See RelayDriver.On
|
||||
// "Off" - See RelayDriver.Off
|
||||
func NewGroveRelayDriver(a DigitalWriter, name string, pin string) *GroveRelayDriver {
|
||||
func NewGroveRelayDriver(a DigitalWriter, pin string) *GroveRelayDriver {
|
||||
return &GroveRelayDriver{
|
||||
RelayDriver: NewRelayDriver(a, name, pin),
|
||||
RelayDriver: NewRelayDriver(a, pin),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,16 +27,16 @@ type GroveRotaryDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveRotaryDriver returns a new GroveRotaryDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewGroveRotaryDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GroveRotaryDriver {
|
||||
func NewGroveRotaryDriver(a AnalogReader, pin string, v ...time.Duration) *GroveRotaryDriver {
|
||||
return &GroveRotaryDriver{
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,16 +45,16 @@ type GroveLedDriver struct {
|
|||
*LedDriver
|
||||
}
|
||||
|
||||
// NewGroveLedDriver return a new GroveLedDriver given a DigitalWriter, name and pin.
|
||||
// NewGroveLedDriver return a new GroveLedDriver given a DigitalWriter and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Brightness" - See LedDriver.Brightness
|
||||
// "Toggle" - See LedDriver.Toggle
|
||||
// "On" - See LedDriver.On
|
||||
// "Off" - See LedDriver.Off
|
||||
func NewGroveLedDriver(a DigitalWriter, name string, pin string) *GroveLedDriver {
|
||||
func NewGroveLedDriver(a DigitalWriter, pin string) *GroveLedDriver {
|
||||
return &GroveLedDriver{
|
||||
LedDriver: NewLedDriver(a, name, pin),
|
||||
LedDriver: NewLedDriver(a, pin),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,16 +65,16 @@ type GroveLightSensorDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveLightSensorDriver returns a new GroveLightSensorDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewGroveLightSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GroveLightSensorDriver {
|
||||
func NewGroveLightSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveLightSensorDriver {
|
||||
return &GroveLightSensorDriver{
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,16 +85,16 @@ type GrovePiezoVibrationSensorDriver struct {
|
|||
}
|
||||
|
||||
// NewGrovePiezoVibrationSensorDriver returns a new GrovePiezoVibrationSensorDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewGrovePiezoVibrationSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
|
||||
func NewGrovePiezoVibrationSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
|
||||
sensor := &GrovePiezoVibrationSensorDriver{
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
||||
}
|
||||
|
||||
sensor.AddEvent(Vibration)
|
||||
|
@ -114,10 +114,10 @@ type GroveBuzzerDriver struct {
|
|||
*BuzzerDriver
|
||||
}
|
||||
|
||||
// NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter, name and pin.
|
||||
func NewGroveBuzzerDriver(a DigitalWriter, name string, pin string) *GroveBuzzerDriver {
|
||||
// NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter and pin.
|
||||
func NewGroveBuzzerDriver(a DigitalWriter, pin string) *GroveBuzzerDriver {
|
||||
return &GroveBuzzerDriver{
|
||||
BuzzerDriver: NewBuzzerDriver(a, name, pin),
|
||||
BuzzerDriver: NewBuzzerDriver(a, pin),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,13 +128,13 @@ type GroveButtonDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveButtonDriver returns a new GroveButtonDriver with a polling interval of
|
||||
// 10 Milliseconds given a DigitalReader, name and pin.
|
||||
// 10 Milliseconds given a DigitalReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
||||
func NewGroveButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *GroveButtonDriver {
|
||||
func NewGroveButtonDriver(a DigitalReader, pin string, v ...time.Duration) *GroveButtonDriver {
|
||||
return &GroveButtonDriver{
|
||||
ButtonDriver: NewButtonDriver(a, name, pin, v...),
|
||||
ButtonDriver: NewButtonDriver(a, pin, v...),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,16 +145,16 @@ type GroveSoundSensorDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveSoundSensorDriver returns a new GroveSoundSensorDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewGroveSoundSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GroveSoundSensorDriver {
|
||||
func NewGroveSoundSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveSoundSensorDriver {
|
||||
return &GroveSoundSensorDriver{
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
|
||||
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,12 +165,12 @@ type GroveTouchDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveTouchDriver returns a new GroveTouchDriver with a polling interval of
|
||||
// 10 Milliseconds given a DigitalReader, name and pin.
|
||||
// 10 Milliseconds given a DigitalReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
||||
func NewGroveTouchDriver(a DigitalReader, name string, pin string, v ...time.Duration) *GroveTouchDriver {
|
||||
func NewGroveTouchDriver(a DigitalReader, pin string, v ...time.Duration) *GroveTouchDriver {
|
||||
return &GroveTouchDriver{
|
||||
ButtonDriver: NewButtonDriver(a, name, pin, v...),
|
||||
ButtonDriver: NewButtonDriver(a, pin, v...),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,16 +21,15 @@ type GroveTemperatureSensorDriver struct {
|
|||
}
|
||||
|
||||
// NewGroveTemperatureSensorDriver returns a new GroveTemperatureSensorDriver with a polling interval of
|
||||
// 10 Milliseconds given an AnalogReader, name and pin.
|
||||
// 10 Milliseconds given an AnalogReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the TemperatureSensor is polled for new information
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Read" - See AnalogSensor.Read
|
||||
func NewGroveTemperatureSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GroveTemperatureSensorDriver {
|
||||
func NewGroveTemperatureSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveTemperatureSensorDriver {
|
||||
d := &GroveTemperatureSensorDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Eventer: gobot.NewEventer(),
|
||||
|
@ -88,6 +87,9 @@ func (a *GroveTemperatureSensorDriver) Halt() (errs []error) {
|
|||
// Name returns the GroveTemperatureSensorDrivers name
|
||||
func (a *GroveTemperatureSensorDriver) Name() string { return a.name }
|
||||
|
||||
// SetName sets the GroveTemperatureSensorDrivers name
|
||||
func (a *GroveTemperatureSensorDriver) SetName(n string) { a.name = n }
|
||||
|
||||
// Pin returns the GroveTemperatureSensorDrivers pin
|
||||
func (a *GroveTemperatureSensorDriver) Pin() string { return a.pin }
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ type gpioTestBareAdaptor struct{}
|
|||
func (t *gpioTestBareAdaptor) Connect() (errs []error) { return }
|
||||
func (t *gpioTestBareAdaptor) Finalize() (errs []error) { return }
|
||||
func (t *gpioTestBareAdaptor) Name() string { return "" }
|
||||
func (t *gpioTestBareAdaptor) SetName(n string) {}
|
||||
|
||||
type gpioTestDigitalWriter struct {
|
||||
gpioTestBareAdaptor
|
||||
|
@ -51,11 +52,11 @@ func (t *gpioTestAdaptor) DigitalRead(string) (val int, err error) {
|
|||
func (t *gpioTestAdaptor) Connect() (errs []error) { return }
|
||||
func (t *gpioTestAdaptor) Finalize() (errs []error) { return }
|
||||
func (t *gpioTestAdaptor) Name() string { return t.name }
|
||||
func (t *gpioTestAdaptor) SetName(n string) { t.name = n }
|
||||
func (t *gpioTestAdaptor) Port() string { return t.port }
|
||||
|
||||
func newGpioTestAdaptor(name string) *gpioTestAdaptor {
|
||||
func newGpioTestAdaptor() *gpioTestAdaptor {
|
||||
return &gpioTestAdaptor{
|
||||
name: name,
|
||||
port: "/dev/null",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,16 +13,15 @@ type LedDriver struct {
|
|||
gobot.Commander
|
||||
}
|
||||
|
||||
// NewLedDriver return a new LedDriver given a DigitalWriter, name and pin.
|
||||
// NewLedDriver return a new LedDriver given a DigitalWriter and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Brightness" - See LedDriver.Brightness
|
||||
// "Toggle" - See LedDriver.Toggle
|
||||
// "On" - See LedDriver.On
|
||||
// "Off" - See LedDriver.Off
|
||||
func NewLedDriver(a DigitalWriter, name string, pin string) *LedDriver {
|
||||
func NewLedDriver(a DigitalWriter, pin string) *LedDriver {
|
||||
l := &LedDriver{
|
||||
name: name,
|
||||
pin: pin,
|
||||
connection: a,
|
||||
high: false,
|
||||
|
@ -58,6 +57,9 @@ func (l *LedDriver) Halt() (errs []error) { return }
|
|||
// Name returns the LedDrivers name
|
||||
func (l *LedDriver) Name() string { return l.name }
|
||||
|
||||
// SetName sets the LedDrivers name
|
||||
func (l *LedDriver) SetName(n string) { l.name = n }
|
||||
|
||||
// Pin returns the LedDrivers name
|
||||
func (l *LedDriver) Pin() string { return l.pin }
|
||||
|
||||
|
|
|
@ -14,17 +14,16 @@ func initTestLedDriver(conn DigitalWriter) *LedDriver {
|
|||
testAdaptorPwmWrite = func() (err error) {
|
||||
return nil
|
||||
}
|
||||
return NewLedDriver(conn, "bot", "1")
|
||||
return NewLedDriver(conn, "1")
|
||||
}
|
||||
|
||||
func TestLedDriver(t *testing.T) {
|
||||
var err interface{}
|
||||
|
||||
d := initTestLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestLedDriver(newGpioTestAdaptor())
|
||||
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Pin(), "1")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
testAdaptorDigitalWrite = func() (err error) {
|
||||
return errors.New("write error")
|
||||
|
@ -48,17 +47,17 @@ func TestLedDriver(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLedDriverStart(t *testing.T) {
|
||||
d := initTestLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestLedDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Start()), 0)
|
||||
}
|
||||
|
||||
func TestLedDriverHalt(t *testing.T) {
|
||||
d := initTestLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestLedDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Halt()), 0)
|
||||
}
|
||||
|
||||
func TestLedDriverToggle(t *testing.T) {
|
||||
d := initTestLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestLedDriver(newGpioTestAdaptor())
|
||||
d.Off()
|
||||
d.Toggle()
|
||||
gobottest.Assert(t, d.State(), true)
|
||||
|
@ -70,7 +69,7 @@ func TestLedDriverBrightness(t *testing.T) {
|
|||
d := initTestLedDriver(&gpioTestDigitalWriter{})
|
||||
gobottest.Assert(t, d.Brightness(150), ErrPwmWriteUnsupported)
|
||||
|
||||
d = initTestLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d = initTestLedDriver(newGpioTestAdaptor())
|
||||
testAdaptorPwmWrite = func() (err error) {
|
||||
err = errors.New("pwm error")
|
||||
return
|
||||
|
|
|
@ -18,13 +18,12 @@ type MakeyButtonDriver struct {
|
|||
}
|
||||
|
||||
// NewMakeyButtonDriver returns a new MakeyButtonDriver with a polling interval of
|
||||
// 10 Milliseconds given a DigitalReader, name and pin.
|
||||
// 10 Milliseconds given a DigitalReader and pin.
|
||||
//
|
||||
// Optionally accepts:
|
||||
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
||||
func NewMakeyButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *MakeyButtonDriver {
|
||||
func NewMakeyButtonDriver(a DigitalReader, pin string, v ...time.Duration) *MakeyButtonDriver {
|
||||
m := &MakeyButtonDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Active: false,
|
||||
|
@ -47,6 +46,9 @@ func NewMakeyButtonDriver(a DigitalReader, name string, pin string, v ...time.Du
|
|||
// Name returns the MakeyButtonDrivers name
|
||||
func (b *MakeyButtonDriver) Name() string { return b.name }
|
||||
|
||||
// SetName sets the MakeyButtonDrivers name
|
||||
func (b *MakeyButtonDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// Pin returns the MakeyButtonDrivers pin
|
||||
func (b *MakeyButtonDriver) Pin() string { return b.pin }
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ var _ gobot.Driver = (*MakeyButtonDriver)(nil)
|
|||
const MAKEY_TEST_DELAY = 30
|
||||
|
||||
func initTestMakeyButtonDriver() *MakeyButtonDriver {
|
||||
return NewMakeyButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
return NewMakeyButtonDriver(newGpioTestAdaptor(), "1")
|
||||
}
|
||||
|
||||
func TestMakeyButtonDriverHalt(t *testing.T) {
|
||||
|
@ -26,11 +26,11 @@ func TestMakeyButtonDriverHalt(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMakeyButtonDriver(t *testing.T) {
|
||||
d := NewMakeyButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
d := NewMakeyButtonDriver(newGpioTestAdaptor(), "1")
|
||||
gobottest.Assert(t, d.Pin(), "1")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
d = NewMakeyButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1", 30*time.Second)
|
||||
d = NewMakeyButtonDriver(newGpioTestAdaptor(), "1", 30*time.Second)
|
||||
gobottest.Assert(t, d.interval, MAKEY_TEST_DELAY*time.Second)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,9 @@ type MotorDriver struct {
|
|||
CurrentDirection string
|
||||
}
|
||||
|
||||
// NewMotorDriver return a new MotorDriver given a DigitalWriter, name and pin
|
||||
func NewMotorDriver(a DigitalWriter, name string, speedPin string) *MotorDriver {
|
||||
// NewMotorDriver return a new MotorDriver given a DigitalWriter and pin
|
||||
func NewMotorDriver(a DigitalWriter, speedPin string) *MotorDriver {
|
||||
return &MotorDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
SpeedPin: speedPin,
|
||||
CurrentState: 0,
|
||||
|
@ -35,6 +34,9 @@ func NewMotorDriver(a DigitalWriter, name string, speedPin string) *MotorDriver
|
|||
// Name returns the MotorDrivers name
|
||||
func (m *MotorDriver) Name() string { return m.name }
|
||||
|
||||
// SetName sets the MotorDrivers name
|
||||
func (m *MotorDriver) SetName(n string) { m.name = n }
|
||||
|
||||
// Connection returns the MotorDrivers Connection
|
||||
func (m *MotorDriver) Connection() gobot.Connection { return m.connection.(gobot.Connection) }
|
||||
|
||||
|
|
|
@ -10,13 +10,12 @@ import (
|
|||
var _ gobot.Driver = (*MotorDriver)(nil)
|
||||
|
||||
func initTestMotorDriver() *MotorDriver {
|
||||
return NewMotorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
return NewMotorDriver(newGpioTestAdaptor(), "1")
|
||||
}
|
||||
|
||||
func TestMotorDriver(t *testing.T) {
|
||||
d := NewMotorDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
d := NewMotorDriver(newGpioTestAdaptor(), "1")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
}
|
||||
func TestMotorDriverStart(t *testing.T) {
|
||||
|
|
|
@ -11,15 +11,14 @@ type RelayDriver struct {
|
|||
gobot.Commander
|
||||
}
|
||||
|
||||
// NewRelayDriver return a new RelayDriver given a DigitalWriter, name and pin.
|
||||
// NewRelayDriver return a new RelayDriver given a DigitalWriter and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Toggle" - See RelayDriver.Toggle
|
||||
// "On" - See RelayDriver.On
|
||||
// "Off" - See RelayDriver.Off
|
||||
func NewRelayDriver(a DigitalWriter, name string, pin string) *RelayDriver {
|
||||
func NewRelayDriver(a DigitalWriter, pin string) *RelayDriver {
|
||||
l := &RelayDriver{
|
||||
name: name,
|
||||
pin: pin,
|
||||
connection: a,
|
||||
high: false,
|
||||
|
@ -50,6 +49,9 @@ func (l *RelayDriver) Halt() (errs []error) { return }
|
|||
// Name returns the RelayDrivers name
|
||||
func (l *RelayDriver) Name() string { return l.name }
|
||||
|
||||
// SetName sets the RelayDrivers name
|
||||
func (l *RelayDriver) SetName(n string) { l.name = n }
|
||||
|
||||
// Pin returns the RelayDrivers name
|
||||
func (l *RelayDriver) Pin() string { return l.pin }
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ type RgbLedDriver struct {
|
|||
gobot.Commander
|
||||
}
|
||||
|
||||
// NewRgbLedDriver return a new RgbLedDriver given a DigitalWriter, name and
|
||||
// NewRgbLedDriver return a new RgbLedDriver given a DigitalWriter and
|
||||
// 3 pins: redPin, greenPin, and bluePin
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
|
@ -24,9 +24,8 @@ type RgbLedDriver struct {
|
|||
// "Toggle" - See RgbLedDriver.Toggle
|
||||
// "On" - See RgbLedDriver.On
|
||||
// "Off" - See RgbLedDriver.Off
|
||||
func NewRgbLedDriver(a DigitalWriter, name string, redPin string, greenPin string, bluePin string) *RgbLedDriver {
|
||||
func NewRgbLedDriver(a DigitalWriter, redPin string, greenPin string, bluePin string) *RgbLedDriver {
|
||||
l := &RgbLedDriver{
|
||||
name: name,
|
||||
pinRed: redPin,
|
||||
pinGreen: greenPin,
|
||||
pinBlue: bluePin,
|
||||
|
@ -63,9 +62,12 @@ func (l *RgbLedDriver) Start() (errs []error) { return }
|
|||
// Halt implements the Driver interface
|
||||
func (l *RgbLedDriver) Halt() (errs []error) { return }
|
||||
|
||||
// Name returns the LedDrivers name
|
||||
// Name returns the RGBLEDDrivers name
|
||||
func (l *RgbLedDriver) Name() string { return l.name }
|
||||
|
||||
// SetName sets the RGBLEDDrivers name
|
||||
func (l *RgbLedDriver) SetName(n string) { l.name = n }
|
||||
|
||||
// Pin returns the RgbLedDrivers pins
|
||||
func (l *RgbLedDriver) Pin() string { return "r=" + l.pinRed + ", g=" + l.pinGreen + ", b=" + l.pinBlue }
|
||||
|
||||
|
|
|
@ -17,20 +17,19 @@ func initTestRgbLedDriver(conn DigitalWriter) *RgbLedDriver {
|
|||
testAdaptorPwmWrite = func() (err error) {
|
||||
return nil
|
||||
}
|
||||
return NewRgbLedDriver(conn, "bot", "1", "2", "3")
|
||||
return NewRgbLedDriver(conn, "1", "2", "3")
|
||||
}
|
||||
|
||||
func TestRgbLedDriver(t *testing.T) {
|
||||
var err interface{}
|
||||
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor())
|
||||
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Pin(), "r=1, g=2, b=3")
|
||||
gobottest.Assert(t, d.RedPin(), "1")
|
||||
gobottest.Assert(t, d.GreenPin(), "2")
|
||||
gobottest.Assert(t, d.BluePin(), "3")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
testAdaptorDigitalWrite = func() (err error) {
|
||||
return errors.New("write error")
|
||||
|
@ -54,17 +53,17 @@ func TestRgbLedDriver(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRgbLedDriverStart(t *testing.T) {
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Start()), 0)
|
||||
}
|
||||
|
||||
func TestRgbLedDriverHalt(t *testing.T) {
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor())
|
||||
gobottest.Assert(t, len(d.Halt()), 0)
|
||||
}
|
||||
|
||||
func TestRgbLedDriverToggle(t *testing.T) {
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d := initTestRgbLedDriver(newGpioTestAdaptor())
|
||||
d.Off()
|
||||
d.Toggle()
|
||||
gobottest.Assert(t, d.State(), true)
|
||||
|
@ -76,7 +75,7 @@ func TestRgbLedDriverSetLevel(t *testing.T) {
|
|||
d := initTestRgbLedDriver(&gpioTestDigitalWriter{})
|
||||
gobottest.Assert(t, d.SetLevel("1", 150), ErrPwmWriteUnsupported)
|
||||
|
||||
d = initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
|
||||
d = initTestRgbLedDriver(newGpioTestAdaptor())
|
||||
testAdaptorPwmWrite = func() (err error) {
|
||||
err = errors.New("pwm error")
|
||||
return
|
||||
|
|
|
@ -11,16 +11,15 @@ type ServoDriver struct {
|
|||
CurrentAngle byte
|
||||
}
|
||||
|
||||
// NewServoDriver returns a new ServoDriver given a ServoWriter, name and pin.
|
||||
// NewServoDriver returns a new ServoDriver given a ServoWriter and pin.
|
||||
//
|
||||
// Adds the following API Commands:
|
||||
// "Move" - See ServoDriver.Move
|
||||
// "Min" - See ServoDriver.Min
|
||||
// "Center" - See ServoDriver.Center
|
||||
// "Max" - See ServoDriver.Max
|
||||
func NewServoDriver(a ServoWriter, name string, pin string) *ServoDriver {
|
||||
func NewServoDriver(a ServoWriter, pin string) *ServoDriver {
|
||||
s := &ServoDriver{
|
||||
name: name,
|
||||
connection: a,
|
||||
pin: pin,
|
||||
Commander: gobot.NewCommander(),
|
||||
|
@ -48,6 +47,9 @@ func NewServoDriver(a ServoWriter, name string, pin string) *ServoDriver {
|
|||
// Name returns the ServoDrivers name
|
||||
func (s *ServoDriver) Name() string { return s.name }
|
||||
|
||||
// SetName sets the ServoDrivers name
|
||||
func (s *ServoDriver) SetName(n string) { s.name = n }
|
||||
|
||||
// Pin returns the ServoDrivers pin
|
||||
func (s *ServoDriver) Pin() string { return s.pin }
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
var _ gobot.Driver = (*ServoDriver)(nil)
|
||||
|
||||
func initTestServoDriver() *ServoDriver {
|
||||
return NewServoDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
|
||||
return NewServoDriver(newGpioTestAdaptor(), "1")
|
||||
}
|
||||
|
||||
func TestServoDriver(t *testing.T) {
|
||||
|
@ -19,9 +19,8 @@ func TestServoDriver(t *testing.T) {
|
|||
|
||||
d := initTestServoDriver()
|
||||
|
||||
gobottest.Assert(t, d.Name(), "bot")
|
||||
gobottest.Assert(t, d.Pin(), "1")
|
||||
gobottest.Assert(t, d.Connection().Name(), "adaptor")
|
||||
gobottest.Refute(t, d.Connection(), nil)
|
||||
|
||||
testAdaptorServoWrite = func() (err error) {
|
||||
return errors.New("pwm error")
|
||||
|
|
Loading…
Reference in New Issue