JoyShockLibrary icon indicating copy to clipboard operation
JoyShockLibrary copied to clipboard

Store Hiddevice path inside JSL_SETTINGS

Open Valkirie opened this issue 1 year ago • 3 comments

C# implementation has to be:

[DllImport("JoyShockLibrary")]
public static extern JOY_SETTINGS JslGetControllerInfoAndSettings(int deviceId);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct JOY_SETTINGS
{
	public int gyroSpace;
	public int colour;
	public int playerNumber;
	public int controllerType;
	public int splitType;
	[MarshalAs(UnmanagedType.U1)]
	public bool isCalibrating;
	[MarshalAs(UnmanagedType.U1)]
	public bool autoCalibrationEnabled;
	[MarshalAs(UnmanagedType.U1)]
	public bool isConnected;
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
	public string path;
}

Valkirie avatar Aug 17 '23 13:08 Valkirie

Thanks for this!

Just because a long string adds a lot to the size of JOY_SETTINGS, I think it'd be better to have a dedicated function for getting the string. The caller would give it a char array and the length of the array, and the function would fill the array with the path up to the given length.

Would you be up for giving that a go?

JibbSmart avatar Aug 17 '23 13:08 JibbSmart

I could implement a dedicated function I guess. The only "issue" is that I'm not sure we can guess the hid path size in advance. Bluetooth devices have a longer path than wired devices. I'll investigate.

Valkirie avatar Aug 17 '23 14:08 Valkirie

It doesn't need to know the size in advance, just have an array that's big enough. Just like how you pre-allocated 256 in the JOY_SETTINGS version, the caller could say "it's probably not more than 256 bytes" and use an array that big.

I think this is a common pattern for strings in C. Commonly, something like this would also return an int that's the length of the actual string

JibbSmart avatar Aug 17 '23 15:08 JibbSmart