Fix joystick_driver to detect dpad input for xbox controllers
This commit is contained in:
parent
b2ddfe7895
commit
9edbf547c8
|
@ -114,7 +114,8 @@ func (j *Driver) Start() (err error) {
|
||||||
j.AddEvent(value.Name)
|
j.AddEvent(value.Name)
|
||||||
}
|
}
|
||||||
for _, value := range j.config.Hats {
|
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() {
|
go func() {
|
||||||
|
@ -140,6 +141,8 @@ func (j *Driver) Halt() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var previousHat = ""
|
||||||
|
|
||||||
// HandleEvent publishes an specific event according to data received
|
// HandleEvent publishes an specific event according to data received
|
||||||
func (j *Driver) handleEvent(event sdl.Event) error {
|
func (j *Driver) handleEvent(event sdl.Event) error {
|
||||||
switch data := event.(type) {
|
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)
|
hat := j.findHatName(data.Value, data.Hat, j.config.Hats)
|
||||||
if hat == "" {
|
if hat == "" {
|
||||||
return fmt.Errorf("Unknown Hat: %v %v", data.Hat, data.Value)
|
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
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue