Esempio n. 1
0
        /* Set GRB LED PWM with Serial communication */
        private void setLedPWM(ledColor color, int pwm)
        {
            string commandColor = "";

            switch (color)
            {
            case ledColor.Red:
                commandColor = "R";
                break;

            case ledColor.Blue:
                commandColor = "B";
                break;

            case ledColor.Green:
                commandColor = "G";
                break;

            default:
                break;
            }

            /* Limit PWM to 255 */
            pwm = pwm > 255 ? 255 : pwm;

            if (Environment.TickCount - lastTick > 30)
            {
                btSerialPort.Write(commandColor + pwm + "X");
                lastTick = Environment.TickCount;
            }
        }
Esempio n. 2
0
 private void advColorDialog_OnUpdateColor(object sender, EventArgs e)
 {
     if (oldLedColor == null || oldLowLedColor == null)
     {
         ledColor color = Global.loadColor(device);
         oldLedColor    = new Byte[] { color.red, color.green, color.blue };
         color          = Global.loadLowColor(device);
         oldLowLedColor = new Byte[] { color.red, color.green, color.blue };
     }
     if (sender is Color)
     {
         Color color = (Color)sender;
         Global.saveColor(device, color.R, color.G, color.B);
         Global.saveLowColor(device, color.R, color.G, color.B);
     }
 }
Esempio n. 3
0
        public CustomMapping(int deviceNum)
        {
            InitializeComponent();
            device = deviceNum;
            ledColor color = Global.loadColor(device);

            pictureBox.BackColor = Color.FromArgb(color.red, color.green, color.blue);
            List <object> availableButtons = new List <object>();

            foreach (Control control in this.Controls)
            {
                if (control is ComboBox)
                {
                    comboBoxes.Add((ComboBox)control);
                    availableButtons.Add(control.Text);

                    // Add defaults
                    defaults.Add(((ComboBox)control).Name, ((ComboBox)control).Text);
                    // Add events here (easier for modification/addition)
                    ((ComboBox)control).SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChangedCommand);
                    ((ComboBox)control).Enter          += new System.EventHandler(this.EnterCommand);
                    ((ComboBox)control).KeyDown        += new System.Windows.Forms.KeyEventHandler(this.KeyDownCommand);
                    ((ComboBox)control).KeyPress       += new System.Windows.Forms.KeyPressEventHandler(this.KeyPressCommand);
                    ((ComboBox)control).PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.PreviewKeyDownCommand);
                }
            }
            availableButtons.Sort();
            foreach (ComboBox comboBox in comboBoxes)
            {
                comboBox.Items.AddRange(availableButtons.ToArray());
            }
            // Do not add XInput to touchpad
            cbTouchButtom.Items.Clear();
            cbTouchButtom.Items.Add(cbTouchButtom.Text);
            cbTouchUpper.Items.Clear();
            cbTouchUpper.Items.Add(cbTouchUpper.Text);
            cbTouchMulti.Items.Clear();
            cbTouchMulti.Items.Add(cbTouchMulti.Text);
            Global.loadCustomMapping(Global.getCustomMap(device), comboBoxes.ToArray());
        }
Esempio n. 4
0
        public Options(BusDevice bus_device, int deviceNum)
        {
            InitializeComponent();
            device    = deviceNum;
            scpDevice = bus_device;
            ledColor color = Global.loadColor(device);

            redBar.Value                 = color.red;
            greenBar.Value               = color.green;
            blueBar.Value                = color.blue;
            rumbleBoostBar.Value         = ScpControl.Global.loadRumbleBoost(device);
            batteryLed.Checked           = ScpControl.Global.getLedAsBatteryIndicator(device);
            flashLed.Checked             = ScpControl.Global.getFlashWhenLowBattery(device);
            touchCheckBox.Checked        = Global.getTouchEnabled(device);
            touchSensitivityBar.Value    = Global.getTouchSensitivity(device);
            leftTriggerMiddlePoint.Text  = Global.getLeftTriggerMiddle(device).ToString();
            rightTriggerMiddlePoint.Text = Global.getRightTriggerMiddle(device).ToString();
            ledColor lowColor = Global.loadLowColor(device);

            touchpadJitterCompensation.Checked = Global.getTouchpadJitterCompensation(device);
            lowerRCOffCheckBox.Checked         = Global.getLowerRCOff(device);
            tapSensitivityBar.Value            = Global.getTapSensitivity(device);
            scrollSensitivityBar.Value         = Global.getScrollSensitivity(device);
            flushHIDQueue.Checked         = Global.getFlushHIDQueue(device);
            advColorDialog.OnUpdateColor += advColorDialog_OnUpdateColor;

            // Force update of color choosers
            colorChooserButton.BackColor    = Color.FromArgb(color.red, color.green, color.blue);
            lowColorChooserButton.BackColor = Color.FromArgb(lowColor.red, lowColor.green, lowColor.blue);
            pictureBox.BackColor            = colorChooserButton.BackColor;
            lowRedValLabel.Text             = lowColor.red.ToString();
            lowGreenValLabel.Text           = lowColor.green.ToString();
            lowBlueValLabel.Text            = lowColor.blue.ToString();

            #region watch sixaxis data
            Timer sixaxisTimer = new Timer();
            sixaxisTimer.Tick +=
                (delegate
            {
                if (tBsixaxisGyroX == null)
                {
                    tBsixaxisGyroX = new TrackBar();
                    tBsixaxisGyroY = new TrackBar();
                    tBsixaxisGyroZ = new TrackBar();
                    tBsixaxisAccelX = new TrackBar();
                    tBsixaxisAccelY = new TrackBar();
                    tBsixaxisAccelZ = new TrackBar();
                    TrackBar[] allSixAxes = { tBsixaxisGyroX,  tBsixaxisGyroY,  tBsixaxisGyroZ,
                                              tBsixaxisAccelX, tBsixaxisAccelY, tBsixaxisAccelZ };
                    foreach (TrackBar t in allSixAxes)
                    {
                        ((System.ComponentModel.ISupportInitialize)(t)).BeginInit();
                        t.Anchor = AnchorStyles.Bottom;
                        t.AutoSize = false;
                        t.Enabled = false;
                        t.Minimum = -0x8000;
                        t.Maximum = 0x7fff;
                        t.Size = new Size(100, 19);
                        t.TickFrequency = 0x2000;     // calibrated to ~1G
                    }
                    // tBsixaxisGyroX
                    tBsixaxisGyroX.Location = new Point(450, 248);
                    tBsixaxisGyroX.Name = "tBsixaxisGyroX";
                    // tBsixaxisGyroY
                    tBsixaxisGyroY.Location = new Point(450, 248 + 20);
                    tBsixaxisGyroY.Name = "tBsixaxisGyroY";
                    // tBsixaxisGyroZ
                    tBsixaxisGyroZ.Location = new Point(450, 248 + 20 + 20);
                    tBsixaxisGyroZ.Name = "tBsixaxisGyroZ";
                    // tBsixaxisAccelX
                    tBsixaxisAccelX.Location = new Point(450 + 100 + 10, 248);
                    tBsixaxisAccelX.Name = "tBsixaxisAccelX";
                    // tBsixaxisAccelY
                    tBsixaxisAccelY.Location = new Point(450 + 100 + 10, 248 + 20);
                    tBsixaxisAccelY.Name = "tBsixaxisAccelY";
                    // tBsixaxisAccelZ
                    tBsixaxisAccelZ.Location = new Point(450 + 100 + 10, 248 + 20 + 20);
                    tBsixaxisAccelZ.Name = "tBsixaxisAccelZ";
                    foreach (TrackBar t in allSixAxes)
                    {
                        Controls.Add(t);
                        ((System.ComponentModel.ISupportInitialize)(t)).EndInit();
                    }
                }
                byte[] inputData = scpDevice.GetInputData(device);
                if (inputData != null)
                {
                    // MEMS gyro data is all calibrated to roughly -1G..1G for values -0x2000..0x1fff
                    // Enough additional acceleration and we are no longer mostly measuring Earth's gravity...
                    // We should try to indicate setpoints of the calibration when exposing this measurement....

                    // R side of controller upward
                    Int16 x = (Int16)((UInt16)(inputData[20] << 8) | inputData[21]);
                    tBsixaxisGyroX.Value = (x + tBsixaxisGyroX.Value * 2) / 3;
                    // touchpad and button face side of controller upward
                    Int16 y = (Int16)((UInt16)(inputData[22] << 8) | inputData[23]);
                    tBsixaxisGyroY.Value = (y + tBsixaxisGyroY.Value * 2) / 3;
                    // audio/expansion ports upward and light bar/shoulders/bumpers/USB port downward
                    Int16 z = (Int16)((UInt16)(inputData[24] << 8) | inputData[25]);
                    tBsixaxisGyroZ.Value = (z + tBsixaxisGyroZ.Value * 2) / 3;
                    // pitch upward/backward
                    Int16 pitch = (Int16)((UInt16)(inputData[14] << 8) | inputData[15]);
                    tBsixaxisAccelX.Value = (pitch + tBsixaxisAccelX.Value * 2) / 3;     // smooth out
                    // yaw leftward/counter-clockwise/turn to port or larboard side
                    Int16 yaw = (Int16)((UInt16)(inputData[16] << 8) | inputData[17]);
                    tBsixaxisAccelY.Value = (yaw + tBsixaxisAccelY.Value * 2) / 3;
                    // roll left/L side of controller down/starboard raising up
                    Int16 roll = (Int16)((UInt16)(inputData[18] << 8) | inputData[19]);
                    tBsixaxisAccelZ.Value = (roll + tBsixaxisAccelZ.Value * 2) / 3;
                }
            });
            sixaxisTimer.Interval = 1000 / 60;
            this.FormClosing     += delegate { sixaxisTimer.Stop(); };
            sixaxisTimer.Start();
            #endregion
        }