Exemple #1
0
        public U2FHidKey([NotNull] IHidDevice device, bool closeDeviceOnDispose)
        {
            if (device == null) throw new ArgumentNullException(nameof(device));

            this.device = device;
            this.closeDeviceOnDispose = closeDeviceOnDispose;
        }
Exemple #2
0
 public void CheckIn(ref IHidDevice HidDev)
 {
     ((HidDevice)HidDev).StopDeviceReadThread();
     ((HidDevice)HidDev).DisposePreparsedData();
     ((HidDevice)HidDev).CloseFileHandle();
     ((HidDevice)HidDev).IsCheckedOut = false;
 }
        internal G933(IHidDevice device)
            : base(device)
        {
            if(PId != Constants.LOGITECH_G933_PRODUCT_ID)
                throw new Exception("Invalid Device");

            if (VId != Constants.LOGITECH_VENDOR_ID)
                throw new Exception("Invalid Device");
        }
Exemple #4
0
 private static string GetManufacturerString(IHidDevice d)
 {
     if (d == null)
     {
         return("");
     }
     d.ReadManufacturer(out var bs);
     return(System.Text.Encoding.Default.GetString(bs.Where(b => b > 0).ToArray()));
 }
Exemple #5
0
        public U2FHidKey([NotNull] IHidDevice device, bool closeDeviceOnDispose)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            this.device = device;
            this.closeDeviceOnDispose = closeDeviceOnDispose;
        }
Exemple #6
0
        private static double GetTemperatureCelsius(IHidDevice bulk)
        {
            var report     = WriteAndReadReport(bulk, 0x00, temperatureHumidityRaw);
            var rawReading = (report.Data[3] & 0xFF) + (report.Data[2] << 8);

            const double calibrationOffset  = -1.70;
            const double calibrationScale   = 2.74301;
            var          temperatureCelsius = (calibrationScale * (rawReading * (125.0 / 32000.0))) + calibrationOffset;

            return(temperatureCelsius);
        }
 public CycloneX10(IButtplugLogManager aLogManager, IHidDevice aHid, CycloneX10HidDeviceInfo aDeviceInfo)
     : base(aLogManager, aHid, aDeviceInfo)
 {
     MsgFuncs.Add(typeof(VorzeA10CycloneCmd), new ButtplugDeviceWrapper(HandleVorzeA10CycloneCmd));
     MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
     aHid.OpenDevice();
 }
        protected HidButtplugDevice(IButtplugLogManager aLogManager, IHidDevice aHid, IHidDeviceInfo aDeviceInfo)
            : base(aLogManager, aDeviceInfo.Name, aHid.DevicePath)
        {
            LogManager = aLogManager;
            _hid       = aHid;
            DeviceInfo = aDeviceInfo;

            _tokenSource   = new CancellationTokenSource();
            _hid.Inserted += DeviceAttachedHandler;
            _hid.Removed  += DeviceRemovedHandler;
        }
Exemple #9
0
 public CycloneX10(IButtplugLogManager aLogManager, IHidDevice aHid, CycloneX10HidDeviceInfo aDeviceInfo)
     : base(aLogManager, aHid, aDeviceInfo)
 {
     AddMessageHandler <VorzeA10CycloneCmd>(HandleVorzeA10CycloneCmd);
     AddMessageHandler <RotateCmd>(HandleRotateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     });
     AddMessageHandler <StopDeviceCmd>(HandleStopDeviceCmd);
     aHid.OpenDevice();
 }
        public Gamepad()
        {
            device = new HidEnumerator().Enumerate(VendorId, ProductId).First();

            eventStream = Observable.Interval(TimeSpan.FromMilliseconds(100))
                          .Select(_ => ReadReport())
                          .DistinctUntilChanged(new HidReportComparer())
                          .Select(MapReport)
                          .Publish()
                          .RefCount();
        }
Exemple #11
0
        public LedgerManager(IHidDevice ledgerHidDevice, ICoinUtility coinUtility)
        {
            LedgerHidDevice = ledgerHidDevice;
            CoinUtility     = coinUtility;

            if (CoinUtility == null)
            {
                CoinUtility = new DefaultCoinUtility();
            }

            SetCoinNumber(0);
        }
 public static Task WriteReportAsync(this IHidDevice device, IHidReport report, CancellationToken token)
 {
     if (device == null)
     {
         throw new ArgumentNullException($"{nameof(device)} is null");
     }
     if (report == null)
     {
         throw new ArgumentNullException($"{nameof(report)} is null");
     }
     return(device.WriteRawDataAsync(report.GetWholeData(), token));
 }
        public static async IAsyncEnumerable <IHidReport> GetReadReportStreamAsync(this IHidDevice device, [EnumeratorCancellation] CancellationToken token = default)
        {
            if (device == null)
            {
                throw new ArgumentNullException($"{nameof(device)} is null");
            }

            while (!token.IsCancellationRequested)
            {
                yield return(await device.ReadReportAsync(token).ConfigureAwait(false));
            }
        }
        private static Tuple <string, DeviceType> IdentityDevice(IHidDevice device)
        {
            device.ReadSerialNumber(out var output);

            var chars = (from o in output where o != 0 select(char) o).ToArray();

            var deviceType = DetermineDeviceType(output[0]);

            var serialNumber = $"0x{string.Join(string.Empty, chars)}";

            return(Tuple.Create(serialNumber, deviceType));
        }
Exemple #15
0
        protected TrezorManagerBase(EnterPinArgs enterPinCallback, IHidDevice hidDevice)
        {
            if (hidDevice == null)
            {
                throw new ArgumentNullException(nameof(hidDevice));
            }

            hidDevice.Connected += HidDevice_Connected;

            _EnterPinCallback = enterPinCallback;
            _HidDevice        = hidDevice;
        }
Exemple #16
0
        public void InitKeyboard(Device p_Device, IHidDevice p_IHidDevice)
        {
            m_Device = p_Device;
            m_HidDeviceEvents_HidDataReceivedEventHandler = new EventHandler <HidDataReceivedEventArgs>(HidDataReceived);
            m_IHidDevice = p_IHidDevice;
            m_IHidDevice.DataReceived += m_HidDeviceEvents_HidDataReceivedEventHandler;

            m_Keys             = 2;
            m_ProgrammableKeys = 0;

            #region Feature Report??
            //////////////////////////////////////////////
            // hier muss vom Aerion abgefragt werden, wieviele Tasten er hat
            // und der InitKeyboard entsprechend aufgerufen werden.
            // irgendwie so:
            // HidReport m_HIDFeatureReport = p_IHidDevice.ReadFeatureReport();

            /*
             * try
             * {
             *  byte[] buffer = {
             *          p_HidDataReceivedEventArgs[1],
             *          p_HidDataReceivedEventArgs[2],
             *          p_HidDataReceivedEventArgs[3],
             *          p_HidDataReceivedEventArgs[4],
             *          p_HidDataReceivedEventArgs[5],
             *          p_HidDataReceivedEventArgs[6],
             *      };
             *
             *  System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
             *  System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
             *
             *  m_keys = Convert.ToInt64(reader.ReadInt16());
             *  bool status = reader.ReadBoolean();
             *
             * }
             *
             * catch (Exception e)
             * {
             *  Console.Out.WriteLine("Exception: {0}", e.GetType());
             * }
             */
            #endregion

            m_KeyDownList  = new BitArray(8, false);
            m_KeyNameList  = new string[m_Keys];
            m_KeyLabelList = new string[m_Keys];

            m_KeyNameList[0]  = "L";
            m_KeyNameList[1]  = "R";
            m_KeyLabelList[0] = "L";
            m_KeyLabelList[1] = "R";
        }
        public UsbDevice(IHidDevice device)
        {
            _device                     = device;
            _device.Inserted           += DeviceInsert;
            _device.Removed            += DeviceRemove;
            _device.MonitorDeviceEvents = true;

            if (device.IsConnected)
            {
                DeviceInsert();
            }
        }
Exemple #18
0
        internal G933(IHidDevice device)
            : base(device)
        {
            if (PId != Constants.LOGITECH_G933_PRODUCT_ID)
            {
                throw new Exception("Invalid Device");
            }

            if (VId != Constants.LOGITECH_VENDOR_ID)
            {
                throw new Exception("Invalid Device");
            }
        }
Exemple #19
0
        public LedgerManager(IHidDevice ledgerHidDevice, ICoinUtility coinUtility, ErrorPromptDelegate errorPrompt)
        {
            ErrorPrompt = errorPrompt;

            LedgerHidDevice = ledgerHidDevice;
            CoinUtility     = coinUtility;

            if (CoinUtility == null)
            {
                CoinUtility = new DefaultCoinUtility();
            }

            SetCoinNumber(0);
        }
Exemple #20
0
 /// <summary>
 /// Connects the AerionInput main instance with a plugged NDOF-device by
 /// passing a predicate.
 /// Instructs m_IHidDevice to handle incoming data and sets the global Type of
 /// the device.
 /// </summary>
 /// <returns>true if device is connected</returns>
 private bool ConnectSpacePilot()
 {
     if ((m_IHidDevice = m_HidControl.GetDeviceByPredicate(new Predicate <IHidDeviceInfo>(IsSpacePilot))) != null)
     {
         Console.Out.WriteLine("SpacePilot connected");
         m_IHidDevice.StartInPipeThread();
         m_Type = c_SpacePilotDeviceType;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #21
0
        private static HidReport WriteAndReadReport(IHidDevice device, byte reportId, byte[] data)
        {
            var outData = device.CreateReport();

            outData.ReportId = reportId;
            outData.Data     = data;
            device.WriteReport(outData);
            while (outData.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                Thread.Sleep(1);
            }
            var report = device.ReadReport();

            return(report);
        }
 public static async Task WriteReportStreamAsync(this IHidDevice device, IAsyncEnumerable <IHidReport> stream, CancellationToken token = default)
 {
     if (device == null)
     {
         throw new ArgumentNullException($"{nameof(device)} is null");
     }
     if (stream == null)
     {
         throw new ArgumentNullException($"{nameof(stream)} is null");
     }
     await foreach (var item in stream.WithCancellation(token))
     {
         await device.WriteReportAsync(item, token).ConfigureAwait(false);
     }
 }
Exemple #23
0
        public void GiveBackDevice(IHidDevice HidDev)
        {
            if (HidDev != null)
            {
                try
                {
                    HidDev.StopInPipeThread();
                }
                finally
                {
                    HidDev = null;
                }

                EmitLogMessage(HidLogMessageType.Info, "Device checked in.");
            }
        }
        public HidConsoleDevice(IHidDevice device)
        {
            HidDevice = device;
            HidDevice.OpenDevice();

            ManufacturerString = GetManufacturerString(HidDevice);
            ProductString      = GetProductString(HidDevice);
            VendorId           = (ushort)HidDevice.Attributes.VendorId;
            ProductId          = (ushort)HidDevice.Attributes.ProductId;
            RevisionBcd        = (ushort)HidDevice.Attributes.Version;

            HidDevice.MonitorDeviceEvents = true;
            HidDevice.ReadReport(HidDeviceReportEvent);

            HidDevice.CloseDevice();
        }
Exemple #25
0
        private async void DevicePoller_DeviceInitialized(object sender, DeviceEventArgs e)
        {
            _rs28Device = (IHidDevice)e.Device;
            try
            {
                while (true)
                {
                    FootpedalStatus status = await ReadStatusAsync();

                    StatusChanged?.Invoke(this, new FootpedalEventArgs(status));
                }
            }
            catch (Exception)
            {
                /* Probably due to device being uplugged */
            }
        }
Exemple #26
0
        /// <summary>
        /// Clean up managed and unmanged ressources by hand.
        /// </summary>
        /// <param name="Disposing"></param>
        protected void Dispose(bool Disposing)
        {
            if (!IsDisposed)
            {
                if (Disposing)
                {
                    //Clean Up managed resources
                    m_IHidDevice = null;
                    m_Device     = null;

                    //Ensure we clean-up references to event
                    m_SensorInput = null;
                }
                //Clean up unmanaged resources
            }
            IsDisposed = true;
        }
        /// <summary>
        /// Initializes a new instance of the CommandCenter class using the specified missile launcher model and HID library implementation.
        /// </summary>
        /// <param name="launcher">missile launcher model you want to control</param>
        /// <param name="device">HID library that will be used</param>
        /// <remarks>This is only for testing - HidLibrary is the default library for production use</remarks>
        internal CommandCenter(ILauncherModel launcher, IHidDevice device)
        {
            if (launcher == null)
            {
                throw new ArgumentException(Resources.LauncherIsNull);
            }

            if (device == null)
            {
                throw new ArgumentException(Resources.DeviceIsNull);
            }

            this.launcher = launcher;
            this.device   = device;
            this.sets     = new CommandSetList();

            device.Initialize(launcher.VendorId, launcher.DeviceId);
        }
Exemple #28
0
        public static async Task AuthenticateAsync(IHidDevice hidDevice, DeviceRegistration deviceRegistration, string appId, string facet, bool checkOnly = false, CancellationToken?cancellationToken = null)
        {
            cancellationToken = cancellationToken ?? CancellationToken.None;

            if (hidDevice == null || !hidDevice.IsConnected)
            {
                throw new ArgumentException("Hid device not connected", nameof(hidDevice));
            }

            using (var u2fHidDevice = await U2FHidDevice.OpenAsync(hidDevice))
            {
                var startAuthentication = U2F.StartAuthentication(appId, deviceRegistration);

                Log.Debug("Touch token to authenticate");
                var authenticateResponse = await WaitForTokenInputAsync(() => U2Fv2.AuthenticateAsync(u2fHidDevice, startAuthentication, facet, checkOnly), cancellationToken.Value).ConfigureAwait(false);

                U2F.FinishAuthentication(startAuthentication, authenticateResponse, deviceRegistration);
                Log.Debug("Authenticated");
            }
        }
Exemple #29
0
        /// <summary>
        /// Clean up managed and unmanged ressources by hand.
        /// </summary>
        /// <param name="Disposing"></param>
        protected void Dispose(bool Disposing)
        {
            if (!IsDisposed)
            {
                if (Disposing)
                {
                    //Clean Up managed resources
                    Disconnect();
                    m_HidControl = null;
                    m_IHidDevice = null;
                    m_Sensor.Dispose();
                    m_Keyboard.Dispose();

                    //Ensure we clean-up references to event
                    m_DeviceChange = null;
                }
                //Clean up unmanaged resources
            }
            IsDisposed = true;
        }
Exemple #30
0
        public static async Task <U2FHidKey> OpenAsync([NotNull] IHidDevice device, bool closeDeviceOnDispose = true)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            var instance = new U2FHidKey(device, closeDeviceOnDispose);

            try
            {
                await instance.InitAsync();

                return(instance);
            }
            catch
            {
                instance.Dispose();
                throw;
            }
        }
Exemple #31
0
        public static async Task WriteFidoU2FHidMessageAsync([NotNull] this IHidDevice device,
                                                             FidoU2FHidMessage message, CancellationToken cancellationToken)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            log.Debug($"Sending U2FHid message {message.Command} on channel 0x{message.Channel:X8} with {message.Data.Count} bytes of data");

            var report  = device.CreateOutputReport();
            var packets = MakeOutputPackets(report.Data.Count, message);

            packets.Item1.WriteTo(report.Data);

            await device.SendOutputReportAsync(report, cancellationToken);

            foreach (var continuation in packets.Item2)
            {
                await device.SendOutputReportAsync(ToOutputReport(device, continuation), cancellationToken);
            }
        }
Exemple #32
0
        public static async Task <DeviceRegistration> RegisterAsync(IHidDevice hidDevice, string appId, string facet, CancellationToken?cancellationToken = null)
        {
            cancellationToken = cancellationToken ?? CancellationToken.None;

            if (hidDevice == null || !hidDevice.IsConnected)
            {
                throw new ArgumentException("Hid device not connected", nameof(hidDevice));
            }

            using (var u2fHidDevice = await U2FHidDevice.OpenAsync(hidDevice))
            {
                var startRegistration = U2F.StartRegistration(appId);

                Log.Debug("Touch token to register");
                var registerResponse = await WaitForTokenInputAsync(() => U2Fv2.RegisterAsync(u2fHidDevice, startRegistration, facet), cancellationToken.Value);

                var deviceRegistration = U2F.FinishRegistration(startRegistration, registerResponse);
                Log.Debug("Registered");

                return(deviceRegistration);
            }
        }
Exemple #33
0
 private static string GetParentIdPrefix(IHidDevice d) => Regex.Match(d.DevicePath, "#([&0-9a-fA-F]+)#").Groups[1].ToString();
Exemple #34
0
 public void InitSensor(Device p_Device, IHidDevice p_IHidDevice)
 {
     m_Device = p_Device;
     m_HidDeviceEvents_HidDataReceivedEventHandler = new EventHandler<HidDataReceivedEventArgs>(HidDataReceived);
     m_IHidDevice = p_IHidDevice;
     m_IHidDevice.DataReceived += m_HidDeviceEvents_HidDataReceivedEventHandler;
 }
 static IHidOutputReport ToOutputReport(IHidDevice device, ContinuationPacket continuation)
 {
     var report = device.CreateOutputReport();
     continuation.WriteTo(report.Data);
     return report;
 }
Exemple #36
0
        /// <summary>
        /// Clean up managed and unmanged ressources by hand.
        /// </summary>
        /// <param name="Disposing"></param>
        protected void Dispose(bool Disposing)
        {
            if (!IsDisposed)
            {
                if (Disposing)
                {
                    //Clean Up managed resources
                    Disconnect();
                    m_HidControl = null;
                    m_IHidDevice = null;
                    m_Sensor.Dispose();
                    m_Keyboard.Dispose();

                    //Ensure we clean-up references to event
                    m_DeviceChange = null;
                }
                //Clean up unmanaged resources

            }
            IsDisposed = true;
        }
Exemple #37
0
        public void GiveBackDevice(IHidDevice HidDev)
        {
            if (HidDev != null)
            {
                try
                {
                    HidDev.StopInPipeThread();
                }
                finally
                {
                    HidDev = null;
                }

                EmitLogMessage(HidLogMessageType.Info, "Device checked in.");
            }
        }
Exemple #38
0
 /// <summary>
 /// Connects the AerionInput main instance with a plugged NDOF-device by
 /// passing a predicate.
 /// Instructs m_IHidDevice to handle incoming data and sets the global Type of
 /// the device.
 /// </summary>
 /// <returns>true if device is connected</returns>
 private bool ConnectAerion()
 {
     if ((m_IHidDevice = m_HidControl.GetDeviceByPredicate(new Predicate<IHidDeviceInfo>(IsAerion))) != null)
     {
         Console.Out.WriteLine("Aerion connected");
         m_IHidDevice.StartInPipeThread();
         m_Type = c_AerionDeviceType;
         return true;
     }
     else return false;
 }
Exemple #39
0
 /// <summary>
 /// Connects the AerionInput main instance with a plugged NDOF-device by
 /// passing a predicate.
 /// Instructs m_IHidDevice to handle incoming data and sets the global Type of
 /// the device.
 /// </summary>
 /// <returns>true if device is connected</returns>
 private bool ConnectSpaceTraveler()
 {
     if ((m_IHidDevice = m_HidControl.GetDeviceByPredicate(new Predicate<IHidDeviceInfo>(IsSpaceTraveler))) != null)
     {
         Console.Out.WriteLine("SpaceTraveler connected");
         m_IHidDevice.StartInPipeThread();
         m_Type = c_SpaceTravelerDeviceType;
         return true;
     }
     else return false;
 }
Exemple #40
0
        /// <summary>
        /// Clean up managed and unmanged ressources by hand.
        /// </summary>
        /// <param name="Disposing"></param>
        protected void Dispose(bool Disposing)
        {
            if (!IsDisposed)
            {
                if (Disposing)
                {
                    //Clean Up managed resources
                    m_IHidDevice = null;
                    m_Device = null;

                    //Ensure we clean-up references to event
                    m_KeyUp = null;
                    m_KeyDown = null;
                }
                //Clean up unmanaged resources

            }
            IsDisposed = true;
        }
        public BigRedButton()
        {
            var hidEnumerator = new HidEnumerator();

            device = hidEnumerator.Enumerate(VendorId, ProductId).FirstOrDefault();
        }
Exemple #42
0
        public void InitKeyboard(Device p_Device, IHidDevice p_IHidDevice)
        {
            m_Device = p_Device;
            m_HidDeviceEvents_HidDataReceivedEventHandler = new EventHandler<HidDataReceivedEventArgs>(HidDataReceived);
            m_IHidDevice = p_IHidDevice;
            m_IHidDevice.DataReceived += m_HidDeviceEvents_HidDataReceivedEventHandler;

            m_Keys = 2;
            m_ProgrammableKeys = 0;

            #region Feature Report??
            //////////////////////////////////////////////
            // hier muss vom Aerion abgefragt werden, wieviele Tasten er hat
            // und der InitKeyboard entsprechend aufgerufen werden.
            // irgendwie so:
            // HidReport m_HIDFeatureReport = p_IHidDevice.ReadFeatureReport();
            /*
            try
            {
                byte[] buffer = {
                        p_HidDataReceivedEventArgs[1],
                        p_HidDataReceivedEventArgs[2],
                        p_HidDataReceivedEventArgs[3],
                        p_HidDataReceivedEventArgs[4],
                        p_HidDataReceivedEventArgs[5],
                        p_HidDataReceivedEventArgs[6],
                    };

                System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
                System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);

                m_keys = Convert.ToInt64(reader.ReadInt16());
                bool status = reader.ReadBoolean();

            }

            catch (Exception e)
            {
                Console.Out.WriteLine("Exception: {0}", e.GetType());
            }
            */
            #endregion

            m_KeyDownList = new BitArray(8, false);
            m_KeyNameList = new string[m_Keys];
            m_KeyLabelList = new string[m_Keys];
        }
	public ClearwareAmpel(IHidDevice device) : this(new [] { device}) { }