Exemplo n.º 1
0
        public MainForm()
        {
            this.FormBorderStyle = FormBorderStyle.None;
            InitializeComponent();

            ControllerData = new ControllerData();
            state          = new SteamController.SteamControllerState();
            // 5s lookback for smoothing
            sensorData = new SensorCollector(5, true);

            LoadThemes();
            LoadSettings();
            if (File.Exists("ctrl.last"))
            {
                settings.Theme = File.ReadAllText("ctrl.last");
                File.Delete("ctrl.last");
            }
            if (!string.IsNullOrWhiteSpace(settings.Theme) && File.Exists(settings.Theme))
            {
                LoadTheme(settings.Theme, false); // we'll just let this task spool off on its own and pray
            }
            if (!string.IsNullOrWhiteSpace(settings.Background))
            {
                try
                {
                    this.BackColor = ColorTranslator.FromHtml(settings.Background);
                }
                catch { }
            }
            LoadControllers(true);
        }
Exemplo n.º 2
0
        public Int32 GetAnalogControl(string inputName)
        {
            if (ActiveController == null)
            {
                return(0);
            }

            inputName = inputName.ToLowerInvariant();

            SteamController.SteamControllerState state = ActiveController.GetState();

            switch (inputName)
            {
            case "leftpadx": return(state.LeftPadX);

            case "leftpady": return(state.LeftPadY);

            case "rightpadx": return(state.RightPadX);

            case "rightpady": return(state.RightPadY);

            case "leftstickx": return(state.LeftStickX);

            case "leftsticky": return(state.LeftStickY);

            case "lefttrigger": return(state.LeftTrigger);

            case "righttrigger": return(state.RightTrigger);

            default: return(0);
            }
        }
Exemplo n.º 3
0
 private void MainForm_StateUpdated(object sender, SteamController.SteamControllerState e, int index)
 {
     txtTemp1.Invoke((MethodInvoker) delegate
     {
         // Running on the UI thread
         txtTemp[index].Text =
             $"Buttons.A = {e.Buttons.A}\r\n" +
             $"Buttons.B = {e.Buttons.B}\r\n" +
             $"Buttons.X = {e.Buttons.X}\r\n" +
             $"Buttons.Y = {e.Buttons.Y}\r\n" +
             "\r\n" +
             $"Buttons.LeftBumper = {e.Buttons.LeftBumper}\r\n" +
             $"Buttons.LeftTrigger = {e.Buttons.LeftTrigger}\r\n" +
             $"Buttons.LeftGrip = {e.Buttons.LeftGrip}\r\n" +
             "\r\n" +
             $"Buttons.RightBumper = {e.Buttons.RightBumper}\r\n" +
             $"Buttons.RightTrigger = {e.Buttons.RightTrigger}\r\n" +
             $"Buttons.RightGrip = {e.Buttons.RightGrip}\r\n" +
             "\r\n" +
             $"Buttons.CenterRight = {e.Buttons.Start}\r\n" +
             $"Buttons.Center = {e.Buttons.Steam}\r\n" +
             $"Buttons.CenterLeft = {e.Buttons.Select}\r\n" +
             "\r\n" +
             $"Buttons.Up = {e.Buttons.Up}\r\n" +
             $"Buttons.Down = {e.Buttons.Down}\r\n" +
             $"Buttons.Left = {e.Buttons.Left}\r\n" +
             $"Buttons.Right = {e.Buttons.Right}\r\n" +
             "\r\n" +
             $"Buttons.ThumbStick = {e.Buttons.StickClick}\r\n" +
             $"Buttons.LeftPadTouch = {e.Buttons.LeftPadTouch}\r\n" +
             $"Buttons.LeftPadPress = {e.Buttons.LeftPadClick}\r\n" +
             $"Buttons.RightPadTouch = {e.Buttons.RightPadTouch}\r\n" +
             $"Buttons.RightPadPress = {e.Buttons.RightPadClick}\r\n" +
             "\r\n" +
             $"LeftTrigger = {e.LeftTrigger}\r\n" +
             $"RightTrigger = {e.RightTrigger}\r\n" +
             "\r\n" +
             $"LeftStickX = {e.LeftStickX}\r\n" +
             $"LeftStickY = {e.LeftStickY}\r\n" +
             $"LeftPadX = {e.LeftPadX}\r\n" +
             $"LeftPadY = {e.LeftPadY}\r\n" +
             $"RightPadX = {e.RightPadX}\r\n" +
             $"RightPadY = {e.RightPadY}\r\n" +
             "\r\n" +
             $"AngularVelocityX = {e.AngularVelocityX}\r\n" +
             $"AngularVelocityY = {e.AngularVelocityY}\r\n" +
             $"AngularVelocityZ = {e.AngularVelocityZ}\r\n" +
             $"OrientationW = {e.OrientationW}\r\n" +
             $"OrientationX = {e.OrientationX}\r\n" +
             $"OrientationY = {e.OrientationY}\r\n" +
             $"OrientationZ = {e.OrientationZ}\r\n";
     });
 }
Exemplo n.º 4
0
        private void Render(object stateInfo)
        {
            var state = new SteamController.SteamControllerState();

            if (ActiveController != null)
            {
                state = ActiveController.GetState();
                sensorData.Update(state);
            }

            if (!this.IsDisposed && this.InvokeRequired && sensorData != null)
            {
                try
                {
                    this.Invoke(new Action(() =>
                    {// force a full repaint
                        this.Invalidate();
                    }));
                }
                catch (ObjectDisposedException e) { /* eat the Disposed exception when exiting */ }
            }
        }
Exemplo n.º 5
0
        public SensorData Update(SteamController.SteamControllerState stateData)
        {// atomic updates
            if (0 == Interlocked.Exchange(ref usingResource, 1))
            {
                Data = new SensorData();
                if (Smoothing)
                {
                    Data.qW = qwEMA.NextValue(stateData.OrientationW * 1.0f / 32768);
                    Data.qX = qxEMA.NextValue(stateData.OrientationX * 1.0f / 32768);
                    Data.qY = qyEMA.NextValue(stateData.OrientationY * 1.0f / 32768);
                    Data.qZ = qzEMA.NextValue(stateData.OrientationZ * 1.0f / 32768);

                    Data.gX = (int)gxEMA.NextValue(stateData.AngularVelocityX);
                    Data.gY = (int)gyEMA.NextValue(stateData.AngularVelocityY);
                    Data.gZ = (int)gzEMA.NextValue(stateData.AngularVelocityZ);

                    /*
                     * Data.aX = (int)axEMA.NextValue(stateData.AccelerometerX);
                     * Data.aY = (int)ayEMA.NextValue(stateData.AccelerometerY);
                     * Data.aZ = (int)azEMA.NextValue(stateData.AccelerometerZ);
                     */
                }
                else if (stateData != null)
                {
                    Data.qW = stateData.OrientationW * 1.0f / 32768;
                    Data.qX = stateData.OrientationX * 1.0f / 32768;
                    Data.qY = stateData.OrientationY * 1.0f / 32768;
                    Data.qZ = stateData.OrientationZ * 1.0f / 32768;

                    Data.gX = stateData.AngularVelocityX;
                    Data.gY = stateData.AngularVelocityY;
                    Data.gZ = stateData.AngularVelocityZ;

                    /*
                     * Data.aX = stateData.AccelerometerX;
                     * Data.aY = stateData.AccelerometerY;
                     * Data.aZ = stateData.AccelerometerZ;
                     */
                }

                Data.GyroTiltFactorX = (float)Data.gX * 0.0001f;
                Data.GyroTiltFactorY = (float)Data.gY * 0.0001f;
                Data.GyroTiltFactorZ = (float)Data.gZ * 0.0001f * -90;
                // sensitivity scale factor 4 -> radian/sec
                Data.calGyroX = Data.gX / 16.4f * deg2rad;
                Data.calGyroY = Data.gY / 16.4f * deg2rad;
                Data.calGyroZ = Data.gZ / 16.4f * deg2rad;
                // sensitivity scale factor 0 -> units/g

                /*
                 * Data.calAccelX = Data.aX * 1.0f / 16384;
                 * Data.calAccelY = Data.aY * 1.0f / 16384;
                 * Data.calAccelZ = Data.aZ * 1.0f / 16384;
                 */

                // accumulate smoothed statistical data on normalized gyro sensor magnitude
                Data.NormGyroMag = (float)Math.Sqrt(
                    Math.Abs(Data.calGyroX * Data.calGyroX) +
                    Math.Abs(Data.calGyroY * Data.calGyroY) +
                    Math.Abs(Data.calGyroZ * Data.calGyroZ)
                    );
                normData.NextValue(Data.NormGyroMag);

                double[] eulAnglesYPR = ToEulerAngles(Data.qW, Data.qY, Data.qZ, Data.qX);
                Data.Yaw   = eulAnglesYPR[0] * 2.0f / Math.PI;
                Data.Pitch = eulAnglesYPR[1] * 2.0f / Math.PI;
                Data.Roll  = -(eulAnglesYPR[2] * 2.0f / Math.PI);
                if (double.IsNaN(Data.Yaw))
                {
                    Data.Yaw = 0f;
                }
                if (double.IsNaN(Data.Pitch))
                {
                    Data.Pitch = 0f;
                }
                if (double.IsNaN(Data.Roll))
                {
                    Data.Roll = 0f;
                }

                // auto-calibrate on the fly over several seconds when near idle
                calib.Calibrate(Data.Yaw, Data.Pitch, Data.Roll, Data.NormGyroMag);
                Data.Yaw   += calib.OffsetY;
                Data.Pitch += calib.OffsetP;
                Data.Roll  += calib.OffsetR;

                Data.QuatTiltFactorX = (float)((2 * Math.Abs(Mod((Data.Pitch - 1) * 0.5f, 2) - 1)) - 1);
                Data.QuatTiltFactorY = (float)((2 * Math.Abs(Mod((Data.Roll - 1) * 0.5f, 2) - 1)) - 1);
                Data.QuatTiltFactorZ = (float)(Data.Yaw * -90.0f);

                Interlocked.Exchange(ref usingResource, 0);
            }
            return(Data);
        }
Exemplo n.º 6
0
        public bool GetBasicControl(string inputName)
        {
            if (ActiveController == null)
            {
                return(false);
            }

            inputName = inputName.ToLowerInvariant();

            SteamController.SteamControllerState state = ActiveController.GetState();
            if (state.Buttons == null)
            {
                return(false);
            }

            switch (inputName)
            {
            case "a":
                return(state.Buttons.A);

            case "b":
                return(state.Buttons.B);

            case "x":
                return(state.Buttons.X);

            case "y":
                return(state.Buttons.Y);

            case "leftbumper":
            case "lb":
                return(state.Buttons.LeftBumper);

            case "lefttrigger":
            case "lt":
                return(state.Buttons.LeftTrigger);

            case "rightbumper":
            case "rb":
                return(state.Buttons.RightBumper);

            case "righttrigger":
            case "rt":
                return(state.Buttons.RightTrigger);

            case "leftgrip":
            case "lg":
                return(state.Buttons.LeftGrip);

            case "rightgrip":
            case "rg":
                return(state.Buttons.RightGrip);

            case "start":
                return(state.Buttons.Start);

            case "steam":
                return(state.Buttons.Steam);

            case "select":
                return(state.Buttons.Select);

            case "down":
                return(state.Buttons.Down);

            case "left":
                return(state.Buttons.Left);

            case "right":
                return(state.Buttons.Right);

            case "up":
                return(state.Buttons.Up);

            case "stickclick":
            case "sc":
                return(state.Buttons.StickClick);

            case "leftpadtouch":
            case "lpt":
                return(state.Buttons.LeftPadTouch);

            case "leftpadclick":
            case "lpc":
                return(state.Buttons.LeftPadClick);

            case "rightpadtouch":
            case "rpt":
                return(state.Buttons.RightPadTouch);

            case "rightpadclick":
            case "rpc":
                return(state.Buttons.RightPadClick);

            default:
                return(false);
            }
        }