*EDIT:
I have managed to get the float value of the brake (I renamed it into Load Cell Kit) function. I tried to change the other two into similar code but can only manage to change from 1 to 0.9, but it definitely removes the loop.
So basically, I need to change the input control on all of them into Stick value, and I also need to give them a full input of the Stick (x, y, up, down, right, left) or else the value won’t go through. After that you have to assign the value in the Input Action Asset into Value Axis and only get the Y value input. For the clutch and throttle, I need to assign the parameter into normalize or else the value won’t be recognized.
Here’s the Screenshot of the Input Action Map:
Hi, I created a Custom HID Input for my FANATEC CSL Pedal because it is listed as unsupported and noticed an annoying bug. The value of all of the CSL Pedal Input keeps on repeating by themself, it will go from 0 to -1 on and on, as you can see here:
https://www.awesomescreenshot.com/video/18995698?key=be25a10b9fe639422331a48723d79635
The Clutch value also got called when the Brake is going down or up, even though on the Input Action Map, the binding only recognizes one of them.
Here’s my code:
public class JoystickTesting : MonoBehaviour
{
[Header("Input Action Asset")]
[SerializeField] private InputActionAsset inputActionAsset;
private InputActionMap t16000M;
private InputAction leftXStick;
private InputAction leftYStick;
private InputAction rightXStick;
private InputAction rightYStick;
private InputActionMap fanatecCSLPedalKit;
private InputAction cslThrottle;
private InputAction cslBrake;
private InputAction cslClutch;
[Header("T.16000M")]
[SerializeField] private float leftX;
[SerializeField] private float leftY;
[SerializeField] private float rightX;
[SerializeField] private float rightY;
[Header("FANATEC CSL Pedal Kit")]
[SerializeField] private float throttle;
[SerializeField] private float brake;
[SerializeField] private float clutch;
// Start is called before the first frame update
void Start()
{
var joysticks = new List<InputDevice>();
foreach (var device in InputSystem.devices)
{
Debug.Log(device.description.product);
if (device.description.product == "T.16000M")
joysticks.Add(device);
}
if (joysticks.Count > 0)
{
InputSystem.SetDeviceUsage(joysticks[0], CommonUsages.LeftHand);
if (joysticks.Count > 1)
InputSystem.SetDeviceUsage(joysticks[1], CommonUsages.RightHand);
}
t16000M = inputActionAsset.FindActionMap("T.16000M");
leftXStick = t16000M.FindAction("leftHandStickX");
leftYStick = t16000M.FindAction("leftHandStickY");
rightXStick = t16000M.FindAction("rightHandStickX");
rightYStick = t16000M.FindAction("rightHandStickY");
leftXStick.Enable();
leftYStick.Enable();
rightXStick.Enable();
rightYStick.Enable();
t16000M = inputActionAsset.FindActionMap("Fanatec CSL Pedal Kit");
cslThrottle = t16000M.FindAction("throttle");
cslBrake = t16000M.FindAction("brake");
cslClutch = t16000M.FindAction("clutch");
cslThrottle.Enable();
cslBrake.Enable();
cslClutch.Enable();
}
// Update is called once per frame
void Update()
{
leftX = leftXStick.ReadValue<float>();
leftY = leftYStick.ReadValue<float>();
rightX = rightXStick.ReadValue<float>();
rightY = rightYStick.ReadValue<float>();
throttle = cslThrottle.ReadValue<float>();
brake = cslBrake.ReadValue<float>();
clutch = cslClutch.ReadValue<float>();
}
}
*Here’s my HIDInputReport (EDITED):
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
[StructLayout(LayoutKind.Explicit, Size = 32)]
struct FanatecCSLHIDInputReport : IInputStateTypeInfo
{
// Because all HID input reports are tagged with the 'HID ' FourCC,
// this is the format we need to use for this state struct.
public FourCC format => new FourCC('H', 'I', 'D');
// HID input reports can start with an 8-bit report ID. It depends on the device
// whether this is present or not. On the PS4 DualShock controller, it is
// present. We don't really need to add the field, but let's do so for the sake of
// completeness. This can also help with debugging.
[FieldOffset(0)] public byte reportId;
// The InputControl annotations here probably look a little scary, but what we do
// here is relatively straightforward. The fields we add we annotate with
// [FieldOffset] to force them to the right location, and then we add InputControl
// to attach controls to the fields. Each InputControl attribute can only do one of
// two things: either it adds a new control or it modifies an existing control.
// Given that our layout is based on Gamepad, almost all the controls here are
// inherited from Gamepad, and we just modify settings on them.
// [InputControl(name = "Throttle", layout = "Axis")]
[InputControl(name = "Throttle", layout = "Stick")]
[InputControl(name = "Throttle/x", offset = 0, format = "BYTE",
parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "Throttle/y", offset = 1, format = "BYTE",
parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[FieldOffset(1)] public byte throttleX;
[FieldOffset(2)] public byte throttleY;
// [InputControl(name = "Brake", layout = "Axis")]
[InputControl(name = "Load Cell Kit", layout = "Stick")]
[InputControl(name = "Load Cell Kit/x", offset = 0, format = "BYTE")]
[InputControl(name = "Load Cell Kit/left", offset = 0, format = "BYTE")]
[InputControl(name = "Load Cell Kit/right", offset = 0, format = "BYTE")]
[InputControl(name = "Load Cell Kit/y", offset = 1, format = "BYTE")]
[InputControl(name = "Load Cell Kit/up", offset = 1, format = "BYTE")]
[InputControl(name = "Load Cell Kit/down", offset = 1, format = "BYTE")]
[FieldOffset(3)] public byte loadCellKitX;
[FieldOffset(4)] public byte loadCellKitY;
// [InputControl(name = "Clutch", layout = "Axis")]
[InputControl(name = "Clutch", layout = "Stick")]
[InputControl(name = "Clutch/x", offset = 0, format = "BYTE",
parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "Clutch/y", offset = 1, format = "BYTE",
parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[FieldOffset(5)] public byte clutchX;
[FieldOffset(6)] public byte clutchY;
}