Skip to content

Commit

Permalink
platforms/joystick: handle OS differences for dualshock3 and remove h…
Browse files Browse the repository at this point in the history
…at since it is not handled in the current joystick package

Signed-off-by: deadprogram <ron@hybridgroup.com>
  • Loading branch information
deadprogram committed Sep 9, 2023
1 parent 2891173 commit a8e7a3d
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 151 deletions.
10 changes: 0 additions & 10 deletions platforms/joystick/joystick_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions platforms/joystick/joystick_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ func initTestDriver(config string) *Driver {
}
_ = a.Connect()
d := NewDriver(a, config)
// d.poll = func() sdl.Event {
// return nil
// }
return d
}

Expand Down
1 change: 0 additions & 1 deletion platforms/joystick/joystick_dualsense.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ var dualsenseConfig = joystickConfig{
ID: 15,
},
},
Hats: []hat{},
}
86 changes: 86 additions & 0 deletions platforms/joystick/joystick_dualshock3_darwin.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
94 changes: 94 additions & 0 deletions platforms/joystick/joystick_dualshock3_linux.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
File renamed without changes.
27 changes: 0 additions & 27 deletions platforms/joystick/joystick_dualshock4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
1 change: 0 additions & 1 deletion platforms/joystick/joystick_nintendo_joycon.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ var joyconPairConfig = joystickConfig{
ID: 6,
},
},
Hats: []hat{},
}
27 changes: 0 additions & 27 deletions platforms/joystick/joystick_shield.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
7 changes: 0 additions & 7 deletions platforms/joystick/joystick_tflight_hotas_x.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}
47 changes: 0 additions & 47 deletions platforms/joystick/joystick_xbox360.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
1 change: 0 additions & 1 deletion platforms/joystick/joystick_xbox360_rock_band_drums.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ var xbox360RockBandDrumsConfig = joystickConfig{
ID: 14,
},
},
Hats: []hat{},
}
27 changes: 0 additions & 27 deletions platforms/joystick/joystick_xboxone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}

0 comments on commit a8e7a3d

Please sign in to comment.