From 04ebe3f60632da0df5c8525700214220b13a7935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerard=20Gasc=C3=B3n?= <52170489+GerardGascon@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:31:23 +0200 Subject: [PATCH] feat: added back non-windows joycon detection support --- SlidePresenter/GamepadReader/JoyConRead.cs | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/SlidePresenter/GamepadReader/JoyConRead.cs b/SlidePresenter/GamepadReader/JoyConRead.cs index 6b7b199..f9b69fc 100644 --- a/SlidePresenter/GamepadReader/JoyConRead.cs +++ b/SlidePresenter/GamepadReader/JoyConRead.cs @@ -1,6 +1,7 @@ #if JoyCon using System.Text; using HidSharp; +using HidSharp.Reports; using wtf.cluster.JoyCon; using wtf.cluster.JoyCon.ExtraData; using wtf.cluster.JoyCon.InputData; @@ -63,10 +64,44 @@ public class JoyConRead : IGamepadReader { } private static HidDevice? GetHidDevice() { + return OperatingSystem.IsWindows() + ? GetWindowsHidDevice() + : GetNonWindowsHidDevice(); + } + + private static HidDevice? GetWindowsHidDevice() { DeviceList list = DeviceList.Local; IEnumerable? nintendos = list.GetHidDevices(0x057e); + HidDevice? device = nintendos.FirstOrDefault(); + return device; + } - return nintendos.FirstOrDefault(); + private static HidDevice? GetNonWindowsHidDevice() { + HidDevice? device = null; + DeviceList list = DeviceList.Local; + + IEnumerable? hidDevices = list.GetHidDevices(); + foreach (HidDevice d in hidDevices) + { + ReportDescriptor? rd = d.GetReportDescriptor(); + if (rd == null) continue; + if (rd.OutputReports.Count() != 4 + || rd.OutputReports.Count(r => r.ReportID == 0x01) != 1 + || rd.OutputReports.Count(r => r.ReportID == 0x10) != 1 + || rd.OutputReports.Count(r => r.ReportID == 0x11) != 1 + || rd.OutputReports.Count(r => r.ReportID == 0x12) != 1 + || rd.InputReports.Count() != 6 + || rd.InputReports.Count(r => r.ReportID == 0x21) != 1 + || rd.InputReports.Count(r => r.ReportID == 0x30) != 1 + || rd.InputReports.Count(r => r.ReportID == 0x31) != 1 + || rd.InputReports.Count(r => r.ReportID == 0x32) != 1 + || rd.InputReports.Count(r => r.ReportID == 0x33) != 1 + || rd.InputReports.Count(r => r.ReportID == 0x3F) != 1) continue; + + device = d; + break; + } + return device; } private Task OnJoyConOnReportReceived(JoyCon _, IJoyConReport input) {