joystick: update scanner to match go-sdl 0.3 API changes

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans 2018-05-30 13:58:27 +02:00
parent 3d4b3b6169
commit 748cb2bb16
1 changed files with 9 additions and 11 deletions

View File

@ -44,18 +44,16 @@ func run() int {
case *sdl.JoyHatEvent: case *sdl.JoyHatEvent:
fmt.Printf("[%d ms] Hat:%d\tvalue:%d\n", fmt.Printf("[%d ms] Hat:%d\tvalue:%d\n",
t.Timestamp, t.Hat, t.Value) t.Timestamp, t.Hat, t.Value)
case *sdl.JoyDeviceEvent: case *sdl.JoyDeviceAddedEvent:
if t.Type == sdl.JOYDEVICEADDED {
joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which)) joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which))
if joysticks[int(t.Which)] != nil { if joysticks[int(t.Which)] != nil {
fmt.Printf("Joystick %d connected\n", t.Which) fmt.Printf("Joystick %d connected\n", t.Which)
} }
} else if t.Type == sdl.JOYDEVICEREMOVED { case *sdl.JoyDeviceRemovedEvent:
if joystick := joysticks[int(t.Which)]; joystick != nil { if joystick := joysticks[int(t.Which)]; joystick != nil {
joystick.Close() joystick.Close()
} }
fmt.Printf("Joystick %d disconnected\n", t.Which) fmt.Printf("Joystick %d disconnected\n", t.Which)
}
default: default:
fmt.Printf("Unknown event\n") fmt.Printf("Unknown event\n")
} }