public XInputController(int deviceIndex)
 {
     _deviceIndex = deviceIndex;
     _controller = XboxController.RetrieveController(deviceIndex);
     _running = true;
     _monitorThread = new Thread(MonitorThread);
     _monitorThread.Start();
 }
 public MainWindow()
 {
     InitializeComponent();
     DataContext = this;
     _selectedController = XboxController.RetrieveController(0);
     _selectedController.StateChanged += _selectedController_StateChanged;
     XboxController.StartPolling();
 }
        public XboxControllerWithInterruptHandler(XboxController x)
        {
            X = x;

            X.StateChanged += X_StateChanged;

            PreviousState = new State(false, false, false, false, false, false, false, false);
            NewState      = new State(false, false, false, false, false, false, false, false);
        }
Exemple #4
0
 static XboxController()
 {
     Controllers = new XboxController[MAX_CONTROLLER_COUNT];
     SyncLock = new object();
     for (int i = FIRST_CONTROLLER_INDEX; i <= LAST_CONTROLLER_INDEX; ++i)
     {
         Controllers[i] = new XboxController(i);
     }
     UpdateFrequency = 25;
 }
Exemple #5
0
 static XboxController()
 {
     Controllers = new XboxController[MAX_CONTROLLER_COUNT];
     SyncLock    = new object();
     for (int i = FIRST_CONTROLLER_INDEX; i <= LAST_CONTROLLER_INDEX; ++i)
     {
         Controllers[i] = new XboxController(i);
     }
     UpdateFrequency = 25;
 }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            mqttBroker = "127.0.0.1";

            var p = new OptionSet
            {
                   { "mqtt=", (v) => { mqttBroker = v; } },
            };

            p.Parse(Environment.GetCommandLineArgs());

            joyStick1.JoystickMovedListeners += joystickMoved;

            _selectedController = XboxController.RetrieveController(0);
            XboxController.UpdateFrequency = 10;
            _selectedController.StateChanged += _selectedController_StateChanged;
            XboxController.StartPolling();
        }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            _selectedController = XboxController.RetrieveController(0);
            _selectedController.StateChanged += _selectedController_StateChanged;

            _droneClient = new DroneClient("192.168.1.1");

            _droneClient.Start();

            _droneClient.NavigationPacketAcquired += OnNavigationPacketAcquired;
            _droneClient.NavigationDataAcquired += ProcessNavigationData;

            _droneClient.FlatTrim();

            _timer = new System.Timers.Timer(50);
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();

            XboxController.StartPolling();
        }
 /// <summary>
 /// 开始装逼
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     if (!WinIOLab.IsInitialize)
     {
         this.button1.Text = "让我歇会儿再装逼";
         WinIOLab.Initialize();
         xBoxControl = XboxController.RetrieveController(0);
         xBoxControl.StateChanged += xBoxControl_StateChanged;
         XboxController.StartPolling();
         stickThread = new Thread(StickStatic);
         stickThread.Start();
         dpsThread = new Thread(dps);
         dpsThread.Start();
     }
     else
     {
         this.button1.Text = "开始强行装逼";
         WinIOLab.Shutdown();
         XboxController.StopPolling();
         stickThread.Abort();
         dpsThread.Abort();
     }
 }
        private void SetupKeyHandlers()
        {
            //register for keyboard events
            KeyDown += MainWindow_KeyDown;

            //register for xbox controller events
            handHeldController = XboxController.RetrieveController(0);
            handHeldController.StateChanged += handHeldController_StateChanged;
            XboxController.StartPolling();
        }
Exemple #10
0
 private void HandleInput(ref PlayerInput playerInput, XboxController controller)
 {
     //Vector3 cameraPos = BaseGame.CameraPos;
     if (Input.KeyboardUpPressed || controller.RightTrigger > 0)
     {
         //_playerForwardDelta = ForwardScalar * _elapsedGameTime;
         playerInput.Forward = 0.5f;
     }
     else if (Input.KeyboardDownPressed || controller.LeftTrigger > 0)
     {
         //_playerForwardDelta = -ForwardScalar * _elapsedGameTime;
         playerInput.Forward = -0.5f;
     }
     if (Input.KeyboardLeftPressed || controller.IsDPadLeftPressed)
     {
         //_playerRotationDelta = -RotationScalar * _elapsedGameTime;
         playerInput.Rotation = 0.5f;
     }
     else if (Input.KeyboardRightPressed || controller.IsDPadRightPressed)
     {
         //_playerRotationDelta = RotationScalar * _elapsedGameTime;
         playerInput.Rotation = -0.5f;
     }
 }
Exemple #11
0
 private void SelectedControllerChanged(object sender, SelectionChangedEventArgs e)
 {
     _selectedController = XboxController.RetrieveController(((ComboBox)sender).SelectedIndex);
     OnPropertyChanged("SelectedController");
 }
        //Static for now... not sure if we actually need to make this class instatiable
        public static async Task HandleInput(MainWindow mainWindow, PanTiltController panTilt, FiringController firingController, 
            Key? key, XboxController handHeldController){
            ////////////////////////////////////////////////////////////////////////////
            //Manual Control Logic
            ////////////////////////////////////////////////////////////////////////////
            if (panTilt.IsReady)
            {
                if (key != null)
                {
                    HandlePanTilt(mainWindow, panTilt, firingController, (Key)key);
                }
                else
                {
                    HandleXboxInputPanTilt(mainWindow, panTilt, firingController, handHeldController);
                }
            }
            
            if (key == Key.NumPad1 || key == Key.D1 || handHeldController.IsXPressed)
            {
                mainWindow.TrackingMode = TrackingMode.MANUAL;
                mainWindow.AudioMeterVisibility = Visibility.Hidden;
            }
            else if (key == Key.NumPad2 || key == Key.D2 || handHeldController.IsAPressed)
            {
                mainWindow.TrackingMode = TrackingMode.SKELETAL;
                mainWindow.AudioMeterVisibility = Visibility.Hidden;
            }
            else if (key == Key.NumPad3 || key == Key.D3 || handHeldController.IsBPressed)
            {
                mainWindow.TrackingMode = TrackingMode.AUDIBLE;
                mainWindow.AudioMeterVisibility = Visibility.Visible;
            }
            //The ordering rational of the key assignments is based on 
            //the bottom row of the keyboard
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.Z)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.A;
            }
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.X)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.B;
            }
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.C)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.C;
            }
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.V)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.D;
            }
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.B)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.E;
            }
            else if (mainWindow.TrackingMode == TrackingMode.SKELETAL &&
                key == Key.N)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.F;
            }
            else if (key == Key.NumPad4 || key == Key.D4 || handHeldController.IsYPressed)
            {
                //toggle 'night vision' mode
                if (mainWindow.DisplayMode == DisplayMode.INFRARED)
                {
                    mainWindow.DisplayMode = DisplayMode.COLOR;
                }
                else{
                    mainWindow.DisplayMode = DisplayMode.INFRARED;
                }

                //check to see if this is the UI thread, xbox controller uses different thread
                if (!mainWindow.Dispatcher.CheckAccess())
                {
                    await mainWindow.Dispatcher.BeginInvoke((Action)(()=>{
                    
                        mainWindow.CameraFeedImageSource.Source = mainWindow.ImageSource;
                    
                    }));
                    
                }
                else
                {
                    //we're on the UI thread directly change the UI element image source, keyboard stroke hits this path
                    mainWindow.CameraFeedImageSource.Source = mainWindow.ImageSource;
                }
            }

            if (handHeldController.IsDPadRightPressed)
            {
                mainWindow.RequestedTrackedSkeleton++;
                //Console.WriteLine(mainWindow.RequestedTrackedSkeleton);
            }
            if (handHeldController.IsDPadLeftPressed)
            {
                mainWindow.RequestedTrackedSkeleton--;
            }
            if (handHeldController.IsDPadDownPressed)
            {
                mainWindow.RequestedTrackedSkeleton = SkeletalLetter.A;
            }
            /////////////////////////////////////////////////////////
            //Rage Safteys - Makey Makey Board Provides These Events
            /////////////////////////////////////////////////////////
            try
            {
                //mainWindow.Cannon is too high
                if (key == Key.A && !s_PanTiltTooFarUp)
                {
                    s_PanTiltTooFarUp = true;
                    mainWindow.CannonYVelocity = 0;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }
                //mainWindow.Cannon is too low
                else if (key == Key.S && !s_PanTiltTooFarDown)
                {
                    s_PanTiltTooFarDown = true;
                    mainWindow.CannonYVelocity = 0;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }
                //mainWindow.Cannon is too far right
                else if (key == Key.D && !s_PanTiltTooFarRight)
                {
                    s_PanTiltTooFarRight = true;
                    mainWindow.CannonXVelocity = 0;
                    panTilt.PanX(mainWindow.CannonXVelocity);
                }
                //mainWindow.Cannon is too far left
                else if (key == Key.F && !s_PanTiltTooFarLeft)
                {
                    s_PanTiltTooFarLeft = true;
                    mainWindow.CannonXVelocity = 0;
                    panTilt.PanX(mainWindow.CannonXVelocity);
                }
            }
            //if anything at all goes wrong we gotta stop the pantilt and crash the app
            catch(Exception ex)
            {
                panTilt.Disengage();
                throw ex;
            }

            if ((key == Key.P || (handHeldController.IsLeftShoulderPressed & handHeldController.IsRightShoulderPressed)) && firingController.VirtualSafetyOn)
            {



                //keep safety from being toggled too fast
                if ((DateTime.Now - s_LastDisarmTime > s_DisarmWaitTime) || s_LastDisarmTime == null)
                {
                    s_LastDisarmTime = DateTime.Now;
                    //toggle the safety
                    firingController.VirtualSafetyOn = !firingController.VirtualSafetyOn;
                    s_VoiceSynth.SelectVoice("Microsoft Hazel Desktop");
                    s_VoiceSynth.SpeakAsync("System Armed, Pull both triggers simultaneously to fire!");
                }

                
                
                //handHeldController.Vibrate(40.0, 40.0, 10.0);
            }
            else if ((key == Key.P || (handHeldController.IsLeftShoulderPressed & handHeldController.IsRightShoulderPressed)) && !firingController.VirtualSafetyOn)
            {
                //keep safety from being toggled too fast
                if (DateTime.Now - s_LastDisarmTime > s_DisarmWaitTime)
                {
                    s_LastDisarmTime = DateTime.Now;
                    //toggle the safety
                    firingController.VirtualSafetyOn = !firingController.VirtualSafetyOn;
                    s_VoiceSynth.SelectVoice("Microsoft Hazel Desktop");
                    s_VoiceSynth.SpeakAsync("System Disarmed!");
                }
                
            }
            //MAYBE WE SHOULD PICK A HARDER TO PRESS KEY THAN THE SPACE BAR?
            if (key == Key.Space || (handHeldController.RightTrigger > 250 && handHeldController.LeftTrigger > 250))
            {
                handHeldController.Vibrate(VIBRATION_INTENSITY, VIBRATION_INTENSITY, new TimeSpan(1));
                await firingController.Fire(350);
            }

            
        }
        private static void HandleXboxInputPanTilt(MainWindow mainWindow, PanTiltController panTilt, FiringController firingController,
            XboxController handHeldController)
        {
            try
            {
                var convertedXboxInputX = ConvertXInputCoordinateToVelocity(handHeldController.LeftThumbStick.X);
                var convertedXboxInputY = ConvertXInputCoordinateToVelocity(handHeldController.LeftThumbStick.Y);
                Console.WriteLine("X Value Converted - " + convertedXboxInputX);
                //Pan Up & Pan Down for Manual Tracking
                if (convertedXboxInputY <= PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarDown && mainWindow.TrackingMode == TrackingMode.MANUAL)
                {
                    s_PanTiltTooFarUp = false;
                    mainWindow.CannonYVelocity = convertedXboxInputY;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }
                if (convertedXboxInputY >= -1 * PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarUp && mainWindow.TrackingMode == TrackingMode.MANUAL)
                {

                    mainWindow.CannonYVelocity = convertedXboxInputY;
                    //set too far to false. if its stil too far the next key event handler will set to true
                    s_PanTiltTooFarDown = false;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }

                if (convertedXboxInputY <= PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarDown && mainWindow.TrackingMode == TrackingMode.AUDIBLE)
                {
                    s_PanTiltTooFarUp = false;
                    mainWindow.CannonYVelocity = convertedXboxInputY;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }
                if (convertedXboxInputY >= -1 * PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarUp && mainWindow.TrackingMode == TrackingMode.AUDIBLE)
                {

                    mainWindow.CannonYVelocity = convertedXboxInputY;
                    //set too far to false. if its stil too far the next key event handler will set to true
                    s_PanTiltTooFarDown = false;
                    panTilt.PanY(mainWindow.CannonYVelocity);
                }
                if (mainWindow.CannonXVelocity >= -1 * PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarRight && mainWindow.TrackingMode == TrackingMode.MANUAL)
                {

                    mainWindow.CannonXVelocity = convertedXboxInputX;
                    //set too far to false. if its stil too far the next key event handler will set to true
                    s_PanTiltTooFarLeft = false;
                    panTilt.PanX(mainWindow.CannonXVelocity);
                }
                if (mainWindow.CannonXVelocity <= PAN_TILT_SPEED_LIMIT && !s_PanTiltTooFarLeft && mainWindow.TrackingMode == TrackingMode.MANUAL)
                {
                    mainWindow.CannonXVelocity = convertedXboxInputX;

                    //set too far to false. if its stil too far the next key event handler will set to true
                    s_PanTiltTooFarRight = false;
                    panTilt.PanX(mainWindow.CannonXVelocity);
                }
            }
            //anything goes wrong, stop pantilt and crash the app
            catch (Exception ex)
            {
                panTilt.Disengage();
                throw ex;
            }

        }