core: update Intel Joule platform to simply return error

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-11-07 19:23:48 +01:00
parent e489918173
commit 4f4b24ff7d
3 changed files with 19 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"strconv" "strconv"
multierror "github.com/hashicorp/go-multierror"
"github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/sysfs" "github.com/hybridgroup/gobot/sysfs"
) )
@ -466,40 +467,38 @@ func (e *Adaptor) Name() string { return e.name }
func (e *Adaptor) SetName(n string) { e.name = n } func (e *Adaptor) SetName(n string) { e.name = n }
// Connect initializes the Joule for use with the Arduino beakout board // Connect initializes the Joule for use with the Arduino beakout board
func (e *Adaptor) Connect() (errs []error) { func (e *Adaptor) Connect() (err error) {
e.digitalPins = make(map[int]sysfs.DigitalPin) e.digitalPins = make(map[int]sysfs.DigitalPin)
e.pwmPins = make(map[int]*pwmPin) e.pwmPins = make(map[int]*pwmPin)
if err := e.connect(e); err != nil { err = e.connect(e)
return []error{err}
}
return return
} }
// Finalize releases all i2c devices and exported digital and pwm pins. // Finalize releases all i2c devices and exported digital and pwm pins.
func (e *Adaptor) Finalize() (errs []error) { func (e *Adaptor) Finalize() (err error) {
for _, pin := range e.digitalPins { for _, pin := range e.digitalPins {
if pin != nil { if pin != nil {
if err := pin.Unexport(); err != nil { if errs := pin.Unexport(); errs != nil {
errs = append(errs, err) err = multierror.Append(err, errs)
} }
} }
} }
for _, pin := range e.pwmPins { for _, pin := range e.pwmPins {
if pin != nil { if pin != nil {
if err := pin.enable("0"); err != nil { if errs := pin.enable("0"); errs != nil {
errs = append(errs, err) err = multierror.Append(err, errs)
} }
if err := pin.unexport(); err != nil { if errs := pin.unexport(); errs != nil {
errs = append(errs, err) err = multierror.Append(err, errs)
} }
} }
} }
if e.i2cDevice != nil { if e.i2cDevice != nil {
if err := e.i2cDevice.Close(); errs != nil { if errs := e.i2cDevice.Close(); errs != nil {
errs = append(errs, err) err = multierror.Append(err, errs)
} }
} }
return errs return
} }
// digitalPin returns matched digitalPin for specified values // digitalPin returns matched digitalPin for specified values

View File

@ -39,7 +39,7 @@ func (n *NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil return len(b), nil
} }
var closeErr error = nil var closeErr error
func (n *NullReadWriteCloser) Close() error { func (n *NullReadWriteCloser) Close() error {
return closeErr return closeErr
@ -128,7 +128,7 @@ func initTestAdaptor() (*Adaptor, *sysfs.MockFilesystem) {
func TestAdaptorConnect(t *testing.T) { func TestAdaptorConnect(t *testing.T) {
a, _ := initTestAdaptor() a, _ := initTestAdaptor()
gobottest.Assert(t, len(a.Connect()), 0) gobottest.Assert(t, a.Connect(), nil)
} }
func TestAdaptorFinalize(t *testing.T) { func TestAdaptorFinalize(t *testing.T) {
@ -139,11 +139,11 @@ func TestAdaptorFinalize(t *testing.T) {
sysfs.SetSyscall(&sysfs.MockSyscall{}) sysfs.SetSyscall(&sysfs.MockSyscall{})
a.I2cStart(0xff) a.I2cStart(0xff)
gobottest.Assert(t, len(a.Finalize()), 0) gobottest.Assert(t, a.Finalize(), nil)
closeErr = errors.New("close error") closeErr = errors.New("close error")
sysfs.SetFilesystem(sysfs.NewMockFilesystem([]string{})) sysfs.SetFilesystem(sysfs.NewMockFilesystem([]string{}))
gobottest.Refute(t, len(a.Finalize()), 0) gobottest.Refute(t, a.Finalize(), nil)
} }
func TestAdaptorDigitalIO(t *testing.T) { func TestAdaptorDigitalIO(t *testing.T) {

View File

@ -1,4 +1,5 @@
// TODO: move this into shared PWM package // package joule pwm implementation
// TODO: move this into shared Intel package
package joule package joule
import "strconv" import "strconv"