From 4f4b24ff7da58f6e82b311ebd820e15675c71267 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Mon, 7 Nov 2016 19:23:48 +0100 Subject: [PATCH] core: update Intel Joule platform to simply return error Signed-off-by: deadprogram --- platforms/intel-iot/joule/joule_adaptor.go | 27 +++++++++---------- .../intel-iot/joule/joule_adaptor_test.go | 8 +++--- platforms/intel-iot/joule/pwm_pin.go | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/platforms/intel-iot/joule/joule_adaptor.go b/platforms/intel-iot/joule/joule_adaptor.go index 963922b5..9b46795d 100644 --- a/platforms/intel-iot/joule/joule_adaptor.go +++ b/platforms/intel-iot/joule/joule_adaptor.go @@ -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 diff --git a/platforms/intel-iot/joule/joule_adaptor_test.go b/platforms/intel-iot/joule/joule_adaptor_test.go index 57b646c3..f29fb843 100644 --- a/platforms/intel-iot/joule/joule_adaptor_test.go +++ b/platforms/intel-iot/joule/joule_adaptor_test.go @@ -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) { diff --git a/platforms/intel-iot/joule/pwm_pin.go b/platforms/intel-iot/joule/pwm_pin.go index 2b514ef3..69be55a4 100644 --- a/platforms/intel-iot/joule/pwm_pin.go +++ b/platforms/intel-iot/joule/pwm_pin.go @@ -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"