From a8e7a3d3fbb102f051fbda8940439bb269d78f2a Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sat, 9 Sep 2023 13:55:56 +0200 Subject: [PATCH] platforms/joystick: handle OS differences for dualshock3 and remove hat since it is not handled in the current joystick package Signed-off-by: deadprogram --- platforms/joystick/joystick_driver.go | 10 -- platforms/joystick/joystick_driver_test.go | 3 - platforms/joystick/joystick_dualsense.go | 1 - .../joystick/joystick_dualshock3_darwin.go | 86 +++++++++++++++++ .../joystick/joystick_dualshock3_linux.go | 94 +++++++++++++++++++ ...ock3.go => joystick_dualshock3_windows.go} | 0 platforms/joystick/joystick_dualshock4.go | 27 ------ .../joystick/joystick_nintendo_joycon.go | 1 - platforms/joystick/joystick_shield.go | 27 ------ .../joystick/joystick_tflight_hotas_x.go | 7 -- platforms/joystick/joystick_xbox360.go | 47 ---------- .../joystick_xbox360_rock_band_drums.go | 1 - platforms/joystick/joystick_xboxone.go | 27 ------ 13 files changed, 180 insertions(+), 151 deletions(-) create mode 100644 platforms/joystick/joystick_dualshock3_darwin.go create mode 100644 platforms/joystick/joystick_dualshock3_linux.go rename platforms/joystick/{joystick_dualshock3.go => joystick_dualshock3_windows.go} (100%) diff --git a/platforms/joystick/joystick_driver.go b/platforms/joystick/joystick_driver.go index 1db3fcc78..da0e96728 100644 --- a/platforms/joystick/joystick_driver.go +++ b/platforms/joystick/joystick_driver.go @@ -59,20 +59,12 @@ type pair struct { ID int `json:"id"` } -// hat is a JSON representation of hat, name and id -type hat struct { - Hat int `json:"hat"` - Name string `json:"name"` - ID int `json:"id"` -} - // joystickConfig is a JSON representation of configuration values type joystickConfig struct { Name string `json:"name"` GUID string `json:"guid"` Axis []pair `json:"axis"` Buttons []pair `json:"buttons"` - Hats []hat `json:"Hats"` } // NewDriver returns a new Driver with a polling interval of @@ -188,8 +180,6 @@ func (j *Driver) Halt() (err error) { return } -var previousHat = "" - func (j *Driver) handleButtons(state js.State) error { for button := 0; button < j.adaptor().joystick.ButtonCount(); button++ { switch { diff --git a/platforms/joystick/joystick_driver_test.go b/platforms/joystick/joystick_driver_test.go index 7fd6647e2..a98d10163 100644 --- a/platforms/joystick/joystick_driver_test.go +++ b/platforms/joystick/joystick_driver_test.go @@ -19,9 +19,6 @@ func initTestDriver(config string) *Driver { } _ = a.Connect() d := NewDriver(a, config) - // d.poll = func() sdl.Event { - // return nil - // } return d } diff --git a/platforms/joystick/joystick_dualsense.go b/platforms/joystick/joystick_dualsense.go index ea17486f1..9827aed47 100644 --- a/platforms/joystick/joystick_dualsense.go +++ b/platforms/joystick/joystick_dualsense.go @@ -91,5 +91,4 @@ var dualsenseConfig = joystickConfig{ ID: 15, }, }, - Hats: []hat{}, } diff --git a/platforms/joystick/joystick_dualshock3_darwin.go b/platforms/joystick/joystick_dualshock3_darwin.go new file mode 100644 index 000000000..09dd31afd --- /dev/null +++ b/platforms/joystick/joystick_dualshock3_darwin.go @@ -0,0 +1,86 @@ +package joystick + +var dualshock3Config = joystickConfig{ + Name: "Dualshock3 Controller", + GUID: "1111", + Axis: []pair{ + { + Name: "left_x", + ID: 0, + }, + { + Name: "left_y", + ID: 1, + }, + { + Name: "right_x", + ID: 2, + }, + { + Name: "right_y", + ID: 3, + }, + }, + Buttons: []pair{ + { + Name: "square", + ID: 15, + }, + { + Name: "triangle", + ID: 12, + }, + { + Name: "circle", + ID: 13, + }, + { + Name: "x", + ID: 14, + }, + { + Name: "up", + ID: 4, + }, + { + Name: "down", + ID: 6, + }, + { + Name: "left", + ID: 17, + }, + { + Name: "right", + ID: 5, + }, + { + Name: "l1", + ID: 10, + }, + { + Name: "l2", + ID: 8, + }, + { + Name: "r1", + ID: 11, + }, + { + Name: "r2", + ID: 9, + }, + { + Name: "start", + ID: 3, + }, + { + Name: "select", + ID: 0, + }, + { + Name: "home", + ID: 16, + }, + }, +} diff --git a/platforms/joystick/joystick_dualshock3_linux.go b/platforms/joystick/joystick_dualshock3_linux.go new file mode 100644 index 000000000..19578f8ec --- /dev/null +++ b/platforms/joystick/joystick_dualshock3_linux.go @@ -0,0 +1,94 @@ +package joystick + +var dualshock3Config = joystickConfig{ + Name: "Dualshock3 Controller", + GUID: "1111", + Axis: []pair{ + { + Name: "left_x", + ID: 0, + }, + { + Name: "left_y", + ID: 1, + }, + { + Name: "l2", + ID: 2, + }, + { + Name: "right_x", + ID: 3, + }, + { + Name: "right_y", + ID: 4, + }, + { + Name: "r2", + ID: 5, + }, + }, + Buttons: []pair{ + { + Name: "square", + ID: 3, + }, + { + Name: "triangle", + ID: 2, + }, + { + Name: "circle", + ID: 1, + }, + { + Name: "x", + ID: 0, + }, + { + Name: "up", + ID: 13, + }, + { + Name: "down", + ID: 14, + }, + { + Name: "left", + ID: 15, + }, + { + Name: "right", + ID: 16, + }, + { + Name: "l1", + ID: 4, + }, + { + Name: "l2", + ID: 6, + }, + { + Name: "r1", + ID: 5, + }, + { + Name: "r2", + ID: 7, + }, + { + Name: "start", + ID: 9, + }, + { + Name: "select", + ID: 8, + }, + { + Name: "home", + ID: 10, + }, + }, +} diff --git a/platforms/joystick/joystick_dualshock3.go b/platforms/joystick/joystick_dualshock3_windows.go similarity index 100% rename from platforms/joystick/joystick_dualshock3.go rename to platforms/joystick/joystick_dualshock3_windows.go diff --git a/platforms/joystick/joystick_dualshock4.go b/platforms/joystick/joystick_dualshock4.go index cb1bdb5d6..77d4dcc80 100644 --- a/platforms/joystick/joystick_dualshock4.go +++ b/platforms/joystick/joystick_dualshock4.go @@ -75,31 +75,4 @@ var dualshock4Config = joystickConfig{ ID: 10, }, }, - Hats: []hat{ - { - Hat: 0, - Name: "down", - ID: 4, - }, - { - Hat: 0, - Name: "up", - ID: 1, - }, - { - Hat: 0, - Name: "left", - ID: 8, - }, - { - Hat: 0, - Name: "right", - ID: 2, - }, - { - Hat: 0, - Name: "released", - ID: 0, - }, - }, } diff --git a/platforms/joystick/joystick_nintendo_joycon.go b/platforms/joystick/joystick_nintendo_joycon.go index 4226ab1df..501bc8114 100644 --- a/platforms/joystick/joystick_nintendo_joycon.go +++ b/platforms/joystick/joystick_nintendo_joycon.go @@ -111,5 +111,4 @@ var joyconPairConfig = joystickConfig{ ID: 6, }, }, - Hats: []hat{}, } diff --git a/platforms/joystick/joystick_shield.go b/platforms/joystick/joystick_shield.go index dd6a70e00..8f3f2989b 100644 --- a/platforms/joystick/joystick_shield.go +++ b/platforms/joystick/joystick_shield.go @@ -75,31 +75,4 @@ var shieldConfig = joystickConfig{ ID: 9, }, }, - Hats: []hat{ - { - Hat: 0, - Name: "down", - ID: 4, - }, - { - Hat: 0, - Name: "up", - ID: 1, - }, - { - Hat: 0, - Name: "left", - ID: 8, - }, - { - Hat: 0, - Name: "right", - ID: 2, - }, - { - Hat: 0, - Name: "released", - ID: 0, - }, - }, } diff --git a/platforms/joystick/joystick_tflight_hotas_x.go b/platforms/joystick/joystick_tflight_hotas_x.go index 280346dd6..8cdb1bab8 100644 --- a/platforms/joystick/joystick_tflight_hotas_x.go +++ b/platforms/joystick/joystick_tflight_hotas_x.go @@ -24,11 +24,4 @@ var tflightHotasXConfig = joystickConfig{ {Name: "select", ID: 10}, {Name: "start", ID: 11}, }, - Hats: []hat{ - {Hat: 0, Name: "down", ID: 4}, - {Hat: 0, Name: "up", ID: 1}, - {Hat: 0, Name: "left", ID: 8}, - {Hat: 0, Name: "right", ID: 2}, - {Hat: 0, Name: "released", ID: 0}, - }, } diff --git a/platforms/joystick/joystick_xbox360.go b/platforms/joystick/joystick_xbox360.go index 6658b7097..02fa88666 100644 --- a/platforms/joystick/joystick_xbox360.go +++ b/platforms/joystick/joystick_xbox360.go @@ -75,51 +75,4 @@ var xbox360Config = joystickConfig{ ID: 9, }, }, - Hats: []hat{ - { - Hat: 0, - Name: "down", - ID: 4, - }, - { - Hat: 0, - Name: "up", - ID: 1, - }, - { - Hat: 0, - Name: "left", - ID: 8, - }, - { - Hat: 0, - Name: "upLeft", - ID: 9, - }, - { - Hat: 0, - Name: "downLeft", - ID: 12, - }, - { - Hat: 0, - Name: "right", - ID: 2, - }, - { - Hat: 0, - Name: "upRight", - ID: 3, - }, - { - Hat: 0, - Name: "downRight", - ID: 6, - }, - { - Hat: 0, - Name: "released", - ID: 0, - }, - }, } diff --git a/platforms/joystick/joystick_xbox360_rock_band_drums.go b/platforms/joystick/joystick_xbox360_rock_band_drums.go index c6c02a738..eaa9d3054 100644 --- a/platforms/joystick/joystick_xbox360_rock_band_drums.go +++ b/platforms/joystick/joystick_xbox360_rock_band_drums.go @@ -54,5 +54,4 @@ var xbox360RockBandDrumsConfig = joystickConfig{ ID: 14, }, }, - Hats: []hat{}, } diff --git a/platforms/joystick/joystick_xboxone.go b/platforms/joystick/joystick_xboxone.go index 76d085e36..e3cf49958 100644 --- a/platforms/joystick/joystick_xboxone.go +++ b/platforms/joystick/joystick_xboxone.go @@ -75,31 +75,4 @@ var xboxOneConfig = joystickConfig{ ID: 8, }, }, - Hats: []hat{ - { - Hat: 0, - Name: "down", - ID: 4, - }, - { - Hat: 0, - Name: "up", - ID: 1, - }, - { - Hat: 0, - Name: "left", - ID: 8, - }, - { - Hat: 0, - Name: "right", - ID: 2, - }, - { - Hat: 0, - Name: "released", - ID: 0, - }, - }, }