Exemplo n.º 1
0
        private void BtnEnumerate_Click(object sender, EventArgs e)
        {
            CboDevices.Items.Clear();
            cbotodevice = new int[128]; //128=max # of devices
            //enumerate and setupinterfaces for all devices
            devices = PIEDevice.EnumeratePIE();
            if (devices.Length == 0)
            {
                toolStripStatusLabel1.Text = "No Devices Found";
            }
            else
            {
                //System.Media.SystemSounds.Beep.Play();
                int cbocount = 0; //keeps track of how many valid devices were added to the CboDevice box
                for (int i = 0; i < devices.Length; i++)
                {
                    //information about device
                    //PID = devices[i].Pid);
                    //HID Usage = devices[i].HidUsage);
                    //HID Usage Page = devices[i].HidUsagePage);
                    //HID Version = devices[i].Version);
                    if (devices[i].HidUsagePage == 0xc)
                    {
                        switch (devices[i].Pid)
                        {
                        case 525:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        case 514:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        case 515:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        default:
                            CboDevices.Items.Add("Unknown Device (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;
                        }
                        devices[i].SetupInterface();
                    }
                }
            }
            if (CboDevices.Items.Count > 0)
            {
                CboDevices.SelectedIndex = 0;
                selecteddevice           = cbotodevice[CboDevices.SelectedIndex];
                wData = new byte[devices[selecteddevice].WriteLength];//go ahead and setup for write
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enumerates all Xkeys devices currently connected.
        /// </summary>
        /// <returns>Returns the number of devices found.</returns>
        public static int EnumerateDevices()
        {
            deviceIndices = new int[INT_MaxDevices];

            foundDevices = PIEDevice.EnumeratePIE();
            if (foundDevices.Length == 0)
            {
                return(0);
            }

            validDevicesFound = 0;
            for (int i = 0; i < foundDevices.Length; i++)
            {
                if (foundDevices[i].HidUsagePage == 0xc)
                {
                    switch (foundDevices[i].Pid)
                    {
                    case INT_XKeysProfessionalID:
                        deviceIndices[validDevicesFound] = i;
                        validDevicesFound++;
                        foundDevices[i].SetupInterface();
                        break;

                    default:
                        // Unknown Device...
                        break;
                    }
                }
            }

            return(validDevicesFound);
        }
Exemplo n.º 3
0
        private IEnumerable <PIEDevice> ScanForBackingDevices()
        {
            var result = PIEDevice.EnumeratePIE()
                         .Where(x => x.HidUsagePage == 0xc);

            return(result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Tries to find a RailDriver and initialize it
 /// </summary>
 /// <param name="basePath"></param>
 public UserInputRailDriver(string basePath)
 {
     try
     {
         PIEDevice[] devices = PIEDevice.EnumeratePIE();
         for (int i = 0; i < devices.Length; i++)
         {
             if (devices[i].HidUsagePage == 0xc && devices[i].Pid == 210)
             {
                 Device = devices[i];
                 Device.SetupInterface();
                 Device.SetErrorCallback(this);
                 Device.SetDataCallback(this);
                 WriteBuffer = new byte[Device.WriteLength];
                 State       = new RailDriverState();
                 SetLEDs(0x40, 0x40, 0x40);
                 ReadCalibrationData(basePath);
                 break;
             }
         }
     }
     catch (Exception error)
     {
         Device = null;
         Trace.WriteLine(error);
     }
 }
Exemplo n.º 5
0
 internal JoystickManager64()
 {
     if (Program.CurrentHost.Platform == HostPlatform.MicrosoftWindows)
     {
         devices = PIEDevice.EnumeratePIE();
     }
 }
Exemplo n.º 6
0
 internal JoystickManager()
 {
     if (!Program.CurrentlyRunningOnWindows)
     {
         return;
     }
     devices = PIEDevice.EnumeratePIE();
 }
Exemplo n.º 7
0
 private RailDriverDevice()
 {
     device = PIEDevice.EnumeratePIE().Where(dev => dev.HidUsagePage == 0xc && dev.Pid == 210).FirstOrDefault();
     if (null != device)
     {
         device.SetupInterface();
         device.SuppressDuplicateReports = true;
         writeBuffer = new byte[WriteBufferSize];
     }
 }
        /// <summary>
        /// Get Devices
        /// </summary>
        /// <returns>
        /// True, they are exist
        /// </returns>
        public bool GetDevices()
        {
            _cboDevices.Items.Clear();
            cbotodevice = new int[128]; //128=max # of devices
            //enumerate and setupinterfaces for all devices
            devices = PIEDevice.EnumeratePIE();
            if (devices.Length == 0)
            {
                //No Devices Found
                return(false);
            }
            else
            {
                int cbocount = 0; //keeps track of how many valid devices were added to the CboDevice box
                for (int i = 0; i < devices.Length; i++)
                {
                    //information about device
                    //PID = devices[i].Pid);
                    //HID Usage = devices[i].HidUsage);
                    //HID Usage Page = devices[i].HidUsagePage);
                    //HID Version = devices[i].Version);
                    long hidusagepg = devices[i].HidUsagePage;
                    long hidusage   = devices[i].HidUsage;
                    if (devices[i].HidUsagePage == 0xc)
                    {
                        switch (devices[i].Pid)
                        {
                        case 693:
                            _cboDevices.Items.Add(devices[i].ProductString + "16 MWII (" + devices[i].Pid + ") - " + devices[i].ManufacturersString);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        default:
                            _cboDevices.Items.Add(devices[i].ProductString + "(" + devices[i].Pid + ") " + devices[i].ManufacturersString);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;
                        }
                        devices[i].SetupInterface();
                        // true = No continues check, false = keep checking
                        devices[i].suppressDuplicateReports = true;
                    }
                }
            }
            if (_cboDevices.Items.Count > 0)
            {
                _cboDevices.SelectedIndex = 0;
                selecteddevice            = cbotodevice[_cboDevices.SelectedIndex];
                wData = new byte[devices[selecteddevice].WriteLength];//go ahead and setup for write
            }
            return(true);
        }
        private static void EnumerationThreadProc()
        {
            var oldDevices = new PIEDevice[0];

            while (true)
            {
                try
                {
                    var devices = PIEDevice.EnumeratePIE();
                    foreach (var pieDevice in devices.Where(d => d.HidUsagePage == 0xC && !oldDevices.Any(od => DeviceEquals(od, d))))
                    {
                        var device = new XKeysDevice(pieDevice);
                        lock (((IList)Devices).SyncRoot)
                            Devices.Add(device);
                        DeviceConnected?.Invoke(null, device);
                        Logger.Info("New device connected {0}:{1}", pieDevice.Pid, pieDevice.Vid);
                    }
                    foreach (var pieDevice in oldDevices.Where(d => d.HidUsagePage == 0xC && !devices.Any(od => DeviceEquals(od, d))))
                    {
                        var device = Devices.FirstOrDefault(d => DeviceEquals(d.PieDevice, pieDevice));
                        if (device == null)
                        {
                            continue;
                        }
                        device.Dispose();
                        lock (((IList)Devices).SyncRoot)
                            Devices.Remove(device);
                        Logger.Info("Device disconnected {0}:{1}", pieDevice.Pid, pieDevice.Vid);
                    }
                    oldDevices = devices;
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
        }