Пример #1
0
        public void HandleSixaxis(byte[] gyro, byte[] accel, DS4State state)
        {
            int currentX = (short)((ushort)(gyro[0] << 8) | gyro[1]) / 64;
            int currentY = (short)((ushort)(gyro[2] << 8) | gyro[3]) / 64;
            int currentZ = (short)((ushort)(gyro[4] << 8) | gyro[5]) / 64;
            int AccelX = (short)((ushort)(accel[2] << 8) | accel[3]) / 256;
            int AccelY = (short)((ushort)(accel[0] << 8) | accel[1]) / 256;
            int AccelZ = (short)((ushort)(accel[4] << 8) | accel[5]) / 256;

            if ((AccelX == 0) && (AccelY == 0) && (AccelZ == 0))
            {
                return;
            }

            if (SixAccelMoved != null)
            {
                SixAxis sPrev = new SixAxis(lastGyroX, lastGyroY, lastGyroZ, lastAX, lastAY, lastAZ);
                SixAxis now = new SixAxis(currentX, currentY, currentZ, AccelX, AccelY, AccelZ, sPrev);
                SixAxisEventArgs args = new SixAxisEventArgs(state.ReportTimeStamp, now);
                SixAccelMoved(this, args);
            }

            lastGyroX = currentX;
            lastGyroY = currentY;
            lastGyroZ = currentZ;
            lastAX = AccelX;
            lastAY = AccelY;
            lastAZ = AccelZ;
        }
Пример #2
0
        public virtual void sixaxisMoved(SixAxisEventArgs arg)
        {
            int deltaX = -arg.sixAxis.accelX;
            int deltaY = -arg.sixAxis.accelY;
            //Console.WriteLine(arg.sixAxis.deltaX);

            double coefficient = Global.GyroSensitivity[deviceNumber] / 100f;
            //Collect rounding errors instead of losing motion.
            double xMotion = coefficient * deltaX;
            xMotion += hRemainder;
            int xAction = (int)xMotion;
            hRemainder += xMotion - xAction;
            hRemainder -= (int)hRemainder;
            double yMotion = coefficient * deltaY;
            yMotion += vRemainder;
            int yAction = (int)yMotion;
            vRemainder += yMotion - yAction;
            vRemainder -= (int)vRemainder;
            if ((Global.GyroInvert[deviceNumber] == 2) || (Global.GyroInvert[deviceNumber] == 3))
            {
                xAction *= -1;
            }
            if ((Global.GyroInvert[deviceNumber] == 1) || (Global.GyroInvert[deviceNumber] == 3))
            {
                yAction *= -1;
            }
            if ((yAction != 0) || (xAction != 0))
            {
                InputMethods.MoveCursorBy(xAction, yAction);
            }
        }
Пример #3
0
        public virtual void sixaxisMoved(object sender, SixAxisEventArgs arg)
        {
            if (!Global.UseSAforMouse[deviceNum] || (Global.GyroSensitivity[deviceNum] <= 0))
            {
                return;
            }

            bool triggeractivated = true;
            string[] ss = Global.SATriggers[deviceNum].Split(',');
            if (!string.IsNullOrEmpty(ss[0]))
            {
                foreach (string _s in ss)
                {
                    int i;
                    if (!(int.TryParse(_s, out i) && getDS4ControlsByName(i)))
                    {
                        triggeractivated = false;
                    }
                }
            }
            if (triggeractivated)
            {
                cursor.sixaxisMoved(arg);
            }
            dev.GetCurrentState(state);
        }