Example #1
0
        public override void OnConnectionStateChange(BluetoothDevice device, [GeneratedEnum] ProfileState status, [GeneratedEnum] ProfileState newState)
        {
            if (status == ProfileState.Connected)
            {
                OnDeviceAdded?.Invoke(device);
            }

            base.OnConnectionStateChange(device, status, newState);
        }
        /// <summary>
        /// Prevents a default instance of the <see cref="AndroidController"/> class from being created.
        /// </summary>
        private AndroidController()
        {
            this.connectedDevices = new List <string>();
            ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER);
            this.resourceDirectory = ResourceFolderManager.GetRegisteredFolderPath(ANDROID_CONTROLLER_TMP_FOLDER);
            //CreateResourceDirectories();
            //ExtractResources();
            this.m_eventWatcher = new ManagementEventWatcher(
                new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2")
                );
            this.m_eventWatcher.EventArrived += (s, evt) => {
                var m_oldConnectedDevices = connectedDevices;
                var m_newConnectedDevices = ConnectedDevices;

                if (m_oldConnectedDevices.Count != m_newConnectedDevices.Count)
                {
                    // List sizes do not match.
                    // Depending on whether the new list is longer or short, fire the corresponding event.
                    if (m_newConnectedDevices.Count > m_oldConnectedDevices.Count)
                    {
                        // A new device was added.
                        // Find out which device it was.
                        foreach (string m_device in m_newConnectedDevices)
                        {
                            if (!m_oldConnectedDevices.Contains(m_device))
                            {
                                // We've found the device that was added.
                                // We know this because the old list doesn't contain this device's serial.
                                // Now fire OnDeviceAdded event(s).
                                foreach (DeviceAddedEventHandler m_handler in OnDeviceAdded.GetInvocationList())
                                {
                                    m_handler(
                                        this,
                                        new OnDeviceAddedEventArgs(
                                            "A new device was added to the local machine.",
                                            GetConnectedDevice(m_device)
                                            )
                                        );
                                }
                            }
                        }
                    }
                    else
                    {
                        // A device was removed.
                        // Find out which one it was.
                        foreach (string m_device in m_oldConnectedDevices)
                        {
                            if (!m_newConnectedDevices.Contains(m_device))
                            {
                                // We've found the device that was removed.
                                // We know this because the new list doesn't contain the device's serial.
                                // Now fire OnDeviceRemoved event(s).
                                foreach (DeviceRemovedEventHandler m_handler in OnDeviceRemoved.GetInvocationList())
                                {
                                    m_handler(
                                        this,
                                        new OnDeviceRemovedEventArgs(
                                            "A device was removed from the local machine.",
                                            m_device
                                            )
                                        );
                                }
                            }
                        }
                    }
                }
                else
                {
                    return;    // Nothing to do here, so don't bother.
                }
            };
            if (m_monitorUSB)
            {
                m_eventWatcher.Start();
            }
        }
Example #3
0
        private void Update()
        {
            if (SDL_Installed && !SDL_Initialized)
            {
                InitSDL();
            }
            if (!SDL_Initialized)
            {
                return;
            }

            SDL.SDL_Event e;

            while (SDL.SDL_PollEvent(out e) > 0)
            {
                switch (e.type)
                {
                case SDL.SDL_EventType.SDL_KEYDOWN:
                    OnKey?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_KEYUP:
                    OnKey?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION:
                    OnAxisMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN:
                    OnButton?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP:
                    OnButton?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED:
                    Controller.AddDevice(e.cdevice.which);
                    OnDeviceAdded?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED:
                    Controller.RemoveDisconnected();
                    OnDeviceRemoved?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED:
                    OnDeviceRemapped?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYAXISMOTION:
                    OnAxisMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYBALLMOTION:
                    OnBallMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYHATMOTION:
                    OnHatMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYBUTTONDOWN:
                    OnButton?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_JOYBUTTONUP:
                    OnButton?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_JOYDEVICEADDED:
                    Controller.AddDevice(e.jdevice.which);
                    OnDeviceAdded?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYDEVICEREMOVED:
                    Controller.RemoveDisconnected();
                    OnDeviceRemoved?.Invoke(e);
                    break;

                default:
                    break;
                }
            }
        }
Example #4
0
 /// <summary>
 /// Операция добавления устройства
 /// </summary>
 /// <param name="parDevice">Физическое устройство OpenTK</param>
 private void DeviceAdd(MDeviceOpenTk parDevice)
 {
     AvailableDevices.Add(parDevice);
     OnDeviceAdded?.Invoke(parDevice);
 }