Beispiel #1
0
 private static void AquireAll()
 {
     pollerList = Poller.RegisterOnAllDevices();
     foreach (Poller p in pollerList)
     {
         p.Acquire();
     }
 }
        private static ActionStatus Start_mapping()
        {
            runningStatus = RunStatus.starting;
            DataTable configTable = ConfigController.GetConfigData(false);

            if (myPollerList == null)
            {
                myPollerList = new List <Poller>();
            }
            if (PollerThreadList == null)
            {
                PollerThreadList = new List <Thread>();
            }

            try
            {
                foreach (DataRow row in configTable.Rows)
                {
                    DirectInput directInput = new DirectInput();
                    foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
                    {
                        if (((string)deviceInstance.InstanceName).ToUpper() == (string)row[0] &&
                            row[2] != null && row[2] != System.DBNull.Value)
                        {
                            Poller tempPoller = new Poller(directInput, deviceInstance.InstanceGuid)
                            {
                                Button   = (string)row[1],
                                Bindings = (string)row[2]
                            };
                            tempPoller.Acquire();
                            myPollerList.Add(tempPoller);
                        }
                    }

                    foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.FirstPerson, DeviceEnumerationFlags.AllDevices))
                    {
                        if (((string)deviceInstance.InstanceName).ToUpper() == (string)row[0] &&
                            row[2] != null && row[2] != System.DBNull.Value)
                        {
                            Poller tempPoller = new Poller(directInput, deviceInstance.InstanceGuid)
                            {
                                Button   = (string)row[1],
                                Bindings = (string)row[2]
                            };
                            tempPoller.Acquire();
                            myPollerList.Add(tempPoller);
                        }
                    }
                }

                foreach (Poller poller in myPollerList)
                {
                    if (poller.DirectInput != null && poller.InstanceGuid != null)
                    {
                        poller.Poll = true;
                        Thread pollerThread = new Thread(new ThreadStart(poller.StartPolling));
                        PollerThreadList.Add(pollerThread);
                        pollerThread.Start();
                    }
                }
            }
            catch (Exception)
            {
                runningStatus = RunStatus.stopped;
                return(ActionStatus.startingError);
            }
            runningStatus = RunStatus.running;
            return(ActionStatus.running);
        }