mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
aio: remove direct pin, does not make sens here
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
a4dc5c690f
commit
d7cd235e7f
@ -12,7 +12,6 @@ go get -d -u gobot.io/x/gobot/...
|
|||||||
## Hardware Support
|
## Hardware Support
|
||||||
Gobot has a extensible system for connecting to hardware devices. The following AIO devices are currently supported:
|
Gobot has a extensible system for connecting to hardware devices. The following AIO devices are currently supported:
|
||||||
- Analog Sensor
|
- Analog Sensor
|
||||||
- Direct Pin
|
|
||||||
- Grove Light Sensor
|
- Grove Light Sensor
|
||||||
- Grove Rotary Dial
|
- Grove Rotary Dial
|
||||||
- Grove Sound Sensor
|
- Grove Sound Sensor
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
package aio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gobot.io/x/gobot"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DirectPinDriver represents a AIO pin
|
|
||||||
type DirectPinDriver struct {
|
|
||||||
name string
|
|
||||||
pin string
|
|
||||||
connection gobot.Connection
|
|
||||||
gobot.Commander
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDirectPinDriver return a new DirectPinDriver given a Connection and pin.
|
|
||||||
//
|
|
||||||
// Adds the following API Command:
|
|
||||||
// "AnalogRead" - See DirectPinDriver.AnalogRead
|
|
||||||
func NewDirectPinDriver(a gobot.Connection, pin string) *DirectPinDriver {
|
|
||||||
d := &DirectPinDriver{
|
|
||||||
name: "DirectPin",
|
|
||||||
connection: a,
|
|
||||||
pin: pin,
|
|
||||||
Commander: gobot.NewCommander(),
|
|
||||||
}
|
|
||||||
|
|
||||||
d.AddCommand("AnalogRead", func(params map[string]interface{}) interface{} {
|
|
||||||
val, err := d.AnalogRead()
|
|
||||||
return map[string]interface{}{"val": val, "err": err}
|
|
||||||
})
|
|
||||||
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 }
|
|
||||||
|
|
||||||
// Connection returns the DirectPinDrivers Connection
|
|
||||||
func (d *DirectPinDriver) Connection() gobot.Connection { return d.connection }
|
|
||||||
|
|
||||||
// Start implements the Driver interface
|
|
||||||
func (d *DirectPinDriver) Start() (err error) { return }
|
|
||||||
|
|
||||||
// Halt implements the Driver interface
|
|
||||||
func (d *DirectPinDriver) Halt() (err error) { return }
|
|
||||||
|
|
||||||
// AnalogRead reads the current analog reading of the pin
|
|
||||||
func (d *DirectPinDriver) AnalogRead() (val int, err error) {
|
|
||||||
if reader, ok := d.Connection().(AnalogReader); ok {
|
|
||||||
return reader.AnalogRead(d.Pin())
|
|
||||||
}
|
|
||||||
err = ErrAnalogReadUnsupported
|
|
||||||
return
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package aio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"gobot.io/x/gobot"
|
|
||||||
"gobot.io/x/gobot/gobottest"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ gobot.Driver = (*DirectPinDriver)(nil)
|
|
||||||
|
|
||||||
func initTestDirectPinDriver(conn gobot.Connection) *DirectPinDriver {
|
|
||||||
testAdaptorAnalogRead = func() (val int, err error) {
|
|
||||||
val = 80
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return NewDirectPinDriver(conn, "1")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDirectPinDriver(t *testing.T) {
|
|
||||||
var ret map[string]interface{}
|
|
||||||
|
|
||||||
d := initTestDirectPinDriver(newAioTestAdaptor())
|
|
||||||
gobottest.Assert(t, d.Pin(), "1")
|
|
||||||
gobottest.Refute(t, d.Connection(), nil)
|
|
||||||
|
|
||||||
ret = d.Command("AnalogRead")(nil).(map[string]interface{})
|
|
||||||
|
|
||||||
gobottest.Assert(t, ret["val"].(int), 80)
|
|
||||||
gobottest.Assert(t, ret["err"], nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDirectPinDriverStart(t *testing.T) {
|
|
||||||
d := initTestDirectPinDriver(newAioTestAdaptor())
|
|
||||||
gobottest.Assert(t, d.Start(), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDirectPinDriverHalt(t *testing.T) {
|
|
||||||
d := initTestDirectPinDriver(newAioTestAdaptor())
|
|
||||||
gobottest.Assert(t, d.Halt(), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDirectPinDriverAnalogRead(t *testing.T) {
|
|
||||||
d := initTestDirectPinDriver(newAioTestAdaptor())
|
|
||||||
ret, err := d.AnalogRead()
|
|
||||||
gobottest.Assert(t, ret, 80)
|
|
||||||
|
|
||||||
d = initTestDirectPinDriver(&aioTestBareAdaptor{})
|
|
||||||
ret, err = d.AnalogRead()
|
|
||||||
gobottest.Assert(t, err, ErrAnalogReadUnsupported)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user