diff --git a/platforms/joystick/joystick_adaptor.go b/platforms/joystick/joystick_adaptor.go index 55f723c3..57faa0d1 100644 --- a/platforms/joystick/joystick_adaptor.go +++ b/platforms/joystick/joystick_adaptor.go @@ -40,15 +40,13 @@ func (j *Adaptor) Name() string { return j.name } func (j *Adaptor) SetName(n string) { j.name = n } // Connect connects to the joystick -func (j *Adaptor) Connect() (errs []error) { - if err := j.connect(j); err != nil { - return []error{err} - } +func (j *Adaptor) Connect() (err error) { + err = j.connect(j) return } // Finalize closes connection to joystick -func (j *Adaptor) Finalize() (errs []error) { +func (j *Adaptor) Finalize() (err error) { j.joystick.Close() return } diff --git a/platforms/joystick/joystick_adaptor_test.go b/platforms/joystick/joystick_adaptor_test.go index 8dd38d0c..0968ff9a 100644 --- a/platforms/joystick/joystick_adaptor_test.go +++ b/platforms/joystick/joystick_adaptor_test.go @@ -21,14 +21,14 @@ func initTestAdaptor() *Adaptor { func TestAdaptorConnect(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, len(a.Connect()), 0) + gobottest.Assert(t, a.Connect(), nil) a = NewAdaptor() - gobottest.Assert(t, a.Connect()[0], errors.New("No joystick available")) + gobottest.Assert(t, a.Connect(), errors.New("No joystick available")) } func TestAdaptorFinalize(t *testing.T) { a := initTestAdaptor() a.Connect() - gobottest.Assert(t, len(a.Finalize()), 0) + gobottest.Assert(t, a.Finalize(), nil) } diff --git a/platforms/joystick/joystick_driver.go b/platforms/joystick/joystick_driver.go index 151de20e..c9ccc263 100644 --- a/platforms/joystick/joystick_driver.go +++ b/platforms/joystick/joystick_driver.go @@ -94,10 +94,10 @@ func (j *Driver) adaptor() *Adaptor { // [button]_press // [button]_release // [axis] -func (j *Driver) Start() (errs []error) { - file, err := ioutil.ReadFile(j.configPath) - if err != nil { - return []error{err} +func (j *Driver) Start() (err error) { + file, e := ioutil.ReadFile(j.configPath) + if e != nil { + return e } var jsontype joystickConfig @@ -118,8 +118,8 @@ func (j *Driver) Start() (errs []error) { go func() { for { for event := j.poll(); event != nil; event = j.poll() { - if err = j.handleEvent(event); err != nil { - j.Publish(j.Event("error"), err) + if errs := j.handleEvent(event); errs != nil { + j.Publish(j.Event("error"), errs) } } select { @@ -133,7 +133,7 @@ func (j *Driver) Start() (errs []error) { } // Halt stops joystick driver -func (j *Driver) Halt() (errs []error) { +func (j *Driver) Halt() (err error) { j.halt <- true return } diff --git a/platforms/joystick/joystick_driver_test.go b/platforms/joystick/joystick_driver_test.go index b4edaea0..19d0c4e9 100644 --- a/platforms/joystick/joystick_driver_test.go +++ b/platforms/joystick/joystick_driver_test.go @@ -28,8 +28,8 @@ func initTestDriver() *Driver { func TestDriverStart(t *testing.T) { d := initTestDriver() d.interval = 1 * time.Millisecond - gobottest.Assert(t, len(d.Start()), 0) - <-time.After(2 * time.Millisecond) + gobottest.Assert(t, d.Start(), nil) + time.Sleep(2 * time.Millisecond) } func TestDriverHalt(t *testing.T) { @@ -37,7 +37,7 @@ func TestDriverHalt(t *testing.T) { go func() { <-d.halt }() - gobottest.Assert(t, len(d.Halt()), 0) + gobottest.Assert(t, d.Halt(), nil) } func TestDriverHandleEvent(t *testing.T) {