Update platforms for new gpio interfaces

This commit is contained in:
Adrian Zankich 2014-11-29 11:51:16 -08:00
parent 7819bb95d6
commit 89f3f53e09
10 changed files with 36 additions and 85 deletions

View File

@ -11,11 +11,18 @@ import (
"strings"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/sysfs"
)
var _ gobot.Adaptor = (*BeagleboneAdaptor)(nil)
var _ gpio.DigitalReader = (*BeagleboneAdaptor)(nil)
var _ gpio.DigitalWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.AnalogReader = (*BeagleboneAdaptor)(nil)
var _ gpio.PwmWriter = (*BeagleboneAdaptor)(nil)
var _ gpio.ServoWriter = (*BeagleboneAdaptor)(nil)
var slots = "/sys/devices/bone_capemgr.*"
var ocp = "/sys/devices/ocp.*"
var usrLed = "/sys/devices/ocp.3/gpio-leds.8/leds/beaglebone:green:"
@ -190,11 +197,6 @@ func (b *BeagleboneAdaptor) PwmWrite(pin string, val byte) (err error) {
return b.pwmWrite(pin, val)
}
// InitServo starts servo (not yet implemented)
func (b *BeagleboneAdaptor) InitServo() (err error) {
return errors.New("InitServo is not yet implemented")
}
// ServoWrite writes scaled value to servo in specified pin
func (b *BeagleboneAdaptor) ServoWrite(pin string, val byte) (err error) {
i, err := b.pwmPin(pin)
@ -257,11 +259,6 @@ func (b *BeagleboneAdaptor) AnalogRead(pin string) (val int, err error) {
return
}
// AnalogWrite writes an analog value to specified pin
func (b *BeagleboneAdaptor) AnalogWrite(pin string, val byte) (err error) {
return b.pwmWrite(pin, val)
}
// I2cStart starts a i2c device in specified address
func (b *BeagleboneAdaptor) I2cStart(address byte) (err error) {
b.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)

View File

@ -60,18 +60,6 @@ func TestBeagleboneAdaptor(t *testing.T) {
"156862",
)
a.AnalogWrite("P9_14", 175)
gobot.Assert(
t,
fs.Files["/sys/devices/ocp.3/pwm_test_P9_14.5/period"].Contents,
"500000",
)
gobot.Assert(
t,
fs.Files["/sys/devices/ocp.3/pwm_test_P9_14.5/duty"].Contents,
"156862",
)
a.ServoWrite("P9_14", 100)
gobot.Assert(
t,
@ -117,7 +105,4 @@ func TestBeagleboneAdaptor(t *testing.T) {
gobot.Assert(t, data, []byte{0x00, 0x01})
gobot.Assert(t, len(a.Finalize()), 0)
gobot.Assert(t, a.InitServo(), errors.New("InitServo is not yet implemented"))
}

View File

@ -6,10 +6,15 @@ import (
"strconv"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
)
var _ gobot.Adaptor = (*DigisparkAdaptor)(nil)
var _ gpio.DigitalWriter = (*DigisparkAdaptor)(nil)
var _ gpio.PwmWriter = (*DigisparkAdaptor)(nil)
var _ gpio.ServoWriter = (*DigisparkAdaptor)(nil)
type DigisparkAdaptor struct {
name string
littleWire lw
@ -61,12 +66,6 @@ func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) (err error) {
return
}
// DigitalRead (not yet implemented)
func (d *DigisparkAdaptor) DigitalRead(pin string) (val int, err error) {
err = errors.New("DigitalRead is not yet implemented")
return
}
// PwmWrite updates pwm pin with sent value
func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) {
if d.pwm == false {
@ -84,11 +83,6 @@ func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) {
return
}
// InitServo (not yet implemented)
func (d *DigisparkAdaptor) InitServo() (err error) {
return errors.New("InitServo is not yet implemented")
}
// ServoWrite updates servo location with specified angle
func (d *DigisparkAdaptor) ServoWrite(pin string, angle uint8) (err error) {
if d.servo == false {

View File

@ -66,8 +66,6 @@ func TestDigisparkAdaptorFinalize(t *testing.T) {
func TestDigisparkAdaptorIO(t *testing.T) {
a := initTestDigisparkAdaptor()
a.InitServo()
a.DigitalRead("1")
a.DigitalWrite("0", uint8(1))
gobot.Assert(t, a.littleWire.(*mock).pin, uint8(0))
gobot.Assert(t, a.littleWire.(*mock).state, uint8(1))

View File

@ -1,18 +1,24 @@
package firmata
import (
"errors"
"fmt"
"io"
"strconv"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/tarm/goserial"
)
var _ gobot.Adaptor = (*FirmataAdaptor)(nil)
var _ gpio.DigitalReader = (*FirmataAdaptor)(nil)
var _ gpio.DigitalWriter = (*FirmataAdaptor)(nil)
var _ gpio.AnalogReader = (*FirmataAdaptor)(nil)
var _ gpio.PwmWriter = (*FirmataAdaptor)(nil)
var _ gpio.ServoWriter = (*FirmataAdaptor)(nil)
type FirmataAdaptor struct {
name string
port string
@ -88,11 +94,6 @@ func (f *FirmataAdaptor) Finalize() (errs []error) {
func (f *FirmataAdaptor) Port() string { return f.port }
func (f *FirmataAdaptor) Name() string { return f.name }
// InitServo (not yet implemented)
func (f *FirmataAdaptor) InitServo() (err error) {
return errors.New("InitServo is not yet implemented")
}
// ServoWrite sets angle form 0 to 360 to specified servo pin
func (f *FirmataAdaptor) ServoWrite(pin string, angle byte) (err error) {
p, err := strconv.Atoi(pin)
@ -205,11 +206,6 @@ func (f *FirmataAdaptor) AnalogRead(pin string) (val int, err error) {
return -1, nil
}
// AnalogWrite writes value to ananlog pin
func (f *FirmataAdaptor) AnalogWrite(pin string, level byte) (err error) {
return f.PwmWrite(pin, level)
}
// digitalPin converts pin number to digital mapping
func (f *FirmataAdaptor) digitalPin(pin int) int {
return pin + 14

View File

@ -48,11 +48,6 @@ func TestFirmataAdaptorConnect(t *testing.T) {
gobot.Assert(t, a.connect(a), nil)
}
func TestFirmataAdaptorInitServo(t *testing.T) {
a := initTestFirmataAdaptor()
a.InitServo()
}
func TestFirmataAdaptorServoWrite(t *testing.T) {
a := initTestFirmataAdaptor()
a.ServoWrite("1", 50)
@ -106,10 +101,7 @@ func TestFirmataAdaptorAnalogRead(t *testing.T) {
val, _ = a.AnalogRead(pinNumber)
gobot.Assert(t, val, 133)
}
func TestFirmataAdaptorAnalogWrite(t *testing.T) {
a := initTestFirmataAdaptor()
a.AnalogWrite("1", 50)
}
func TestFirmataAdaptorI2cStart(t *testing.T) {
a := initTestFirmataAdaptor()
a.I2cStart(0x00)

View File

@ -7,11 +7,17 @@ import (
"strconv"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/sysfs"
)
var _ gobot.Adaptor = (*EdisonAdaptor)(nil)
var _ gpio.DigitalReader = (*EdisonAdaptor)(nil)
var _ gpio.DigitalWriter = (*EdisonAdaptor)(nil)
var _ gpio.AnalogReader = (*EdisonAdaptor)(nil)
var _ gpio.PwmWriter = (*EdisonAdaptor)(nil)
func writeFile(path string, data []byte) (i int, err error) {
file, err := sysfs.OpenFile(path, os.O_WRONLY, 0644)
defer file.Close()
@ -422,21 +428,6 @@ func (e *EdisonAdaptor) PwmWrite(pin string, val byte) (err error) {
return errors.New("Not a PWM pin")
}
// AnalogWrite Not Implemented
func (e *EdisonAdaptor) AnalogWrite(string, byte) (err error) {
return errors.New("AnalogWrite is not yet implemented")
}
// InitServo Not Implemented
func (e *EdisonAdaptor) InitServo() (err error) {
return errors.New("InitServo is not yet implemented")
}
// ServoWrite Not Implemented
func (e *EdisonAdaptor) ServoWrite(string, byte) (err error) {
return errors.New("ServoWrite is not yet implemented")
}
// AnalogRead returns value from analog reading of specified pin
func (e *EdisonAdaptor) AnalogRead(pin string) (val int, err error) {
buf, err := readFile(

View File

@ -139,10 +139,3 @@ func TestEdisonAdaptorAnalog(t *testing.T) {
i, _ := a.AnalogRead("0")
gobot.Assert(t, i, 1000)
}
func TestEdisonAdaptorNotImplemented(t *testing.T) {
a, _ := initTestEdisonAdaptor()
gobot.Assert(t, a.AnalogWrite("", 100), errors.New("AnalogWrite is not yet implemented"))
gobot.Assert(t, a.InitServo(), errors.New("InitServo is not yet implemented"))
gobot.Assert(t, a.ServoWrite("", 100), errors.New("ServoWrite is not yet implemented"))
}

View File

@ -10,11 +10,15 @@ import (
"strings"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/sysfs"
)
var _ gobot.Adaptor = (*RaspiAdaptor)(nil)
var _ gpio.DigitalReader = (*RaspiAdaptor)(nil)
var _ gpio.DigitalWriter = (*RaspiAdaptor)(nil)
var boardRevision = func() (string, string) {
cat, _ := exec.Command("cat", "/proc/cpuinfo").Output()
grep := exec.Command("grep", "Revision")
@ -221,11 +225,6 @@ func (r *RaspiAdaptor) DigitalWrite(pin string, val byte) (err error) {
return sysfsPin.Write(int(val))
}
// PwmWrite Not Implemented
func (r *RaspiAdaptor) PwmWrite(pin string, val byte) (err error) {
return errors.New("PwmWrite is not yet implemented.")
}
// I2cStart starts a i2c device in specified address
func (r *RaspiAdaptor) I2cStart(address byte) (err error) {
r.i2cDevice, err = sysfs.NewI2cDevice(r.i2cLocation, address)

View File

@ -9,10 +9,16 @@ import (
"net/url"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
)
var _ gobot.Adaptor = (*SparkCoreAdaptor)(nil)
var _ gpio.DigitalReader = (*SparkCoreAdaptor)(nil)
var _ gpio.DigitalWriter = (*SparkCoreAdaptor)(nil)
var _ gpio.AnalogReader = (*SparkCoreAdaptor)(nil)
var _ gpio.PwmWriter = (*SparkCoreAdaptor)(nil)
type SparkCoreAdaptor struct {
name string
DeviceID string