using HidLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoraV2Tools { internal class SoraV2Interface { private const ushort VID = 0x1915; private const ushort PID_WIRELESS = 0xAE1C; private const ushort PID_WIRED = 0xAE11; public static List GetDevice() { var devices = HidDevices.Enumerate(VID, PID_WIRELESS).ToList(); return devices; } public static DeviceStatus GetDeviceStatus() { try { foreach (var device in GetDevice()) { // Get the HID device if (device == null) { Console.WriteLine("Device not found."); continue; } // Open the device for communication device.OpenDevice(); if (!device.IsOpen || !device.IsConnected) { continue; } // Prepare the report to send to the device byte[] report = new byte[32]; report[0] = 5; // Report ID report[1] = 21; // Command or action type report[4] = 1; // Action flag // Send the feature report to request battery info var success = device.WriteFeatureData(report); if (!success) { Console.WriteLine("Failed to send feature report."); continue; } // Wait a bit for the device to respond System.Threading.Thread.Sleep(90); // Get the response feature report device.ReadFeatureData(out byte[] responseData, reportId: 5); if (responseData == null || responseData.Length < 13) { Console.WriteLine("Failed to read feature report."); continue; } // Extract battery information from the response byte battery = responseData[9]; byte charging = responseData[10]; byte fullCharge = responseData[11]; byte online = responseData[12]; return new DeviceStatus(battery, charging, fullCharge, online); } return new DeviceStatus(); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); return new DeviceStatus(); } } } public struct DeviceStatus { public byte Battery; public byte Charging; public byte FullCharge; public byte Online; public DeviceStatus(byte battery, byte charging, byte fullCharge, byte online) { Battery = battery; Charging = charging; FullCharge = fullCharge; Online = online; } } }