core: update Intel Joule platform to simply return error
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
e489918173
commit
4f4b24ff7d
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"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 }
|
||||
|
||||
// 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.pwmPins = make(map[int]*pwmPin)
|
||||
if err := e.connect(e); err != nil {
|
||||
return []error{err}
|
||||
}
|
||||
err = e.connect(e)
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if pin != nil {
|
||||
if err := pin.Unexport(); err != nil {
|
||||
errs = append(errs, err)
|
||||
if errs := pin.Unexport(); errs != nil {
|
||||
err = multierror.Append(err, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, pin := range e.pwmPins {
|
||||
if pin != nil {
|
||||
if err := pin.enable("0"); err != nil {
|
||||
errs = append(errs, err)
|
||||
if errs := pin.enable("0"); errs != nil {
|
||||
err = multierror.Append(err, errs)
|
||||
}
|
||||
if err := pin.unexport(); err != nil {
|
||||
errs = append(errs, err)
|
||||
if errs := pin.unexport(); errs != nil {
|
||||
err = multierror.Append(err, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.i2cDevice != nil {
|
||||
if err := e.i2cDevice.Close(); errs != nil {
|
||||
errs = append(errs, err)
|
||||
if errs := e.i2cDevice.Close(); errs != nil {
|
||||
err = multierror.Append(err, errs)
|
||||
}
|
||||
}
|
||||
return errs
|
||||
return
|
||||
}
|
||||
|
||||
// digitalPin returns matched digitalPin for specified values
|
||||
|
|
|
@ -39,7 +39,7 @@ func (n *NullReadWriteCloser) Read(b []byte) (int, error) {
|
|||
return len(b), nil
|
||||
}
|
||||
|
||||
var closeErr error = nil
|
||||
var closeErr error
|
||||
|
||||
func (n *NullReadWriteCloser) Close() error {
|
||||
return closeErr
|
||||
|
@ -128,7 +128,7 @@ func initTestAdaptor() (*Adaptor, *sysfs.MockFilesystem) {
|
|||
|
||||
func TestAdaptorConnect(t *testing.T) {
|
||||
a, _ := initTestAdaptor()
|
||||
gobottest.Assert(t, len(a.Connect()), 0)
|
||||
gobottest.Assert(t, a.Connect(), nil)
|
||||
}
|
||||
|
||||
func TestAdaptorFinalize(t *testing.T) {
|
||||
|
@ -139,11 +139,11 @@ func TestAdaptorFinalize(t *testing.T) {
|
|||
sysfs.SetSyscall(&sysfs.MockSyscall{})
|
||||
a.I2cStart(0xff)
|
||||
|
||||
gobottest.Assert(t, len(a.Finalize()), 0)
|
||||
gobottest.Assert(t, a.Finalize(), nil)
|
||||
|
||||
closeErr = errors.New("close error")
|
||||
sysfs.SetFilesystem(sysfs.NewMockFilesystem([]string{}))
|
||||
gobottest.Refute(t, len(a.Finalize()), 0)
|
||||
gobottest.Refute(t, a.Finalize(), nil)
|
||||
}
|
||||
|
||||
func TestAdaptorDigitalIO(t *testing.T) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// TODO: move this into shared PWM package
|
||||
// package joule pwm implementation
|
||||
// TODO: move this into shared Intel package
|
||||
package joule
|
||||
|
||||
import "strconv"
|
||||
|
|
Loading…
Reference in New Issue