diff --git a/drivers/aio/README.md b/drivers/aio/README.md index 2f684f44..faa06cb6 100644 --- a/drivers/aio/README.md +++ b/drivers/aio/README.md @@ -12,7 +12,6 @@ go get -d -u gobot.io/x/gobot/... ## Hardware Support Gobot has a extensible system for connecting to hardware devices. The following AIO devices are currently supported: - Analog Sensor - - Direct Pin - Grove Light Sensor - Grove Rotary Dial - Grove Sound Sensor diff --git a/drivers/aio/direct_pin_driver.go b/drivers/aio/direct_pin_driver.go deleted file mode 100644 index 83788b28..00000000 --- a/drivers/aio/direct_pin_driver.go +++ /dev/null @@ -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 -} diff --git a/drivers/aio/direct_pin_driver_test.go b/drivers/aio/direct_pin_driver_test.go deleted file mode 100644 index caef7f34..00000000 --- a/drivers/aio/direct_pin_driver_test.go +++ /dev/null @@ -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) -}