Fix joystick_driver to detect dpad input for xbox controllers

This commit is contained in:
Issa Mathno 2018-05-23 23:56:58 -07:00
parent b2ddfe7895
commit 9edbf547c8
1 changed files with 10 additions and 2 deletions

View File

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