From 9edbf547c8ba060e200646ca904268edb5e34380 Mon Sep 17 00:00:00 2001 From: Issa Mathno Date: Wed, 23 May 2018 23:56:58 -0700 Subject: [PATCH] Fix joystick_driver to detect dpad input for xbox controllers --- platforms/joystick/joystick_driver.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platforms/joystick/joystick_driver.go b/platforms/joystick/joystick_driver.go index db49529f..b4cbe105 100644 --- a/platforms/joystick/joystick_driver.go +++ b/platforms/joystick/joystick_driver.go @@ -114,7 +114,8 @@ func (j *Driver) Start() (err error) { j.AddEvent(value.Name) } for _, value := range j.config.Hats { - j.AddEvent(value.Name) + j.AddEvent(fmt.Sprintf("%s_press", value.Name)) + j.AddEvent(fmt.Sprintf("%s_release", value.Name)) } go func() { @@ -140,6 +141,8 @@ func (j *Driver) Halt() (err error) { return } +var previousHat = "" + // HandleEvent publishes an specific event according to data received func (j *Driver) handleEvent(event sdl.Event) error { switch data := event.(type) { @@ -168,8 +171,13 @@ func (j *Driver) handleEvent(event sdl.Event) error { hat := j.findHatName(data.Value, data.Hat, j.config.Hats) if hat == "" { return fmt.Errorf("Unknown Hat: %v %v", data.Hat, data.Value) + } else if hat == "released" { + hat = previousHat + j.Publish(j.Event(fmt.Sprintf("%s_release", hat)), true) + } else { + previousHat = hat + j.Publish(j.Event(fmt.Sprintf("%s_press", hat)), true) } - j.Publish(j.Event(hat), true) } } return nil