From 3466c4e30a50d19b42b2182e4f1fb8ead2e506d3 Mon Sep 17 00:00:00 2001 From: thomast75 <62158572+ThomasT75@users.noreply.github.com> Date: Tue, 20 Feb 2024 06:10:11 -0300 Subject: [PATCH 1/4] fixes weak HatPress/Release() force --- gamepad.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gamepad.go b/gamepad.go index 88f759d..e15d63b 100644 --- a/gamepad.go +++ b/gamepad.go @@ -199,22 +199,22 @@ func (vg vGamepad) sendHatEvent(direction HatDirection, action HatAction) error case HatUp: { event = absHat0Y - value = -1 + value = -MaximumAxisValue } case HatDown: { event = absHat0Y - value = 1 + value = MaximumAxisValue } case HatLeft: { event = absHat0X - value = -1 + value = -MaximumAxisValue } case HatRight: { event = absHat0X - value = 1 + value = MaximumAxisValue } default: { From a9010087ba29a6aeaed1dd86db20d32b73549cdf Mon Sep 17 00:00:00 2001 From: thomast75 <62158572+ThomasT75@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:10:09 -0300 Subject: [PATCH 2/4] adds 2 new functions for trigger-axis control --- gamepad.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gamepad.go b/gamepad.go index e15d63b..d2ec1d0 100644 --- a/gamepad.go +++ b/gamepad.go @@ -61,6 +61,11 @@ type Gamepad interface { // HatRelease will issue a hat-release event in the given direction HatRelease(direction HatDirection) error + // LeftTriggerForce performs a trigger-axis-z event with a given force + LeftTriggerForce(value float32) error + // RightTriggerForce performs a trigger-axis-rz event with a given force + RightTriggerForce(value float32) error + io.Closer } @@ -125,6 +130,14 @@ func (vg vGamepad) RightStickMoveY(value float32) error { return vg.sendStickAxisEvent(absRY, value) } +func (vg vGamepad) LeftTriggerForce(value float32) error { + return vg.sendStickAxisEvent(absZ, value) +} + +func (vg vGamepad) RightTriggerForce(value float32) error { + return vg.sendStickAxisEvent(absRZ, value) +} + func (vg vGamepad) RightStickMove(x, y float32) error { values := map[uint16]float32{} values[absRX] = x From fd21d80e2119b6917cb51a4ad89d9e346f2555ee Mon Sep 17 00:00:00 2001 From: thomast75 <62158572+ThomasT75@users.noreply.github.com> Date: Thu, 29 Feb 2024 02:27:32 -0300 Subject: [PATCH 3/4] gamepad: specify Absmin/max in uinputUserDev also I reverted hat force to -1:1 but set the Absmin/max to -1:1 --- gamepad.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/gamepad.go b/gamepad.go index d2ec1d0..ba7f8b1 100644 --- a/gamepad.go +++ b/gamepad.go @@ -212,22 +212,22 @@ func (vg vGamepad) sendHatEvent(direction HatDirection, action HatAction) error case HatUp: { event = absHat0Y - value = -MaximumAxisValue + value = -1 } case HatDown: { event = absHat0Y - value = MaximumAxisValue + value = 1 } case HatLeft: { event = absHat0X - value = -MaximumAxisValue + value = -1 } case HatRight: { event = absHat0X - value = MaximumAxisValue + value = 1 } default: { @@ -302,6 +302,27 @@ func createVGamepadDevice(path string, name []byte, vendor uint16, product uint1 absHat0Y, } + //tell uinput what the minimum/maximum abs value is + var absMin [absSize]int32 + absMin[absX] = -MaximumAxisValue + absMin[absY] = -MaximumAxisValue + absMin[absZ] = -MaximumAxisValue + absMin[absRX] = -MaximumAxisValue + absMin[absRY] = -MaximumAxisValue + absMin[absRZ] = -MaximumAxisValue + absMin[absHat0X] = -1 + absMin[absHat0Y] = -1 + + var absMax [absSize]int32 + absMax[absX] = MaximumAxisValue + absMax[absY] = MaximumAxisValue + absMax[absZ] = MaximumAxisValue + absMax[absRX] = MaximumAxisValue + absMax[absRY] = MaximumAxisValue + absMax[absRZ] = MaximumAxisValue + absMax[absHat0X] = 1 + absMax[absHat0Y] = 1 + deviceFile, err := createDeviceFile(path) if err != nil { return nil, fmt.Errorf("failed to create virtual gamepad device: %v", err) @@ -344,7 +365,11 @@ func createVGamepadDevice(path string, name []byte, vendor uint16, product uint1 Bustype: busUsb, Vendor: vendor, Product: product, - Version: 1}}) + Version: 1, + }, + Absmin: absMin, + Absmax: absMax, + }) } // Takes in a normalized value (-1.0:1.0) and return an event value From 589707f7462d06f47b7482fe7545ff387ee5997d Mon Sep 17 00:00:00 2001 From: thomast75 <62158572+ThomasT75@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:43:01 -0300 Subject: [PATCH 4/4] Add TestTriggerAxis to gamepad_test.go --- gamepad_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gamepad_test.go b/gamepad_test.go index 2b59d7b..6fb658c 100644 --- a/gamepad_test.go +++ b/gamepad_test.go @@ -96,6 +96,34 @@ func TestAxisMovement(t *testing.T) { } } +//This test press the triggers with some amount of force +func TestTriggerAxis(t *testing.T) { + vg, err := CreateGamepad("/dev/uinput", []byte("Hot gophers in your area"), 0xDEAD, 0xBEEF) + if err != nil { + t.Fatalf("Failed to create the virtual gamepad. Last error was: %s\n", err) + } + + err = vg.LeftTriggerForce(1.0) + if err != nil { + t.Fatalf("Failed to send trigger axis event. Last error was: %s\n", err) + } + + err = vg.RightTriggerForce(-1.0) + if err != nil { + t.Fatalf("Failed to send trigger axis event. Last error was: %s\n", err) + } + + err = vg.LeftTriggerForce(-0.2) + if err != nil { + t.Fatalf("Failed to send trigger axis event. Last error was: %s\n", err) + } + + err = vg.RightTriggerForce(0.2) + if err != nil { + t.Fatalf("Failed to send trigger axis event. Last error was: %s\n", err) + } +} + func TestHatMovement(t *testing.T) { vg, err := CreateGamepad("/dev/uinput", []byte("Hot gophers in your area"), 0xDEAD, 0xBEEF) if err != nil {