public ControlService()
        {
            //sp.Stream = Properties.Resources.EE;
            // Cause thread affinity to not be tied to main GUI thread

            /*Task x360task = new Task(() => { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; x360Bus = new X360Device(); });
             * x360task.Start();
             * while (!x360task.IsCompleted)
             *  Thread.SpinWait(500);
             */
            tempThread              = new Thread(() => { x360Bus = new X360Device(); });
            tempThread.Priority     = ThreadPriority.AboveNormal;
            tempThread.IsBackground = true;
            tempThread.Start();
            while (tempThread.IsAlive)
            {
                Thread.SpinWait(500);
            }

            AddtoDS4List();

            for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
            {
                processingData[i] = new X360Data();
                MappedState[i]    = new DS4State();
                CurrentState[i]   = new DS4State();
                PreviousState[i]  = new DS4State();
                ExposedState[i]   = new DS4StateExposed(CurrentState[i]);
            }

            _udpServer = new UdpServer(GetPadDetailForIdx);
        }
Пример #2
0
        public ControlService()
        {
            //sp.Stream = Properties.Resources.EE;
            // Cause thread affinity to not be tied to main GUI thread
            Thread x360Thread = new Thread(() => { x360Bus = new X360Device(); });

            x360Thread.IsBackground = true;
            x360Thread.Priority     = ThreadPriority.Normal;
            x360Thread.Name         = "SCP Virtual Bus Thread";
            x360Thread.Start();
            while (!x360Thread.ThreadState.HasFlag(ThreadState.Stopped))
            {
                Thread.SpinWait(500);
            }

            AddtoDS4List();

            for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
            {
                processingData[i] = new X360Data();
                MappedState[i]    = new DS4State();
                CurrentState[i]   = new DS4State();
                PreviousState[i]  = new DS4State();
                ExposedState[i]   = new DS4StateExposed(CurrentState[i]);
            }
        }
Пример #3
0
 public ControlService()
 {
     sp.Stream = Properties.Resources.EE;
     x360Bus   = new X360Device();
     AddtoDS4List();
     for (int i = 0; i < DS4Controllers.Length; i++)
     {
         processingData[i] = new X360Data();
         MappedState[i]    = new DS4State();
         CurrentState[i]   = new DS4State();
         PreviousState[i]  = new DS4State();
         ExposedState[i]   = new DS4StateExposed(CurrentState[i]);
     }
 }
Пример #4
0
        public ControlService()
        {
            //sp.Stream = Properties.Resources.EE;
            // Cause thread affinity to not be tied to main GUI thread
            tempThread              = new Thread(() => { x360Bus = new X360Device(); });
            tempThread.Priority     = ThreadPriority.AboveNormal;
            tempThread.IsBackground = true;
            tempThread.Start();
            while (tempThread.IsAlive)
            {
                Thread.SpinWait(500);
            }

            for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
            {
                processingData[i] = new X360Data();
                MappedState[i]    = new DS4State();
                CurrentState[i]   = new DS4State();
                TempState[i]      = new DS4State();
                PreviousState[i]  = new DS4State();
                ExposedState[i]   = new DS4StateExposed(CurrentState[i]);
            }
        }
        public DS4Controls GetActiveInputControl(int ind)
        {
            DS4State        cState = CurrentState[ind];
            DS4StateExposed eState = ExposedState[ind];
            Mouse           tp     = touchPad[ind];
            DS4Controls     result = DS4Controls.None;

            if (DS4Controllers[ind] != null)
            {
                if (Mapping.getBoolButtonMapping(cState.Cross))
                {
                    result = DS4Controls.Cross;
                }
                else if (Mapping.getBoolButtonMapping(cState.Circle))
                {
                    result = DS4Controls.Circle;
                }
                else if (Mapping.getBoolButtonMapping(cState.Triangle))
                {
                    result = DS4Controls.Triangle;
                }
                else if (Mapping.getBoolButtonMapping(cState.Square))
                {
                    result = DS4Controls.Square;
                }
                else if (Mapping.getBoolButtonMapping(cState.L1))
                {
                    result = DS4Controls.L1;
                }
                else if (Mapping.getBoolTriggerMapping(cState.L2))
                {
                    result = DS4Controls.L2;
                }
                else if (Mapping.getBoolButtonMapping(cState.L3))
                {
                    result = DS4Controls.L3;
                }
                else if (Mapping.getBoolButtonMapping(cState.R1))
                {
                    result = DS4Controls.R1;
                }
                else if (Mapping.getBoolTriggerMapping(cState.R2))
                {
                    result = DS4Controls.R2;
                }
                else if (Mapping.getBoolButtonMapping(cState.R3))
                {
                    result = DS4Controls.R3;
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadUp))
                {
                    result = DS4Controls.DpadUp;
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadDown))
                {
                    result = DS4Controls.DpadDown;
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadLeft))
                {
                    result = DS4Controls.DpadLeft;
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadRight))
                {
                    result = DS4Controls.DpadRight;
                }
                else if (Mapping.getBoolButtonMapping(cState.Share))
                {
                    result = DS4Controls.Share;
                }
                else if (Mapping.getBoolButtonMapping(cState.Options))
                {
                    result = DS4Controls.Options;
                }
                else if (Mapping.getBoolButtonMapping(cState.PS))
                {
                    result = DS4Controls.PS;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LX, true))
                {
                    result = DS4Controls.LXPos;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LX, false))
                {
                    result = DS4Controls.LXNeg;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LY, true))
                {
                    result = DS4Controls.LYPos;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LY, false))
                {
                    result = DS4Controls.LYNeg;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RX, true))
                {
                    result = DS4Controls.RXPos;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RX, false))
                {
                    result = DS4Controls.RXNeg;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RY, true))
                {
                    result = DS4Controls.RYPos;
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RY, false))
                {
                    result = DS4Controls.RYNeg;
                }
                else if (Mapping.getBoolTouchMapping(tp.leftDown))
                {
                    result = DS4Controls.TouchLeft;
                }
                else if (Mapping.getBoolTouchMapping(tp.rightDown))
                {
                    result = DS4Controls.TouchRight;
                }
                else if (Mapping.getBoolTouchMapping(tp.multiDown))
                {
                    result = DS4Controls.TouchMulti;
                }
                else if (Mapping.getBoolTouchMapping(tp.upperDown))
                {
                    result = DS4Controls.TouchUpper;
                }
            }

            return(result);
        }
Пример #6
0
        public DS4Controls GetInputkeysDS4(int ind)
        {
            DS4State        cState = CurrentState[ind];
            DS4StateExposed eState = ExposedState[ind];
            Mouse           tp     = touchPad[ind];

            if (DS4Controllers[ind] != null)
            {
                if (Mapping.getBoolMapping(ind, DS4Controls.Cross, cState, eState, tp))
                {
                    return(DS4Controls.Cross);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Circle, cState, eState, tp))
                {
                    return(DS4Controls.Circle);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Triangle, cState, eState, tp))
                {
                    return(DS4Controls.Triangle);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Square, cState, eState, tp))
                {
                    return(DS4Controls.Square);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L1, cState, eState, tp))
                {
                    return(DS4Controls.L1);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R1, cState, eState, tp))
                {
                    return(DS4Controls.R1);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L2, cState, eState, tp))
                {
                    return(DS4Controls.L2);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R2, cState, eState, tp))
                {
                    return(DS4Controls.R2);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L3, cState, eState, tp))
                {
                    return(DS4Controls.L3);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R3, cState, eState, tp))
                {
                    return(DS4Controls.R3);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadUp, cState, eState, tp))
                {
                    return(DS4Controls.DpadUp);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadDown, cState, eState, tp))
                {
                    return(DS4Controls.DpadDown);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadLeft, cState, eState, tp))
                {
                    return(DS4Controls.DpadLeft);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadRight, cState, eState, tp))
                {
                    return(DS4Controls.DpadRight);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Share, cState, eState, tp))
                {
                    return(DS4Controls.Share);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Options, cState, eState, tp))
                {
                    return(DS4Controls.Options);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.PS, cState, eState, tp))
                {
                    return(DS4Controls.PS);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LXPos, cState, eState, tp))
                {
                    return(DS4Controls.LXPos);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LXNeg, cState, eState, tp))
                {
                    return(DS4Controls.LXNeg);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LYPos, cState, eState, tp))
                {
                    return(DS4Controls.LYPos);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LYNeg, cState, eState, tp))
                {
                    return(DS4Controls.LYNeg);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RXPos, cState, eState, tp))
                {
                    return(DS4Controls.RXPos);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RXNeg, cState, eState, tp))
                {
                    return(DS4Controls.RXNeg);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RYPos, cState, eState, tp))
                {
                    return(DS4Controls.RYPos);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RYNeg, cState, eState, tp))
                {
                    return(DS4Controls.RYNeg);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchLeft, cState, eState, tp))
                {
                    return(DS4Controls.TouchLeft);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchRight, cState, eState, tp))
                {
                    return(DS4Controls.TouchRight);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchMulti, cState, eState, tp))
                {
                    return(DS4Controls.TouchMulti);
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchUpper, cState, eState, tp))
                {
                    return(DS4Controls.TouchUpper);
                }
            }
            return(DS4Controls.None);
        }
Пример #7
0
        public string GetInputkeys(int ind)
        {
            DS4State        cState = CurrentState[ind];
            DS4StateExposed eState = ExposedState[ind];
            Mouse           tp     = touchPad[ind];

            if (DS4Controllers[ind] != null)
            {
                if (Mapping.getBoolMapping(ind, DS4Controls.Cross, cState, eState, tp))
                {
                    return("Cross");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Circle, cState, eState, tp))
                {
                    return("Circle");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Triangle, cState, eState, tp))
                {
                    return("Triangle");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Square, cState, eState, tp))
                {
                    return("Square");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L1, cState, eState, tp))
                {
                    return("L1");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R1, cState, eState, tp))
                {
                    return("R1");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L2, cState, eState, tp))
                {
                    return("L2");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R2, cState, eState, tp))
                {
                    return("R2");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.L3, cState, eState, tp))
                {
                    return("L3");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.R3, cState, eState, tp))
                {
                    return("R3");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadUp, cState, eState, tp))
                {
                    return("Up");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadDown, cState, eState, tp))
                {
                    return("Down");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadLeft, cState, eState, tp))
                {
                    return("Left");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.DpadRight, cState, eState, tp))
                {
                    return("Right");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Share, cState, eState, tp))
                {
                    return("Share");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.Options, cState, eState, tp))
                {
                    return("Options");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.PS, cState, eState, tp))
                {
                    return("PS");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LXPos, cState, eState, tp))
                {
                    return("LS Right");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LXNeg, cState, eState, tp))
                {
                    return("LS Left");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LYPos, cState, eState, tp))
                {
                    return("LS Down");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.LYNeg, cState, eState, tp))
                {
                    return("LS Up");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RXPos, cState, eState, tp))
                {
                    return("RS Right");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RXNeg, cState, eState, tp))
                {
                    return("RS Left");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RYPos, cState, eState, tp))
                {
                    return("RS Down");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.RYNeg, cState, eState, tp))
                {
                    return("RS Up");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchLeft, cState, eState, tp))
                {
                    return("Touch Left");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchRight, cState, eState, tp))
                {
                    return("Touch Right");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchMulti, cState, eState, tp))
                {
                    return("Touch Multi");
                }
                else if (Mapping.getBoolMapping(ind, DS4Controls.TouchUpper, cState, eState, tp))
                {
                    return("Touch Upper");
                }
            }
            return("nothing");
        }
Пример #8
0
        /* private void DoExtras(int ind)
         * {
         *   DS4State cState = CurrentState[ind];
         *   DS4StateExposed eState = ExposedState[ind];
         *   Mouse tp = touchPad[ind];
         *   DS4Controls helddown = DS4Controls.None;
         *   foreach (KeyValuePair<DS4Controls, string> p in getCustomExtras(ind))
         *   {
         *       if (Mapping.getBoolMapping(ind, p.Key, cState, eState, tp))
         *       {
         *           helddown = p.Key;
         *           break;
         *       }
         *   }
         *   if (helddown != DS4Controls.None)
         *   {
         *       string p = getCustomExtras(ind)[helddown];
         *       string[] extraS = p.Split(',');
         *       int[] extras = new int[extraS.Length];
         *       for (int i = 0; i < extraS.Length; i++)
         *       {
         *           int b;
         *           if (int.TryParse(extraS[i], out b))
         *               extras[i] = b;
         *       }
         *       held[ind] = true;
         *       try
         *       {
         *           if (!(extras[0] == extras[1] && extras[1] == 0))
         *               setRumble((byte)extras[0], (byte)extras[1], ind);
         *           if (extras[2] == 1)
         *           {
         *               DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] };
         *               DS4LightBar.forcedColor[ind] = color;
         *               DS4LightBar.forcedFlash[ind] = (byte)extras[6];
         *               DS4LightBar.forcelight[ind] = true;
         *           }
         *           if (extras[7] == 1)
         *           {
         *               if (oldmouse[ind] == -1)
         *                   oldmouse[ind] = ButtonMouseSensitivity[ind];
         *               ButtonMouseSensitivity[ind] = extras[8];
         *           }
         *       }
         *       catch { }
         *   }
         *   else if (held[ind])
         *   {
         *       DS4LightBar.forcelight[ind] = false;
         *       DS4LightBar.forcedFlash[ind] = 0;
         *       ButtonMouseSensitivity[ind] = oldmouse[ind];
         *       oldmouse[ind] = -1;
         *       setRumble(0, 0, ind);
         *       held[ind] = false;
         *   }
         * }*/



        public void EasterTime(int ind)
        {
            DS4State        cState = CurrentState[ind];
            DS4StateExposed eState = ExposedState[ind];
            Mouse           tp     = touchPad[ind];

            bool pb = false;

            foreach (DS4Controls dc in dcs)
            {
                if (Mapping.getBoolMapping(ind, dc, cState, eState, tp))
                {
                    pb = true;
                    break;
                }
            }
            int temp = eCode;

            //Looks like you found the easter egg code, since you're already cheating,
            //I scrambled the code for you :)
            if (pb && !buttonsdown[ind])
            {
                if (cState.Cross && eCode == 9)
                {
                    eCode++;
                }
                else if (!cState.Cross && eCode == 9)
                {
                    eCode = 0;
                }
                else if (cState.DpadLeft && eCode == 6)
                {
                    eCode++;
                }
                else if (!cState.DpadLeft && eCode == 6)
                {
                    eCode = 0;
                }
                else if (cState.DpadRight && eCode == 7)
                {
                    eCode++;
                }
                else if (!cState.DpadRight && eCode == 7)
                {
                    eCode = 0;
                }
                else if (cState.DpadLeft && eCode == 4)
                {
                    eCode++;
                }
                else if (!cState.DpadLeft && eCode == 4)
                {
                    eCode = 0;
                }
                else if (cState.DpadDown && eCode == 2)
                {
                    eCode++;
                }
                else if (!cState.DpadDown && eCode == 2)
                {
                    eCode = 0;
                }
                else if (cState.DpadRight && eCode == 5)
                {
                    eCode++;
                }
                else if (!cState.DpadRight && eCode == 5)
                {
                    eCode = 0;
                }
                else if (cState.DpadUp && eCode == 1)
                {
                    eCode++;
                }
                else if (!cState.DpadUp && eCode == 1)
                {
                    eCode = 0;
                }
                else if (cState.DpadDown && eCode == 3)
                {
                    eCode++;
                }
                else if (!cState.DpadDown && eCode == 3)
                {
                    eCode = 0;
                }
                else if (cState.Circle && eCode == 8)
                {
                    eCode++;
                }
                else if (!cState.Circle && eCode == 8)
                {
                    eCode = 0;
                }

                if (cState.DpadUp && eCode == 0)
                {
                    eCode++;
                }

                if (eCode == 10)
                {
                    string message = "(!)";
                    sp.Play();
                    LogDebug(message, true);
                    eCode = 0;
                }

                if (temp != eCode)
                {
                    Console.WriteLine(eCode);
                }
                buttonsdown[ind] = true;
            }
            else if (!pb)
            {
                buttonsdown[ind] = false;
            }
        }
Пример #9
0
 public void getExposedState(DS4StateExposed expState, DS4State state)
 {
     cState.CopyTo(state);
     expState.setAccel(accel);
     expState.setGyro(gyro);
 }
Пример #10
0
 public void getExposedState(DS4StateExposed expState, DS4State state)
 {
     cState.CopyTo(state);
     expState.Accel = accel;
     expState.Gyro  = gyro;
 }
Пример #11
0
        private void DoExtras(int ind)
        {
            DS4State        cState   = CurrentState[ind];
            DS4StateExposed eState   = ExposedState[ind];
            Mouse           tp       = touchPad[ind];
            DS4Controls     helddown = DS4Controls.None;

            foreach (KeyValuePair <DS4Controls, string> p in getCustomExtras(ind))
            {
                if (Mapping.getBoolMapping(p.Key, cState, eState, tp))
                {
                    helddown = p.Key;
                    break;
                }
            }
            if (helddown != DS4Controls.None)
            {
                string   p      = getCustomExtras(ind)[helddown];
                string[] extraS = p.Split(',');
                int[]    extras = new int[extraS.Length];
                for (int i = 0; i < extraS.Length; i++)
                {
                    int b;
                    if (int.TryParse(extraS[i], out b))
                    {
                        extras[i] = b;
                    }
                }
                held[ind] = true;
                try
                {
                    if (!(extras[0] == extras[1] && extras[1] == 0))
                    {
                        setRumble((byte)extras[0], (byte)extras[1], ind);
                    }
                    if (extras[2] == 1)
                    {
                        DS4Color color = new DS4Color {
                            red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5]
                        };
                        DS4LightBar.forcedColor[ind] = color;
                        DS4LightBar.forcedFlash[ind] = (byte)extras[6];
                        DS4LightBar.forcelight[ind]  = true;
                    }
                    if (extras[7] == 1)
                    {
                        if (oldmouse[ind] == -1)
                        {
                            oldmouse[ind] = ButtonMouseSensitivity[ind];
                        }
                        ButtonMouseSensitivity[ind] = extras[8];
                    }
                }
                catch { }
            }
            else if (held[ind])
            {
                DS4LightBar.forcelight[ind]  = false;
                DS4LightBar.forcedFlash[ind] = 0;
                ButtonMouseSensitivity[ind]  = oldmouse[ind];
                oldmouse[ind] = -1;
                setRumble(0, 0, ind);
                held[ind] = false;
            }
        }
Пример #12
0
        public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp)
        {
            DS4Color color;

            if (!defualtLight && !forcelight[deviceNum])
            {
                if (UseCustomLed[deviceNum])
                {
                    if (LedAsBatteryIndicator[deviceNum])
                    {
                        DS4Color fullColor = CustomColor[deviceNum];
                        DS4Color lowColor  = LowColor[deviceNum];

                        color = getTransitionedColor(lowColor, fullColor, device.Battery);
                    }
                    else
                    {
                        color = CustomColor[deviceNum];
                    }
                }
                else
                {
                    if (Rainbow[deviceNum] > 0)
                    {                                                      // Display rainbow
                        DateTime now = DateTime.UtcNow;
                        if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
                        {
                            oldnow = now;
                            if (device.Charging)
                            {
                                counters[deviceNum] -= 1.5 * 3 / Rainbow[deviceNum];
                            }
                            else
                            {
                                counters[deviceNum] += 1.5 * 3 / Rainbow[deviceNum];
                            }
                        }
                        if (counters[deviceNum] < 0)
                        {
                            counters[deviceNum] = 180000;
                        }
                        if (counters[deviceNum] > 180000)
                        {
                            counters[deviceNum] = 0;
                        }
                        if (LedAsBatteryIndicator[deviceNum])
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery));
                        }
                        else
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        }
                    }
                    else if (LedAsBatteryIndicator[deviceNum])
                    {
                        //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
                        {
                            DS4Color fullColor = MainColor[deviceNum];
                            DS4Color lowColor  = LowColor[deviceNum];

                            color = getTransitionedColor(lowColor, fullColor, (uint)device.Battery);
                        }
                    }
                    else
                    {
                        color = MainColor[deviceNum];
                    }
                }

                if (device.Battery <= FlashAt[deviceNum] && !defualtLight && !device.Charging)
                {
                    if (!(FlashColor[deviceNum].red == 0 &&
                          FlashColor[deviceNum].green == 0 &&
                          FlashColor[deviceNum].blue == 0))
                    {
                        color = FlashColor[deviceNum];
                    }
                    if (FlashType[deviceNum] == 1)
                    {
                        if (fadetimer[deviceNum] <= 0)
                        {
                            fadedirection[deviceNum] = true;
                        }
                        else if (fadetimer[deviceNum] >= 100)
                        {
                            fadedirection[deviceNum] = false;
                        }
                        if (fadedirection[deviceNum])
                        {
                            fadetimer[deviceNum] += 1;
                        }
                        else
                        {
                            fadetimer[deviceNum] -= 1;
                        }
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
                    }
                }

                if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.Charging || device.Battery >= 100))
                {//Fade lightbar by idle time
                    TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks);
                    double   botratio  = timeratio.TotalMilliseconds;
                    double   topratio  = TimeSpan.FromSeconds(IdleDisconnectTimeout[deviceNum]).TotalMilliseconds;
                    double   ratio     = ((botratio / topratio) * 100);
                    if (ratio >= 50 && ratio <= 100)
                    {
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2));
                    }
                    else if (ratio >= 100)
                    {
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100);
                    }
                }
                if (device.Charging && device.Battery < 100)
                {
                    switch (ChargingType[deviceNum])
                    {
                    case 1:
                        if (fadetimer[deviceNum] <= 0)
                        {
                            fadedirection[deviceNum] = true;
                        }
                        else if (fadetimer[deviceNum] >= 105)
                        {
                            fadedirection[deviceNum] = false;
                        }
                        if (fadedirection[deviceNum])
                        {
                            fadetimer[deviceNum] += .1;
                        }
                        else
                        {
                            fadetimer[deviceNum] -= .1;
                        }
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
                        break;

                    case 2:
                        counters[deviceNum] += .167;
                        color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        break;

                    case 3:
                        color = ChargingColor[deviceNum];
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (forcelight[deviceNum])
            {
                color = forcedColor[deviceNum];
            }
            else if (shuttingdown)
            {
                color = new DS4Color(0, 0, 0);
            }
            else
            {
                if (device.ConnectionType == ConnectionType.BT)
                {
                    color = new DS4Color(32, 64, 64);
                }
                else
                {
                    color = new DS4Color(0, 0, 0);
                }
            }
            bool distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));

            if (distanceprofile && !defualtLight)
            { //Thing I did for Distance
                float rumble = device.LeftHeavySlowRumble / 2.55f;
                byte  max    = Max(color.red, Max(color.green, color.blue));
                if (device.LeftHeavySlowRumble > 100)
                {
                    color = getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble);
                }
                else
                {
                    color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.LeftHeavySlowRumble);
                }
            }
            DS4HapticState haptics = new DS4HapticState
            {
                LightBarColor = color
            };

            if (haptics.IsLightBarSet())
            {
                if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
                    haptics.LightBarExplicitlyOff    = true;
                }
                else if (device.Battery <= FlashAt[deviceNum] && FlashType[deviceNum] == 0 && !defualtLight && !device.Charging)
                {
                    int level = device.Battery / 10;
                    //if (level >= 10)
                    //level = 0; // all values of ~0% or >~100% are rendered the same
                    haptics.LightBarFlashDurationOn  = BatteryIndicatorDurations[level, 0];
                    haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
                }
                else if (distanceprofile && device.LeftHeavySlowRumble > 155) //also part of Distance
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.LeftHeavySlowRumble + 265));
                    haptics.LightBarExplicitlyOff    = true;
                }
                else
                {
                    //haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
                    haptics.LightBarExplicitlyOff    = true;
                }
            }
            else
            {
                haptics.LightBarExplicitlyOff = true;
            }
            if (device.LightBarOnDuration != haptics.LightBarFlashDurationOn && device.LightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
            {
                haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
            }
            if (device.LightBarOnDuration == 1) //helps better reset the color
            {
                System.Threading.Thread.Sleep(5);
            }
            device.pushHapticState(haptics);
        }
Пример #13
0
        public string GetInputkeys(int ind)
        {
            DS4State        cState = CurrentState[ind];
            DS4StateExposed eState = ExposedState[ind];
            Mouse           tp     = touchPad[ind];
            string          result = "nothing";

            if (DS4Controllers[ind] != null)
            {
                if (Mapping.getBoolButtonMapping(cState.Cross))
                {
                    result = "Cross";
                }
                else if (Mapping.getBoolButtonMapping(cState.Circle))
                {
                    result = "Circle";
                }
                else if (Mapping.getBoolButtonMapping(cState.Triangle))
                {
                    result = "Triangle";
                }
                else if (Mapping.getBoolButtonMapping(cState.Square))
                {
                    result = "Square";
                }
                else if (Mapping.getBoolButtonMapping(cState.L1))
                {
                    result = "L1";
                }
                else if (Mapping.getBoolTriggerMapping(cState.L2))
                {
                    result = "L2";
                }
                else if (Mapping.getBoolButtonMapping(cState.L3))
                {
                    result = "L3";
                }
                else if (Mapping.getBoolButtonMapping(cState.R1))
                {
                    result = "R1";
                }
                else if (Mapping.getBoolTriggerMapping(cState.R2))
                {
                    result = "R2";
                }
                else if (Mapping.getBoolButtonMapping(cState.R3))
                {
                    result = "R3";
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadUp))
                {
                    result = "Up";
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadDown))
                {
                    result = "Down";
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadLeft))
                {
                    result = "Left";
                }
                else if (Mapping.getBoolButtonMapping(cState.DpadRight))
                {
                    result = "Right";
                }
                else if (Mapping.getBoolButtonMapping(cState.Share))
                {
                    result = "Share";
                }
                else if (Mapping.getBoolButtonMapping(cState.Options))
                {
                    result = "Options";
                }
                else if (Mapping.getBoolButtonMapping(cState.PS))
                {
                    result = "PS";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LX, true))
                {
                    result = "LS Right";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LX, false))
                {
                    result = "LS Left";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LY, true))
                {
                    result = "LS Down";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.LY, false))
                {
                    result = "LS Up";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RX, true))
                {
                    result = "RS Right";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RX, false))
                {
                    result = "RS Left";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RY, true))
                {
                    result = "RS Down";
                }
                else if (Mapping.getBoolAxisDirMapping(cState.RY, false))
                {
                    result = "RS Up";
                }
                else if (Mapping.getBoolTouchMapping(tp.leftDown))
                {
                    result = "Touch Left";
                }
                else if (Mapping.getBoolTouchMapping(tp.rightDown))
                {
                    result = "Touch Right";
                }
                else if (Mapping.getBoolTouchMapping(tp.multiDown))
                {
                    result = "Touch Multi";
                }
                else if (Mapping.getBoolTouchMapping(tp.upperDown))
                {
                    result = "Touch Upper";
                }
            }

            return(result);
        }
Пример #14
0
        public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState,
                                          DS4StateExposed eState, Mouse tp)
        {
            DS4Color color;

            if (!defaultLight && !forcelight[deviceNum])
            {
                if (getUseCustomLed(deviceNum))
                {
                    if (getLedAsBatteryIndicator(deviceNum))
                    {
                        DS4Color fullColor = getCustomColor(deviceNum);
                        DS4Color lowColor  = getLowColor(deviceNum);
                        color = getTransitionedColor(lowColor, fullColor, device.getBattery());
                    }
                    else
                    {
                        color = getCustomColor(deviceNum);
                    }
                }
                else
                {
                    double rainbow = getRainbow(deviceNum);
                    if (rainbow > 0)
                    {
                        // Display rainbow
                        DateTime now = DateTime.UtcNow;
                        if (now >= oldnow[deviceNum] + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
                        {
                            oldnow[deviceNum] = now;
                            if (device.isCharging())
                            {
                                counters[deviceNum] -= 1.5 * 3 / rainbow;
                            }
                            else
                            {
                                counters[deviceNum] += 1.5 * 3 / rainbow;
                            }
                        }

                        if (counters[deviceNum] < 0)
                        {
                            counters[deviceNum] = 180000;
                        }
                        else if (counters[deviceNum] > 180000)
                        {
                            counters[deviceNum] = 0;
                        }

                        if (getLedAsBatteryIndicator(deviceNum))
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(device.getBattery() * 2.55));
                        }
                        else
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        }
                    }
                    else if (getLedAsBatteryIndicator(deviceNum))
                    {
                        //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
                        {
                            DS4Color fullColor = getMainColor(deviceNum);
                            DS4Color lowColor  = getLowColor(deviceNum);

                            color = getTransitionedColor(lowColor, fullColor, device.getBattery());
                        }
                    }
                    else
                    {
                        color = getMainColor(deviceNum);
                    }
                }

                if (device.getBattery() <= getFlashAt(deviceNum) && !defaultLight && !device.isCharging())
                {
                    DS4Color flashColor = getFlashColor(deviceNum);
                    if (!(flashColor.red == 0 &&
                          flashColor.green == 0 &&
                          flashColor.blue == 0))
                    {
                        color = flashColor;
                    }

                    if (getFlashType(deviceNum) == 1)
                    {
                        double ratio = 0.0;

                        if (!fadewatches[deviceNum].IsRunning)
                        {
                            bool temp = fadedirection[deviceNum];
                            fadedirection[deviceNum] = !temp;
                            fadewatches[deviceNum].Restart();
                            ratio = temp ? 100.0 : 0.0;
                        }
                        else
                        {
                            long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;

                            if (fadedirection[deviceNum])
                            {
                                if (elapsed < PULSE_FLASH_DURATION)
                                {
                                    ratio = 100.0 * (elapsed / (double)PULSE_FLASH_DURATION);
                                }
                                else
                                {
                                    ratio = 100.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                            else
                            {
                                if (elapsed < PULSE_FLASH_DURATION)
                                {
                                    ratio = (0 - 100.0) * (elapsed / (double)PULSE_FLASH_DURATION) + 100.0;
                                }
                                else
                                {
                                    ratio = 0.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                        }

                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio);
                    }
                }

                int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum);
                if (idleDisconnectTimeout > 0 && getLedAsBatteryIndicator(deviceNum) &&
                    (!device.isCharging() || device.getBattery() >= 100))
                {
                    //Fade lightbar by idle time
                    TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks);
                    double   botratio  = timeratio.TotalMilliseconds;
                    double   topratio  = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
                    double   ratio     = 100.0 * (botratio / topratio);
                    if (ratio >= 50.0 && ratio < 100.0)
                    {
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2));
                    }
                    else if (ratio >= 100.0)
                    {
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0);
                    }
                }

                if (device.isCharging() && device.getBattery() < 100)
                {
                    switch (getChargingType(deviceNum))
                    {
                    case 1:
                    {
                        double ratio = 0.0;

                        if (!fadewatches[deviceNum].IsRunning)
                        {
                            bool temp = fadedirection[deviceNum];
                            fadedirection[deviceNum] = !temp;
                            fadewatches[deviceNum].Restart();
                            ratio = temp ? 100.0 : 0.0;
                        }
                        else
                        {
                            long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;

                            if (fadedirection[deviceNum])
                            {
                                if (elapsed < PULSE_CHARGING_DURATION)
                                {
                                    ratio = 100.0 * (elapsed / (double)PULSE_CHARGING_DURATION);
                                }
                                else
                                {
                                    ratio = 100.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                            else
                            {
                                if (elapsed < PULSE_CHARGING_DURATION)
                                {
                                    ratio = (0 - 100.0) * (elapsed / (double)PULSE_CHARGING_DURATION) + 100.0;
                                }
                                else
                                {
                                    ratio = 0.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                        }

                        color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio);
                        break;
                    }

                    case 2:
                    {
                        counters[deviceNum] += 0.167;
                        color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        break;
                    }

                    case 3:
                    {
                        color = getChargingColor(deviceNum);
                        break;
                    }

                    default: break;
                    }
                }
            }
            else if (forcelight[deviceNum])
            {
                color = forcedColor[deviceNum];
            }
            else if (shuttingdown)
            {
                color = new DS4Color(0, 0, 0);
            }
            else
            {
                if (device.getConnectionType() == ConnectionType.BT)
                {
                    color = new DS4Color(32, 64, 64);
                }
                else
                {
                    color = new DS4Color(0, 0, 0);
                }
            }

            bool distanceprofile = DistanceProfiles[deviceNum] || tempprofileDistance[deviceNum];

            //distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));
            if (distanceprofile && !defaultLight)
            {
                // Thing I did for Distance
                float rumble = device.getLeftHeavySlowRumble() / 2.55f;
                byte  max    = Max(color.red, Max(color.green, color.blue));
                if (device.getLeftHeavySlowRumble() > 100)
                {
                    color = getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble);
                }
                else
                {
                    color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble());
                }
            }

            DS4HapticState haptics = new DS4HapticState
            {
                LightBarColor = color
            };

            if (haptics.IsLightBarSet())
            {
                if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
                    haptics.LightBarExplicitlyOff    = true;
                }
                else if (device.getBattery() <= getFlashAt(deviceNum) && getFlashType(deviceNum) == 0 && !defaultLight && !device.isCharging())
                {
                    int level = device.getBattery() / 10;
                    if (level >= 10)
                    {
                        level = 0; // all values of ~0% or >~100% are rendered the same
                    }
                    haptics.LightBarFlashDurationOn  = BatteryIndicatorDurations[level, 0];
                    haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
                }
                else if (distanceprofile && device.getLeftHeavySlowRumble() > 155) //also part of Distance
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.getLeftHeavySlowRumble() + 265));
                    haptics.LightBarExplicitlyOff    = true;
                }
                else
                {
                    //haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
                    haptics.LightBarExplicitlyOff    = true;
                }
            }
            else
            {
                haptics.LightBarExplicitlyOff = true;
            }

            byte tempLightBarOnDuration = device.getLightBarOnDuration();

            if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
            {
                haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
            }

            // Comment out code for now. This condition gets hit too often and bogs down the GUI
            //if (device.LightBarOnDuration == 1) //helps better reset the color
            //    System.Threading.Thread.Sleep(5);

            device.pushHapticState(haptics);
        }
Пример #15
0
        public static bool shiftMod(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp)
        {
            bool shift;

            switch (ShiftModifier[deviceNum])
            {
            case 1: shift = Mapping.getBoolMapping(DS4Controls.Cross, cState, eState, tp); break;

            case 2: shift = Mapping.getBoolMapping(DS4Controls.Circle, cState, eState, tp); break;

            case 3: shift = Mapping.getBoolMapping(DS4Controls.Square, cState, eState, tp); break;

            case 4: shift = Mapping.getBoolMapping(DS4Controls.Triangle, cState, eState, tp); break;

            case 5: shift = Mapping.getBoolMapping(DS4Controls.Options, cState, eState, tp); break;

            case 6: shift = Mapping.getBoolMapping(DS4Controls.Share, cState, eState, tp); break;

            case 7: shift = Mapping.getBoolMapping(DS4Controls.DpadUp, cState, eState, tp); break;

            case 8: shift = Mapping.getBoolMapping(DS4Controls.DpadDown, cState, eState, tp); break;

            case 9: shift = Mapping.getBoolMapping(DS4Controls.DpadLeft, cState, eState, tp); break;

            case 10: shift = Mapping.getBoolMapping(DS4Controls.DpadRight, cState, eState, tp); break;

            case 11: shift = Mapping.getBoolMapping(DS4Controls.PS, cState, eState, tp); break;

            case 12: shift = Mapping.getBoolMapping(DS4Controls.L1, cState, eState, tp); break;

            case 13: shift = Mapping.getBoolMapping(DS4Controls.R1, cState, eState, tp); break;

            case 14: shift = Mapping.getBoolMapping(DS4Controls.L2, cState, eState, tp); break;

            case 15: shift = Mapping.getBoolMapping(DS4Controls.R2, cState, eState, tp); break;

            case 16: shift = Mapping.getBoolMapping(DS4Controls.L3, cState, eState, tp); break;

            case 17: shift = Mapping.getBoolMapping(DS4Controls.R3, cState, eState, tp); break;

            case 18: shift = Mapping.getBoolMapping(DS4Controls.TouchLeft, cState, eState, tp); break;

            case 19: shift = Mapping.getBoolMapping(DS4Controls.TouchUpper, cState, eState, tp); break;

            case 20: shift = Mapping.getBoolMapping(DS4Controls.TouchMulti, cState, eState, tp); break;

            case 21: shift = Mapping.getBoolMapping(DS4Controls.TouchRight, cState, eState, tp); break;

            case 22: shift = Mapping.getBoolMapping(DS4Controls.GyroZNeg, cState, eState, tp); break;

            case 23: shift = Mapping.getBoolMapping(DS4Controls.GyroZPos, cState, eState, tp); break;

            case 24: shift = Mapping.getBoolMapping(DS4Controls.GyroXPos, cState, eState, tp); break;

            case 25: shift = Mapping.getBoolMapping(DS4Controls.GyroXNeg, cState, eState, tp); break;

            case 26: shift = device.getCurrentState().Touch1; break;

            default: shift = false; break;
            }
            return(shift);
        }
Пример #16
0
 public void getExposedState(DS4StateExposed expState, DS4State state)
 {
     cState.CopyTo(state);
     expState.Accel = accel;
     expState.Gyro = gyro;
 }