1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00

core: update Joystick platform to simply return error

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-11-07 19:32:12 +01:00
parent 4f4b24ff7d
commit af21d98074
4 changed files with 16 additions and 18 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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) {