static void Main(string[] args) { if (args.Length < 1) { WriteErrorToConsoleAndExit("Please specify a config file"); } BongoConfig config = null; try { String json = ""; using (StreamReader sr = new StreamReader(args[0])) { json += sr.ReadToEnd(); } config = JsonConvert.DeserializeObject <BongoConfig>(json); } catch (IOException) { WriteErrorToConsoleAndExit("File not found"); } if (config == null) { WriteErrorToConsoleAndExit("Failed to read config file"); } manager = new BongoManager(config.micThreshold); switch (config.output.ToLower().Trim()) { case ("keyboard"): handler = new KeyboardHandler(manager, config.keyboardMapping); break; case ("vjoy"): handler = new VJoyHandler(manager, config.vJoyMapping, config.vJoyId, config.micSensitivity); break; default: WriteErrorToConsoleAndExit("Unsupported output method"); break; } bongos = HidDevices.Enumerate(config.vendorID, config.productID).FirstOrDefault(); if (bongos == null) { WriteErrorToConsoleAndExit("No device found"); } bongos.OpenDevice(); bongos.Removed += () => WriteErrorToConsoleAndExit("Device disconnected"); pollRate = config.pollRate; polling = new Thread(PollDevice); polling.Start(); Console.WriteLine($"Beginning bongo translation with method '{config.output}'"); while (polling.IsAlive) { Console.ReadKey(); } }
public static IEnumerable <SDP_Handler> Enumerate(int Vid, int[] productIds) { return(HidDevices.Enumerate(Vid, productIds).Select(x => new SDP_Handler(x))); }
private bool PopulateDeviceInfo() { if (deviceMode == IDTECH_DEVICE_PID.VP3000_HID) { string serialNumber = ""; RETURN_CODE rt = IDT_VP3300.SharedController.config_getSerialNumber(ref serialNumber); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { deviceInfo.SerialNumber = serialNumber.Trim('\0'); Debug.WriteLine("device INFO[Serial Number] : {0}", (object)deviceInfo.SerialNumber); } else { Debug.WriteLine("DeviceCfg::PopulateDeviceInfo(): failed to get serialNumber reason={0}", rt); } string firmwareVersion = ""; rt = IDT_VP3300.SharedController.device_getFirmwareVersion(ref firmwareVersion); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { deviceInfo.FirmwareVersion = ParseFirmwareVersion(firmwareVersion); Debug.WriteLine("device INFO[Firmware Version] : {0}", (object)deviceInfo.FirmwareVersion); deviceInfo.Port = firmwareVersion.Substring(firmwareVersion.IndexOf("USB", StringComparison.Ordinal), 7); Debug.WriteLine("device INFO[Port] : {0}", (object)deviceInfo.Port); } else { Debug.WriteLine("DeviceCfg::PopulateDeviceInfo(): failed to get Firmware version reason={0}", rt); } deviceInfo.ModelName = IDTechSDK.Profile.IDT_DEVICE_String(deviceType, deviceConnect); Debug.WriteLine("device INFO[Model Name] : {0}", (object)deviceInfo.ModelName); deviceInfo.ModelNumber = "UNKNOWN"; /*rt = IDT_VP3300.SharedController.config_getModelNumber(ref deviceInfo.ModelNumber); * * if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) * { * Debug.WriteLine("device INFO[Model Number] : {0}", (object) deviceInfo.ModelNumber); * } * else * { * Debug.WriteLine("DeviceCfg::PopulateDeviceInfo(): failed to get Model number reason={0}", rt); * }*/ } else { // Initialize Device HidDevice device = HidDevices.Enumerate(Device_IDTech.IDTechVendorID).FirstOrDefault(); if (device != null) { byte[] data; if (device.ReadSerialNumber(out data)) { deviceInfo.SerialNumber = GetKeyboardModeSerialNumber(); // VP3300 USB NEO v1.01.107 string [] payload = GetKeyboardModeFirmwareVersion(); if (payload?.Length == 4) { deviceInfo.FirmwareVersion = payload[3].Substring(1, payload[3].Length - 1); deviceInfo.ModelName = payload[0] + " (" + payload[1] + ")"; deviceInfo.ModelNumber = "UNKNOWN"; deviceInfo.Port = payload[1] + "-KB"; } } } } return(true); }
private static HidDevice[] ListBlink1Devices() { var devices = HidDevices.Enumerate(VendorId, ProductId); return(devices as HidDevice[] ?? devices.ToArray()); }
private static IEnumerable <HidDevice> GetListableDevices() => HidDevices.Enumerate() .Where(d => d.IsConnected) .Where(device => device.Capabilities.InputReportByteLength > 0) .Where(device => (ushort)device.Capabilities.UsagePage == Flashing.ConsoleUsagePage) .Where(device => (ushort)device.Capabilities.Usage == Flashing.ConsoleUsage);
private static IEnumerable <HidDevice> GetListableDevices() => HidDevices.Enumerate() .Where(d => d.IsConnected) .Where(device => (ushort)device.Capabilities.UsagePage == Flashing.UsagePage);
protected virtual HidDevice SelectDevice() { return(HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault()); }
static public ObservableCollection <HidDevice> GetDevices(int vid) { ObservableCollection <HidDevice> devices = new ObservableCollection <HidDevice>(HidDevices.Enumerate(vid)); return(devices); }
public void Init() { device = HidDevices.Enumerate(4152, 5648).FirstOrDefault(); device.OpenDevice(); }
private bool Initialise() { bool result = false; var devices = HidDevices.Enumerate(vid, pid); if (devices.Count() == 0) { configurationDevice = null; inputDevice = null; result = false; isDetected = false; } else { isDetected = true; configurationDevice = devices.FirstOrDefault(x => x.DevicePath.Contains("&col01")); inputDevice = devices.FirstOrDefault(x => x.DevicePath.Contains("&col02")); if (configurationDevice != null && inputDevice != null) { var attached = Observable.FromEvent <InsertedEventHandler, Unit>(h => () => h(Unit.Default), h => configurationDevice.Inserted += h, h => configurationDevice.Inserted -= h); var detached = Observable.FromEvent <RemovedEventHandler, Unit>(h => () => h(Unit.Default), h => configurationDevice.Removed += h, h => configurationDevice.Removed -= h); CableAttached = attached.Select(s => true).Merge(detached.Select(s => false)); CableAttached.Subscribe(async connected => { if (connected) { await Connect(); } else { cancellationSource.Cancel(); inputDevice.CloseDevice(); configurationDevice.CloseDevice(); isConnected.OnNext(false); } }); configurationIdpInterface = new IdpInterface(); inputIdpInterface = new IdpInterface(); commandManager = new CommandManager(); commandManager.RegisterInterface(configurationIdpInterface); commandManager.RegisterInterface(inputIdpInterface); InitialiseCommands(); packetStream = inputIdpInterface.PacketParsed.Merge(configurationIdpInterface.PacketParsed); Task.Run(() => Connect()).Wait(); result = true; } } return(result); }
public static IEnumerable <Scanner> Enumerate(int[] productIds) { return(HidDevices.Enumerate(HoneywellVendorId, productIds).Select(x => new Scanner(x))); }
private static int SearchDevice() { var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList(); var scpBus = GlobalScpBus; var alreadyMapped = MappedDevices; foreach (var deviceInstance in compatibleDevices) { var device = deviceInstance; if (alreadyMapped.ContainsKey(device.DevicePath)) { continue; } try { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); } catch { var instanceId = DevicePathToInstanceId(deviceInstance.DevicePath); if (TryReEnableDevice(instanceId)) { try { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); } catch { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); } } else { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); } } byte[] vibration = { 0x20, 0x00, 0x00 }; if (device.WriteFeatureData(vibration) == false) { device.CloseDevice(); continue; } byte[] serialNumber; byte[] product; device.ReadSerialNumber(out serialNumber); device.ReadProduct(out product); var index = MappedDevices.Count + 1; var gamepad = new XiaomiGamepad(device, scpBus, index); MappedDevices.Add(device.DevicePath, gamepad); } return(MappedDevices.Count); }
public IEnumerable <string> ListAvailableDevices() { return(HidDevices.Enumerate().Select(GetFriendlyName)); }
public bool Apply(int steerLock, bool isReset, out int appliedValue) { appliedValue = Math.Min(Math.Max(steerLock, MinimumSteerLock), MaximumSteerLock); var cmd0 = new byte[] { 0x1, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; var cmd1 = new byte[] { 0x1, 0xf8, 0x09, 0x01, 0x06, 0x01, 0x0, 0x0 }; var cmd2 = new byte[] { 0x1, 0xf8, 0x81 } .Concat(BitConverter.GetBytes((ushort)appliedValue)) .Concat(new byte[] { 0x0, 0x0, 0x0 }).ToArray(); var cmdE = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; return(HidDevices.Enumerate(0xEB7, 0x7).Aggregate(false, (a, b) => { using (b) { try { AcToolsLogging.Write($"Set to {steerLock}: " + b.DevicePath); AcToolsLogging.Write($"Device state: connected={b.IsConnected}, description={b.Description}"); AcToolsLogging.Write( $"Device caps: Usage={b.Capabilities.Usage}, UsagePage={b.Capabilities.UsagePage}, FeatureReportByteLength={b.Capabilities.FeatureReportByteLength}"); AcToolsLogging.Write( $"Device caps: OutputReportByteLength={b.Capabilities.OutputReportByteLength}, InputReportByteLength={b.Capabilities.InputReportByteLength}"); AcToolsLogging.Write( $"Device caps: NumberLinkCollectionNodes={b.Capabilities.NumberLinkCollectionNodes}, NumberInputButtonCaps={b.Capabilities.NumberInputButtonCaps}"); AcToolsLogging.Write( $"Device caps: NumberInputValueCaps={b.Capabilities.NumberInputValueCaps}, NumberInputDataIndices={b.Capabilities.NumberInputDataIndices}"); AcToolsLogging.Write( $"Device caps: NumberOutputButtonCaps={b.Capabilities.NumberOutputButtonCaps}, NumberOutputValueCaps={b.Capabilities.NumberOutputValueCaps}"); AcToolsLogging.Write( $"Device caps: NumberOutputDataIndices={b.Capabilities.NumberOutputDataIndices}, NumberFeatureButtonCaps={b.Capabilities.NumberFeatureButtonCaps}"); AcToolsLogging.Write( $"Device caps: NumberFeatureValueCaps={b.Capabilities.NumberFeatureValueCaps}, NumberFeatureDataIndices={b.Capabilities.NumberFeatureDataIndices}"); if (b.Capabilities.Usage != 4) { AcToolsLogging.Write("Unknown usage for setting a lock"); // return a; } b.OpenDevice(); AcToolsLogging.Write($"Device state: opened={b.IsOpen}, handle={b.WriteHandle}, read={b.ReadHandle}"); if (b.WriteDataThrowy(cmd0, 0)) { AcToolsLogging.Write($"First command sent: {cmd0.Select(x => x.ToString("X2")).JoinToString(" ")}"); AcToolsLogging.Write($"Device state post-writing first command: opened={b.IsOpen}, handle={b.WriteHandle}"); if (b.WriteDataThrowy(cmd1, 0)) { AcToolsLogging.Write($"Second command sent: {cmd1.Select(x => x.ToString("X2")).JoinToString(" ")}"); if (b.WriteDataThrowy(cmd2, 0)) { AcToolsLogging.Write($"Third command sent: {cmd2.Select(x => x.ToString("X2")).JoinToString(" ")}"); if (b.Write(cmd2)) { AcToolsLogging.Write($"Empty command sent: {cmdE.Select(x => x.ToString("X2")).JoinToString(" ")}"); AcToolsLogging.Write($"Device state post-writing: opened={b.IsOpen}, handle={b.WriteHandle}"); b.CloseDevice(); return true; } } } } else { AcToolsLogging.Write($"Failed to sent even the first command: {Marshal.GetLastWin32Error()}"); } AcToolsLogging.Write($"Device state post-writing: opened={b.IsOpen}, handle={b.WriteHandle}"); } catch (Exception e) { AcToolsLogging.Write($"Error: {e}"); } } return a; })); }
/// <summary> /// Enumerates all HID devices connected to the system. /// </summary> /// <returns>An <see cref="IEnumerable{T}"/> containing all found <see cref="HidDevice"/>s.</returns> public static IEnumerable <HidDevice> EnumAllDevices() { return(HidDevices.Enumerate()); }
public Task Initialize(Progress <MonitorMessage> progress, CancellationToken cancellationToken) { _progress = progress; if (String.IsNullOrEmpty(Properties.Settings.Default.ScaleID)) { _progress.Report(new MonitorMessage(Strings.ScaleConfigurationMissingWarning)); return(null); } return(Task.Run(() => { while (true) { try { if (cancellationToken.IsCancellationRequested) { LogoutFromAcumatica(); break; } decimal readWeight = 0m; WeightUnits weightUnit = WeightUnits.None; HidDevice hidDevice = HidDevices.Enumerate(Properties.Settings.Default.ScaleDeviceVendorId, Properties.Settings.Default.ScaleDeviceProductId).FirstOrDefault(); if (hidDevice != null) { using (hidDevice) { hidDevice.OpenDevice(); WaitForConnection(hidDevice); readWeight = ReadWeight(hidDevice, out weightUnit); hidDevice.CloseDevice(); } if (!weightUnit.Equals(WeightUnits.None)) { _progress.Report(new MonitorMessage(String.Format(Strings.ScaleWeightNotify, readWeight, WeightUnitToStringAbbreviation[weightUnit]))); if (_lastWeightSentToAcumatica != readWeight) { if (_screen != null || LoginToAcumatica()) { UpdateWeight(Properties.Settings.Default.ScaleID, ConvertWeightToKilogram(readWeight, weightUnit)); _lastWeightSentToAcumatica = readWeight; } } } } System.Threading.Thread.Sleep(Properties.Settings.Default.ScaleReadInterval); } catch (Exception ex) { // Assume the server went offline or our session got lost - new login will be attempted in next iteration _progress.Report(new MonitorMessage(String.Format(Strings.ScaleWeightError, ex.Message), MonitorMessage.MonitorStates.Error)); _screen = null; System.Threading.Thread.Sleep(Properties.Settings.Default.ErrorWaitInterval); } } })); }
/// <summary> /// Enumerates all NZXT devices connected to the system. /// </summary> /// <returns>An <see cref="IEnumerable{T}"/> containing all found NZXT <see cref="HidDevice"/>s.</returns> public static IEnumerable <HidDevice> EnumNZXTDevices() { return(HidDevices.Enumerate(0x1E71)); }
internal static HidDevice[] getHidDevicesConnected() { HidDevice[] deviceList = HidDevices.Enumerate().ToArray(); return(deviceList); }
public static bool HasDriver() { IEnumerable <HidDevice> devices = HidDevices.Enumerate(0xdddd, 0x0001); return(devices.FirstOrDefault() != null); }
private static void ManageControllers(ScpBus scpBus) { var nrConnected = 0; while (true) { var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList(); var existingDevices = Gamepads.Select(g => g.Device).ToList(); var newDevices = compatibleDevices.Where(d => !existingDevices.Select(e => e.DevicePath).Contains(d.DevicePath)); foreach (var gamepad in Gamepads.ToList()) { if (!gamepad.check_connected()) { gamepad.unplug(); Gamepads.Remove(gamepad); } } foreach (var deviceInstance in newDevices) { var device = deviceInstance; try { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); } catch { InformUser("Could not open gamepad in exclusive mode. Try reconnecting the device."); var instanceId = devicePathToInstanceId(deviceInstance.DevicePath); if (TryReEnableDevice(instanceId)) { try { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); //InformUser("Opened in exclusive mode."); } catch { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); //InformUser("Opened in shared mode."); } } else { device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); //InformUser("Opened in shared mode."); } } byte[] vibration = { 0x20, 0x00, 0x00 }; if (device.WriteFeatureData(vibration) == false) { InformUser("Could not write to gamepad (is it closed?), skipping"); device.CloseDevice(); continue; } byte[] serialNumber; byte[] product; device.ReadSerialNumber(out serialNumber); device.ReadProduct(out product); var usedIndexes = Gamepads.Select(g => g.Index); var index = 1; while (usedIndexes.Contains(index)) { index++; } Gamepads.Add(new Xiaomi_gamepad(device, scpBus, index)); } if (Gamepads.Count != nrConnected) { InformUser($"{Gamepads.Count} controllers connected"); } Thread.Sleep(1000); } }
private static void Init() { ScpBus scpBus = new ScpBus(); scpBus.UnplugAll(); global_scpBus = scpBus; handler = new ConsoleEventDelegate(ConsoleEventCallback); SetConsoleCtrlHandler(handler, true); var compatibleDevices = HidDevices.Enumerate(0x79, 0x181c).ToList(); Thread.Sleep(400); FuzeGamepad[] gamepads = new FuzeGamepad[4]; int index = 1; //compatibleDevices.RemoveRange(1, compatibleDevices.Count - 1); foreach (var deviceInstance in compatibleDevices) { //Console.WriteLine(deviceInstance); HidDevice Device = deviceInstance; try { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); } catch { Log.WriteLine("Could not open gamepad in exclusive mode. Try re-enable device.", Log.LogType.warning); var instanceId = devicePathToInstanceId(deviceInstance.DevicePath); if (TryReEnableDevice(instanceId)) { try { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); Log.WriteLine("Opened in exclusive mode."); } catch { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); Log.WriteLine("Opened in shared mode."); } } else { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); Log.WriteLine("Opened in shared mode."); } } //byte[] Vibration = { 0x20, 0x00, 0x00 }; //if (Device.WriteFeatureData(Vibration) == false) //{ // Console.WriteLine("Could not write to gamepad (is it closed?), skipping"); // Device.CloseDevice(); // continue; //} byte[] serialNumber; byte[] product; Device.ReadSerialNumber(out serialNumber); Device.ReadProduct(out product); gamepads[index - 1] = new FuzeGamepad(Device, scpBus, index); ++index; if (index >= 5) { break; } } Log.WriteLine(string.Format("{0} controllers connected", index - 1)); while (true) { Thread.Sleep(1000); } }
static void Main(string[] args) { ScpBus scpBus = new ScpBus(); scpBus.UnplugAll(); global_scpBus = scpBus; handler = new ConsoleEventDelegate(ConsoleEventCallback); SetConsoleCtrlHandler(handler, true); Thread.Sleep(400); Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4]; int index = 1; var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList(); foreach (var deviceInstance in compatibleDevices) { Console.WriteLine(deviceInstance); HidDevice Device = deviceInstance; try { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); } catch { Console.WriteLine("Could not open gamepad in exclusive mode. Try re-enable device."); var instanceId = devicePathToInstanceId(deviceInstance.DevicePath); if (TryReEnableDevice(instanceId)) { try { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive); Console.WriteLine("Opened in exclusive mode."); } catch { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); Console.WriteLine("Opened in shared mode."); } } else { Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite); Console.WriteLine("Opened in shared mode."); } } byte[] Vibration = { 0x20, 0x00, 0x00 }; if (Device.WriteFeatureData(Vibration) == false) { Console.WriteLine("Could not write to gamepad (is it closed?), skipping"); Device.CloseDevice(); continue; } byte[] serialNumber; byte[] product; Device.ReadSerialNumber(out serialNumber); Device.ReadProduct(out product); gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index); ++index; if (index >= 5) { break; } } Console.WriteLine("{0} controllers connected", index - 1); while (true) { Thread.Sleep(1000); } }
private EntryModeStatus SetupVivoCommand(byte[] command, out byte[] response) { var status = EntryModeStatus.Success; const int bufferLength = 1000; var deviceDataBuffer = new byte[bufferLength]; response = null; try { HidDevice device = HidDevices.Enumerate(Device_IDTech.IDTechVendorID).FirstOrDefault(); if (device != null) { // Initialize return data buffer for (int i = 0; i < bufferLength; i++) { deviceDataBuffer[i] = 0; } int featureReportLen = device.Capabilities.FeatureReportByteLength; bool result = false; // REPORT: SEND 9 BYTES AT A TIME, WITH THE FIRST BYTE BEING THE REPORT ID int OFFSET = 1; int pages = (command.Length - OFFSET) / 8; int rem = (command.Length - OFFSET) % 8; for (int i = 0; i <= pages; i++) { // WriteFeatureData works better if we send the entire feature length array, not just the length of command plus checksum var reportBuffer = new byte[featureReportLen]; reportBuffer[0] = command[0]; if (i < pages) { Array.Copy(command, (8 * i) + OFFSET, reportBuffer, 1, 8); } else { Array.Copy(command, (8 * i) + OFFSET, reportBuffer, 1, rem); } Debug.Write("CMD: [ "); for (int ix = 0; ix < reportBuffer.Length; ix++) { Debug.Write(string.Format("{0:X2} ", reportBuffer[ix])); } Debug.WriteLine(" ] - LEN: {0}", reportBuffer.Length); result = device.WriteFeatureData(reportBuffer); } if (result) { // Empirical data shows this is a good time to wait. Thread.Sleep(1200); result = ReadFeatureDataLong(out deviceDataBuffer); } //as long as we have data in result, we are ok with failed reading later. if (result || deviceDataBuffer.Length > 0) { int dataIndex = 0; for (dataIndex = bufferLength - 1; dataIndex > 1; dataIndex--) { if (deviceDataBuffer[dataIndex] != 0) { break; } } response = new byte[dataIndex + 1]; for (var ind = 0; ind <= dataIndex; ind++) { response[ind] += deviceDataBuffer[ind]; } status = EntryModeStatus.Success; } else { status = EntryModeStatus.CardNotRead; } } } catch (Exception ex) { Debug.WriteLine("DeviceCfg::SetupVivoCommand(): - exception={0}", (object)ex.Message); status = EntryModeStatus.Error; } return(status); }