Exemple #1
0
        private bool SetupDevice(HidDevice device, out HidStream stream, out HidDeviceInputReceiver receiver)
        {
            stream   = null;
            receiver = null;
            if (device == null)
            {
                return(false);
            }

            try
            {
                if (!device.TryOpen(out stream))
                {
                    return(false);
                }

                var descriptor = device.GetReportDescriptor();
                receiver           = descriptor.CreateHidDeviceInputReceiver();
                receiver.Received += OnReceiverReceived;
                receiver.Start(stream);
            }
            catch (Exception e)
            {
                Log($"Exception while setting up device occured: {e}");
                return(false);
            }

            return(receiver.IsRunning);
        }
Exemple #2
0
        /// <summary>
        /// Begin communication with moRFeus
        /// </summary>
        private void ConfigDevice()
        {
            // Report stream opened
            if (moRFeusDevice.TryOpen(out moRFeusStream))
            {
                moRFeusStream.ReadTimeout = Timeout.Infinite;

                // HIDSharp setup
                reportBuffer = new byte[moRFeusDevice.GetMaxInputReportLength()];
                ReportDescriptor reportDescriptor = moRFeusDevice.GetReportDescriptor();
                reportReceiver = reportDescriptor.CreateHidDeviceInputReceiver();

                // Receive event handling
                //reportReceiver.Received += ReportReceived;
                reportReceiver.Start(moRFeusStream);

                // Disconnect event handling
                moRFeusStream.Closed += new EventHandler(Disconnected);

                // Indicate successful connection
                Tools.Debug("Connected to moRFeus");
                Program.MainClass.StatusMessage = "Connected to moRFeus";
                Program.MainClass.EnableUI();
                moRFeusOpen = true;

                // Initial polling of device values
                Task.Delay(10).ContinueWith(t => Program.MainClass.PollDevice());
            }
        }
Exemple #3
0
 public void Start()
 {
     if (_digitizer.TryOpen(out _hidStream))
     {
         _hidDeviceInputReceiver           = _reportDescr.CreateHidDeviceInputReceiver();
         _hiddeviceInputParser             = _reportDescr.DeviceItems[0].CreateDeviceItemInputParser();
         _hidDeviceInputReceiver.Received += OnDigitizerInputReceived;
         _hidDeviceInputReceiver.Start(_hidStream);
     }
     else
     {
         throw new Exception("Failed to open iBridge HID digitizer");
     }
 }
Exemple #4
0
            public override void CommOpen(Bsl430NetDevice device)
            {
                try
                {
                    Bsl430NetDevice _device = device;

                    if (device == null)
                    {
                        _device = DefaultDevice;
                    }

                    if (_device == null || _device.Name == "")
                    {
                        throw new Bsl430NetException(461);
                    }

                    if (!devices.ContainsKey(_device.Name.ToLower()))
                    {
                        Status stat = Scan <USB_HID_Device>(out _);
                        if (!stat.OK)
                        {
                            throw new Bsl430NetException(stat.Error);
                        }
                    }

                    if (!devices.TryGetValue(_device.Name.ToLower(), out USB_HID_Device dev))
                    {
                        throw new Bsl430NetException(462);
                    }

                    DeviceList.Local.GetHidDeviceOrNull(dev.Vid,
                                                        dev.Pid)?.TryOpen(out usb);

                    if (usb == null)
                    {
                        throw new Bsl430NetException(610);
                    }
                    else
                    {
                        max_output_len   = usb.Device.GetMaxOutputReportLength();
                        max_input_len    = usb.Device.GetMaxInputReportLength();
                        usb.ReadTimeout  = Timeout.Infinite;
                        reportDescriptor = usb.Device.GetReportDescriptor();
                        inputReceiver    = reportDescriptor.CreateHidDeviceInputReceiver();
                        inputReceiver.Start(usb);
                    }
                }
                catch (Exception ex) { throw new Bsl430NetException(611, ex); }
            }
Exemple #5
0
        static void InputReceiverM_Received(object sender, EventArgs e)
        {
            Report report;
            HidDeviceInputReceiver inputReceiver = sender as HidDeviceInputReceiver;

            byte[] inputReportBuffer = new byte[5];
            while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
            {
                if (inputReportBuffer[1] != 0)
                {
                    Console.WriteLine(inputReportBuffer[1]);
                    PageTable.CurrentPage.InputM(inputReportBuffer[1]);
                }
            }
        }
Exemple #6
0
 public RawInputDevice(HidDevice device, ReportDescriptor reportDescriptor, DeviceItem deviceItem, HidStream hidStream, string uniqueId)
 {
     this.device       = device;
     inputReportBuffer = new byte[device.GetMaxInputReportLength()];
     inputReceiver     = reportDescriptor.CreateHidDeviceInputReceiver();
     inputParser       = deviceItem.CreateDeviceItemInputParser();
     inputReceiver.Start(hidStream);
     DisplayName           = device.GetProductName();
     UniqueId              = uniqueId;
     InterfacePath         = device.DevicePath;
     HardwareID            = IdHelper.GetHardwareId(InterfacePath);
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     sources = reportDescriptor.InputReports.SelectMany(ir => ir.DataItems)
               .SelectMany(di => di.Usages.GetAllValues())
               .Select(u => (Usage)u)
               .SelectMany(u => RawInputSource.FromUsage(this, u))
               .ToArray();
     readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start();
 }
Exemple #7
0
        public void Reset()
        {
            _virtualStream?.Dispose();
            _physicalStream?.Dispose();

            if (_virtualReceiver != null)
            {
                _virtualReceiver.Received -= OnReceiverReceived;
            }

            if (_physicalReceiver != null)
            {
                _physicalReceiver.Received -= OnReceiverReceived;
            }

            _virtualDevice    = null;
            _virtualStream    = null;
            _virtualReceiver  = null;
            _physicalDevice   = null;
            _physicalStream   = null;
            _physicalReceiver = null;
        }