Beispiel #1
0
        public StartMenu()
        {
            var types = Application.Current.GetType().GetTypeInfo().Assembly.GetTypes();

            foreach (var t in types)
            {
                var p = t.GetTypeInfo().GetCustomAttributes <SceneMenuEntryAttribute>();
                if (p.Count() > 0)
                {
                    // TODO: Ordering!!
                    Items.Add(new MenuItem()
                    {
                        Destination = t, Details = p.First()
                    });
                }
            }

            this.InitializeComponent();

            ListItems.Loaded += (s, e) => { ListItems.SelectedIndex = 0; };

            GamepadButtons old_buttons = GamepadButtons.None;

            Task.Run(async() =>
            {
                while (Running)
                {
                    await Task.Delay(1000 / 15);
                    if (Gamepad.Gamepads.Count > 0)
                    {
                        var buttons = Gamepad.Gamepads[0].GetCurrentReading().Buttons;
                        if (buttons.HasFlag(GamepadButtons.DPadDown) && !old_buttons.HasFlag(GamepadButtons.DPadDown))
                        {
                            var ignore = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                if (ListItems.SelectedIndex < Items.Count - 1)
                                {
                                    ++ListItems.SelectedIndex;
                                }
                            });
                        }
                        if (buttons.HasFlag(GamepadButtons.DPadUp) && !old_buttons.HasFlag(GamepadButtons.DPadUp))
                        {
                            var ignore = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                if (ListItems.SelectedIndex > 0)
                                {
                                    --ListItems.SelectedIndex;
                                }
                            });
                        }
                        if (buttons.HasFlag(GamepadButtons.A) && !old_buttons.HasFlag(GamepadButtons.A))
                        {
                            var ignore = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                var m   = ListItems.SelectedItem as MenuItem;
                                Running = false;
                                Frame.Navigate(m.Destination);
                            });
                        }
                        old_buttons = buttons;
                    }
                }
            });
        }
Beispiel #2
0
        private GamePadButtonStatus ConvertButtonsFromMsft(GamepadButtons buttonsenum)
        {
            var gamepadbuttons = new GamePadButtonStatus();

            if (buttonsenum.HasFlag((GamepadButtons)0))
            {
                gamepadbuttons.None = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)1))
            {
                gamepadbuttons.Menu = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)2))
            {
                gamepadbuttons.View = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)4))
            {
                gamepadbuttons.A = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)8))
            {
                gamepadbuttons.B = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)16))
            {
                gamepadbuttons.X = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)32))
            {
                gamepadbuttons.Y = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)64))
            {
                gamepadbuttons.Up = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)128))
            {
                gamepadbuttons.Down = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)256))
            {
                gamepadbuttons.Left = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)512))
            {
                gamepadbuttons.Right = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)1024))
            {
                gamepadbuttons.LeftShoulder = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)2048))
            {
                gamepadbuttons.RightShoulder = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)4096))
            {
                gamepadbuttons.LeftThumbstick = true;
            }
            if (buttonsenum.HasFlag((GamepadButtons)8192))
            {
                gamepadbuttons.RightThumbstick = true;
            }

            return(gamepadbuttons);
        }
Beispiel #3
0
        private GamePadButtonStatus ConvertButtonsFromMsft(GamepadButtons buttonsenum)
        {
            var gamepadbuttons = new GamePadButtonStatus();

            if (buttonsenum.HasFlag((GamepadButtons)0))
                gamepadbuttons.None = true;
            if (buttonsenum.HasFlag((GamepadButtons)1))
                gamepadbuttons.Menu = true;
            if (buttonsenum.HasFlag((GamepadButtons)2))
                gamepadbuttons.View = true;
            if (buttonsenum.HasFlag((GamepadButtons)4))
                gamepadbuttons.A = true;
            if (buttonsenum.HasFlag((GamepadButtons)8))
                gamepadbuttons.B = true;
            if (buttonsenum.HasFlag((GamepadButtons)16))
                gamepadbuttons.X = true;
            if (buttonsenum.HasFlag((GamepadButtons)32))
                gamepadbuttons.Y = true;
            if (buttonsenum.HasFlag((GamepadButtons)64))
                gamepadbuttons.Up = true;
            if (buttonsenum.HasFlag((GamepadButtons)128))
                gamepadbuttons.Down = true;
            if (buttonsenum.HasFlag((GamepadButtons)256))
                gamepadbuttons.Left = true;
            if (buttonsenum.HasFlag((GamepadButtons)512))
                gamepadbuttons.Right = true;
            if (buttonsenum.HasFlag((GamepadButtons)1024))
                gamepadbuttons.LeftShoulder = true;
            if (buttonsenum.HasFlag((GamepadButtons)2048))
                gamepadbuttons.RightShoulder = true;
            if (buttonsenum.HasFlag((GamepadButtons)4096))
                gamepadbuttons.LeftThumbstick = true;
            if (buttonsenum.HasFlag((GamepadButtons)8192))
                gamepadbuttons.RightThumbstick = true;

            return gamepadbuttons;
        }
 private void DisplayControllerState(GamepadReading reading, GamepadButtons buttons)
 {
     LeftThumbstickState.Text   = "Left Stick: " + Math.Round(reading.LeftThumbstickX, 1) + ", " + Math.Round(reading.LeftThumbstickY, 1);
     RightThumbstickState.Text  = "Right Stick: " + Math.Round(reading.RightThumbstickX, 1) + ", " + Math.Round(reading.RightThumbstickY, 1);
     LeftTriggerState.Text      = "Left Trigger: " + Math.Round(reading.LeftTrigger, 1);
     RightTriggerState.Text     = "Right Trigger: " + Math.Round(reading.RightTrigger, 1);
     LeftBumperState.Text       = "Left Bumper: " + buttons.HasFlag(GamepadButtons.LeftShoulder);
     RightBumperState.Text      = "Right Bumper: " + buttons.HasFlag(GamepadButtons.RightShoulder);
     MenuState.Text             = "Menu: " + buttons.HasFlag(GamepadButtons.Menu).ToString();
     ViewState.Text             = "View: " + buttons.HasFlag(GamepadButtons.View).ToString();
     LeftThumbButtonState.Text  = "Left Stick Button: " + buttons.HasFlag(GamepadButtons.LeftThumbstick).ToString();
     RightThumbButtonState.Text = "Right Stick Button: " + buttons.HasFlag(GamepadButtons.RightThumbstick).ToString();
     DPadUpState.Text           = "D-Pad Up: " + buttons.HasFlag(GamepadButtons.DPadUp).ToString();
     DPadDownState.Text         = "D-Pad Down: " + buttons.HasFlag(GamepadButtons.DPadDown).ToString();
     DPadLeftState.Text         = "D-Pad Left: " + buttons.HasFlag(GamepadButtons.DPadLeft).ToString();
     DPadRightState.Text        = "D-Pad Right: " + buttons.HasFlag(GamepadButtons.DPadRight).ToString();
     AState.Text = "A: " + buttons.HasFlag(GamepadButtons.A).ToString();
     BState.Text = "B: " + buttons.HasFlag(GamepadButtons.B).ToString();
     XState.Text = "X: " + buttons.HasFlag(GamepadButtons.X).ToString();
     YState.Text = "Y: " + buttons.HasFlag(GamepadButtons.Y).ToString();
 }
        private async void DispatcherTimer_TickAsync(object sender, object e)
        {
            if (arduino != null)
            {
                string arduinoStatus = arduino.ReadBufferAndGetStatus();
                ArduinoDisplay.Text = arduinoStatus;
                if (arduino.IsSimulator)
                {
                    ArduinoDisplay.Text += "\n(Simulator)";
                }
            }

            if (functionRunningName != "" && functionRunningName.StartsWith("AIM"))
            {
                if (!isAiming)
                {
                    if (targetSet)
                    {
                        SendCommand_Async("STOP");
                        if (functionRunningName == "AIM THEN FIRE")
                        {
                            SendCommand_Async("FIRE");
                            targetSet = false;
                        }
                        functionRunningName = "";
                    }
                    else
                    {
                        AimRobot_Async();
                    }
                }
            }

            if (Gamepad.Gamepads.Count > 0)
            {
                controller = Gamepad.Gamepads.First();                                          // Get the first controller
                GamepadReading reading = controller.GetCurrentReading();                        // Get the controller's reading
                GamepadButtons buttons = reading.Buttons;                                       // Get the button enum from this reading
                // Update button states on-screen
                DisplayControllerState(reading, buttons);

                // Controller Mapping
                // ==================
                // Left Stick       : Steering (X) [Acceleration (Y)]
                // Left Trigger     : Acceleration
                // Right Trigger    : Deceleration

                // D-Up             : Follow Line
                // D-Down           : Goto Range
                // D-Left           : Complete Auto
                // D-Right          : Auto Aim and Fire 5x
                // Right Bumper     : Fire
                // A                : Auto Aim
                // B                : Stop Automation
                // X                : Record Start/Stop
                // Y                : Record Go
                // View             : Goto Start / Set Start

                // Button Handlers
                if (buttons.HasFlag(GamepadButtons.DPadUp))
                {
                    buttonTimes[0] += 1;
                }
                else if (buttonTimes[0] > 0)
                {
                    if (functionRunningName == "")
                    {
                        functionRunningName = "FOLLOW";
                        SendCommand_Async("FOLLOW");
                    }
                    buttonTimes[0] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.DPadDown))
                {
                    buttonTimes[1] += 1;
                }
                else if (buttonTimes[1] > 0)
                {
                    if (functionRunningName == "")
                    {
                        functionRunningName = "GOTO RANGE";
                        SendCommand_Async("GOTO RANGE");
                    }
                    buttonTimes[1] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.DPadLeft))
                {
                    buttonTimes[2] += 1;
                }
                else if (buttonTimes[2] > 0)
                {
                    if (functionRunningName == "")
                    {
                        functionRunningName = "COMPLETE";
                    }
                    buttonTimes[2] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.DPadRight))
                {
                    buttonTimes[3] += 1;
                }
                else if (buttonTimes[3] > 0)
                {
                    if (functionRunningName == "" && inRange)
                    {
                        functionRunningName = "AIM THEN FIRE";
                    }
                    buttonTimes[3] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.RightShoulder))
                {
                    buttonTimes[4] += 1;
                }
                else if (buttonTimes[4] > 0)
                {
                    if (functionRunningName == "" && inRange)
                    {
                        // Fire
                        SendCommand_Async("FIRE");
                    }
                    buttonTimes[4] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.A))
                {
                    buttonTimes[5] += 1;
                }
                else if (buttonTimes[5] > 0)
                {
                    if (functionRunningName == "" && inRange)
                    {
                        targetSet           = false;
                        functionRunningName = "AIM";
                    }
                    buttonTimes[5] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.B))
                {
                    buttonTimes[6] += 1;
                }
                else if (buttonTimes[6] > 0)
                {
                    if (functionRunningName != "")
                    {
                        // Stop
                        functionRunningName = "";
                        SendCommand_Async("STOP");
                    }
                    buttonTimes[6] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.X))
                {
                    buttonTimes[7] += 1;
                }
                else if (buttonTimes[7] > 0)
                {
                    if (functionRunningName == "")
                    {
                        functionRunningName = "RECORD";
                        SendCommand_Async("RECORD START");
                    }
                    else if (functionRunningName == "RECORD")
                    {
                        functionRunningName = "";
                        SendCommand_Async("RECORD STOP");
                    }
                    buttonTimes[7] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.Y))
                {
                    buttonTimes[8] += 1;
                }
                else if (buttonTimes[8] > 0)
                {
                    if (functionRunningName == "")
                    {
                        functionRunningName = "RECORD GO";
                        SendCommand_Async("RECORD GO");
                    }
                    buttonTimes[8] = 0;
                }

                if (buttons.HasFlag(GamepadButtons.View))
                {
                    buttonTimes[9] += 1;
                    if (functionRunningName == "" && buttonTimes[9] == viewButtonLong)
                    {
                        // Set START
                        SendCommand_Async("SETSTART");
                    }
                }
                else if (buttonTimes[9] > 0)
                {
                    if (functionRunningName == "" && buttonTimes[9] < viewButtonLong)
                    {
                        functionRunningName = "GOTO START";
                        SendCommand_Async("GOTO START");
                    }
                    buttonTimes[9] = 0;
                }
                if (functionRunningName == "")
                {
                    motorSpeeds = new double[] { 0, 0 };

                    if (manualMotorDrive)
                    {
                        motorSpeeds = new double[] { reading.LeftThumbstickY, reading.RightThumbstickY };
                    }
                    else
                    {
                        // Once done, remove rounding!
                        double steering = reading.LeftThumbstickX;
                        // Use either the left stick Y or the triggers for acceleration value:
                        double acceleration = reading.LeftTrigger - reading.RightTrigger;           // Use triggers
                        //double acceleration = reading.LeftThumbstickY;                              // Use left stick Y
                        // Remove sensitivity around 0 zones
                        double zoneRadius = 0.1;
                        steering     = -zoneRadius < steering && steering < zoneRadius ? 0 : steering;
                        acceleration = -zoneRadius < acceleration && acceleration < zoneRadius ? 0 : acceleration;
                        motorSpeeds  = ComputeMotorSpeeds(steering, acceleration, buttons.HasFlag(GamepadButtons.LeftThumbstick) ? 0.5 : 1);
                    }

                    if (loopsUntilMotorSend <= 0)
                    {
                        SendCommand_Async("SETMOTORS " + Math.Round(motorSpeeds[0], 2).ToString() + "," + Math.Round(motorSpeeds[1], 2).ToString());
                        loopsUntilMotorSend = loopsUntilMotorSendReset;
                    }
                    else
                    {
                        loopsUntilMotorSend--;
                    }
                }

                FunctionDisplay.Text = functionRunningName;
            }
        }
Beispiel #6
0
 private void g_Gamepad_OnButtonUp(object sender, GamepadButtons e)
 {
     if (e.HasFlag(GamepadButtons.A))
     {
         StopJump();
     }
     else if (e.HasFlag(GamepadButtons.X))
     {
         if (InHandItem != null)
             InHandItem.FinishAction();
     }
 }