Esempio n. 1
0
        public static void Main()
        {
            // Game Controller
            GameController gamepad = new GameController(UsbHostDevice.GetInstance());

            // NinaB Font
            Font ninaB = Properties.Resources.GetFont(Properties.Resources.FontResources.NinaB);

            // Initializing a display module: DisplayModule(port, orientation)
            DisplayModule displayModule = new DisplayModule(CTRE.HERO.IO.Port8, DisplayModule.OrientationType.Landscape);

            while (true)
            {
                // Connect the game controller first so that the sprites show up
                if (gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                {
                    // Erases everything on the display
                    displayModule.Clear();

                    // Adding labels: [Display Module Name].AddLabelSprite(font, colour, x_pos, y_pos, width, height)
                    DisplayModule.LabelSprite title   = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 27, 17, 120, 15);
                    DisplayModule.LabelSprite x_label = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 65, 80, 15);
                    DisplayModule.LabelSprite y_label = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 85, 80, 15);

                    // Adding rectangles: [Display Module Name].AddRectSprite(colour, x_pos, y_pos, width, height)
                    DisplayModule.RectSprite x_rect = displayModule.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                    DisplayModule.RectSprite y_rect = displayModule.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);

                    // Everything gets cleared when the game controller is unplugged
                    while (gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                    {
                        // Declares and resets the joystick
                        double x_value = gamepad.GetAxis(0);
                        double y_value = -gamepad.GetAxis(1);
                        if (x_value < 0.05 && x_value > -0.05)
                        {
                            x_value = 0;
                        }
                        if (y_value < 0.05 && y_value > -0.05)
                        {
                            y_value = 0;
                        }

                        // Changes the color of the rectangle (x-value of the left joystick): [Rectangle Name].SetColor(colour)
                        if (x_value > 0.05)
                        {
                            x_rect.SetColor(DisplayModule.Color.Green);
                        }
                        else if (x_value < -0.05)
                        {
                            x_rect.SetColor(DisplayModule.Color.Red);
                        }
                        else
                        {
                            x_rect.SetColor(DisplayModule.Color.White);
                        }

                        // Changes the color of the rectangle (y-value of the left joystick): [Rectangle Name].SetColor(colour)
                        if (y_value > 0.05)
                        {
                            y_rect.SetColor(DisplayModule.Color.Green);
                        }
                        else if (y_value < -0.05)
                        {
                            y_rect.SetColor(DisplayModule.Color.Red);
                        }
                        else
                        {
                            y_rect.SetColor(DisplayModule.Color.White);
                        }

                        // Sets the text that the label displays: [Label Name].SetText(text: string)
                        title.SetText("Joystick Control");
                        x_label.SetText("X: " + x_value.ToString());
                        y_label.SetText("Y: " + y_value.ToString());
                    }
                }
                else
                {
                    // Erases everything on the display
                    displayModule.Clear();

                    // Adding images: [Display Module Name].AddResourceImageSprite(resource_manager, img_ID, img_type, x_pos, y_pos)
                    DisplayModule.ResourceImageSprite image = displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.img, Bitmap.BitmapImageType.Jpeg, 44, 16);

                    // Adding labels: [Display Module Name].AddLabelSprite(font, colour, x_pos, y_pos, width, height)
                    DisplayModule.LabelSprite text = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 36, 99, 100, 30);

                    // Sets the text that the label displays: [Label Name].SetText(text: string)
                    text.SetText("TAS Robotics");

                    // Keeps the image and text while the gamepad is unplugged
                    while (gamepad.GetConnectionStatus() == UsbDeviceConnection.NotConnected)
                    {
                    }
                }
                System.Threading.Thread.Sleep(100);
            }
        }
Esempio n. 2
0
        public void DisplayOutput()
        {
            if (displayModeRefresh == false)
            {
                title              = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 34, 17, 120, 15);
                label1             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 56, 80, 15);
                label2             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 76, 80, 15);
                label3             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 96, 80, 15);
                rect1              = display.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                rect2              = display.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);
                displayModeRefresh = true;
            }
            if (title == null || label1 == null || label2 == null || label3 == null || rect1 == null || rect2 == null)
            {
                display.Clear();
                title  = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 34, 17, 120, 15);
                label1 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 55, 80, 15);
                label2 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 75, 80, 15);
                label3 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 95, 80, 15);
                rect1  = display.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                rect2  = display.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);
            }

            string colorStringX = "0x00";
            string colorStringY = "0x00";
            string redX, blueX, greenX;
            string redY, blueY, greenY;
            int    colorIntX = (int)System.Math.Round(xAxisA * 100);
            int    colorIntY = (int)System.Math.Round(yAxisA * 100);

            if (colorIntX > 0)
            {
                blueX  = (100 - colorIntX).ToString("X2");
                greenX = "ff";
                redX   = (100 - colorIntX).ToString("X2");
            }
            else if (colorIntX < 0)
            {
                blueX  = (100 + colorIntX).ToString("X2");
                greenX = (100 + colorIntX).ToString("X2");
                redX   = "ff";
            }
            else
            {
                blueX  = "ff";
                greenX = "ff";
                redX   = "ff";
            }
            if (colorIntY > 0)
            {
                blueY  = (100 - colorIntY).ToString("X2");
                greenY = "ff";
                redY   = (100 - colorIntY).ToString("X2");
            }
            else if (colorIntY < 0)
            {
                blueY  = (100 + colorIntY).ToString("X2");
                greenY = (100 + colorIntY).ToString("X2");
                redY   = "ff";
            }
            else
            {
                blueY  = "ff";
                greenY = "ff";
                redY   = "ff";
            }
            colorStringX = colorStringX + blueX + greenX + redX;
            colorStringY = colorStringY + blueY + greenY + redY;
            rect1.SetColor((DisplayModule.Color)Convert.ToInt32(colorStringX, 16));
            rect2.SetColor((DisplayModule.Color)Convert.ToInt32(colorStringY, 16));

            label1.SetText("X: " + xAxisA.ToString());
            label2.SetText("Y: " + yAxisA.ToString());
            label3.SetText("Angle: " + ((int)System.Math.Round(angle)).ToString());
            title.SetText("Motor Control");
        }