Ejemplo n.º 1
0
        bool SearchDevices()
        {
            if (hidStream != null)
            {
                hidStream.Dispose();
                hidStream = null;
            }

            var list = DeviceList.Local;
            var dev  = list.GetHidDevices().FirstOrDefault(d => d.GetProductName().Contains("FrSky"));

            if (dev == null)
            {
                Console.WriteLine("No FrSky device found.");
                return(false);
            }
            if (dev.TryOpen(out hidStream))
            {
                hidStream.ReadTimeout = Timeout.Infinite;
                var inputReportBuffer   = new byte[dev.GetMaxInputReportLength()];
                var rawReportDescriptor = dev.GetRawReportDescriptor();
                var reportDescriptor    = dev.GetReportDescriptor();

                var inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver();
                foreach (var deviceItem in reportDescriptor.DeviceItems)
                {
                    var inputParser = deviceItem.CreateDeviceItemInputParser();
                    inputReceiver.Received += (sender, e) =>
                    {
                        Report report;

                        while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
                        {
                            if (inputParser.TryParseReport(inputReportBuffer, 0, report))
                            {
                                WriteDeviceItemInputParserResult(inputParser);
                            }
                        }
                        if (oldState == null || !controllerState.Equals(oldState))
                        {
                            Console.WriteLine(controllerState);
                            UpdateControlState();
                            oldState = controllerState.Clone();
                        }
                    };
                }
                inputReceiver.Start(hidStream);
                Console.WriteLine("FrSky device found and initialized.");
            }
            else
            {
                Console.WriteLine($"Can't open device {dev.GetFriendlyName()}. Check permissions for {dev.GetFileSystemName()}.");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
 public ControllerState getPreviousState()
 {
     return(pState.Clone());
 }
Ejemplo n.º 3
0
 public ControllerState getCurrentState()
 {
     return(cState.Clone());
 }