Exemple #1
0
 public string getShortEAll4ControllerInfo(int index)
 {
     if (controllers[index] != null)
     {
         IEAll4Device d = controllers[index];
         String       battery;
         if (!d.IsAlive())
         {
             battery = "...";
         }
         if (d.Charging)
         {
             if (d.Battery >= 100)
             {
                 battery = Properties.Resources.Full;
             }
             else
             {
                 battery = d.Battery + "%+";
             }
         }
         else
         {
             battery = d.Battery + "%";
         }
         return(d.ConnectionType + " " + battery);
     }
     else
     {
         return(Properties.Resources.NoneText);
     }
 }
Exemple #2
0
        public void TimeoutConnection(IEAll4Device d)
        {
            try
            {
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                while (!d.IsAlive())
                {
                    if (sw.ElapsedMilliseconds < 1000)
                    {
                        System.Threading.Thread.SpinWait(500);
                    }
                    //If weve been waiting less than 1 second let the thread keep its processing chunk
                    else
                    {
                        System.Threading.Thread.Sleep(500);
                    }
                    //If weve been waiting more than 1 second give up some resources

                    if (sw.ElapsedMilliseconds > 5000)
                    {
                        throw new TimeoutException();                                //Weve waited long enough
                    }
                }
                sw.Reset();
            }
            catch (TimeoutException)
            {
                Stop(false);
                Start(false);
            }
        }
Exemple #3
0
 public Mouse(int deviceID, IEAll4Device d)
 {
     deviceNum = deviceID;
     dev       = d;
     cursor    = new MouseCursor(deviceNum);
     wheel     = new MouseWheel(deviceNum);
 }
 //returns EAll4 controllers that were found and are running
 public static IEnumerable <IEAll4Device> getEAll4Controllers()
 {
     lock (Devices)
     {
         IEAll4Device[] controllers = new IEAll4Device[Devices.Count];
         Devices.Values.CopyTo(controllers, 0);
         return(controllers);
     }
 }
Exemple #5
0
 //called when devices is diconnected, timed out or has input reading failure
 public static void On_Removal(object sender, EventArgs e)
 {
     lock (Devices)
     {
         IEAll4Device ieAll4Device = (IEAll4Device)sender;
         ieAll4Device.HidDevice.CloseDevice();
         Devices.Remove(ieAll4Device.MacAddress);
         DevicePaths.Remove(ieAll4Device.HidDevice.DevicePath);
     }
 }
Exemple #6
0
        private async void WarnExclusiveModeFailure(IEAll4Device ieAll4Device)
        {
            if (EAll4Devices.isExclusiveMode && !ieAll4Device.IsExclusive)
            {
                await System.Threading.Tasks.Task.Delay(5);

                String message = Properties.Resources.CouldNotOpenEAll4.Replace("*Mac address*", ieAll4Device.MacAddress) + " WarnExclusiveModeFailure " + Properties.Resources.QuitOtherPrograms;
                LogDebug(message, true);
                Log.LogToTray(message);
            }
        }
 //allows to get EAll4Device by specifying unique MAC address
 //format for MAC address is XX:XX:XX:XX:XX:XX
 public static IEAll4Device getEAll4Controller(string mac)
 {
     lock (Devices)
     {
         IEAll4Device ieAll4Device = null;
         try
         {
             Devices.TryGetValue(mac, out ieAll4Device);
         }
         catch (ArgumentNullException) { }
         return(ieAll4Device);
     }
 }
 //enumerates eall4 controllers in the system
 public static void findControllers()
 {
     lock (Devices)
     {
         var typeOfInterface = typeof(IEAll4Device);
         var types           = AppDomain.CurrentDomain.GetAssemblies()
                               .SelectMany(s => s.GetTypes())
                               .Where(p => typeOfInterface.IsAssignableFrom(p) && !p.IsInterface);//.Select(p => (IEAll4Device)p).ToList();
         var hDevices = new List <HidDevice>();
         foreach (var type in types)
         {
             //Detect DS4 Controllers
             IEAll4Device helper = (IEAll4Device)Activator.CreateInstance(type);
             int[]        pids   = helper.PIDs;
             int[]        vids   = helper.VIDs;
             foreach (var vid in vids)
             {
                 var devices = HidDevices.Enumerate(vid, pids).ToList();
                 // Sort Bluetooth first in case USB is also connected on the same controller.
                 hDevices = devices.OrderBy(d => ConnectionType(d, helper)).ToList();
                 foreach (var hDevice in hDevices.Where(hDevice => !DevicePaths.Contains(hDevice.DevicePath)))
                 {
                     if (!hDevice.IsOpen)
                     {
                         hDevice.OpenDevice(isExclusiveMode);
                         // TODO in exclusive mode, try to hold both open when both are connected
                         if (isExclusiveMode && !hDevice.IsOpen)
                         {
                             hDevice.OpenDevice(false);
                         }
                     }
                     if (!hDevice.IsOpen)
                     {
                         continue;
                     }
                     if (Devices.ContainsKey(hDevice.readSerial()))
                     {
                         continue; // happens when the BT endpoint already is open and the USB is plugged into the same host
                     }
                     IEAll4Device controller = (IEAll4Device)Activator.CreateInstance(type);
                     controller.Load(hDevice);
                     controller.Removal += On_Removal;
                     Devices.Add(controller.MacAddress, controller);
                     DevicePaths.Add(hDevice.DevicePath);
                     controller.StartUpdate();
                 }
             }
         }
     }
 }
Exemple #9
0
 public void TouchPadOn(int ind, IEAll4Device ieAll4Device)
 {
     if (ieAll4Device.Touchpad != null)
     {
         ITouchpadBehaviour tPad = touchPad[ind];
         ieAll4Device.Touchpad.TouchButtonDown += tPad.touchButtonDown;
         ieAll4Device.Touchpad.TouchButtonUp   += tPad.touchButtonUp;
         ieAll4Device.Touchpad.TouchesBegan    += tPad.touchesBegan;
         ieAll4Device.Touchpad.TouchesMoved    += tPad.touchesMoved;
         ieAll4Device.Touchpad.TouchesEnded    += tPad.touchesEnded;
         ieAll4Device.Touchpad.TouchUnchanged  += tPad.touchUnchanged;
         //LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
         //Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
     }
     Global.ControllerStatusChanged(this);
 }
Exemple #10
0
 public string getEAll4ControllerInfo(int index)
 {
     if (controllers[index] != null)
     {
         IEAll4Device d = controllers[index];
         if (!d.IsAlive())
         //return "Connecting..."; // awaiting the first battery charge indication
         {
             var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d));
             TimeoutThread.IsBackground = true;
             TimeoutThread.Name         = "TimeoutFor" + d.MacAddress.ToString();
             TimeoutThread.Start();
             return(Properties.Resources.Connecting);
         }
         String battery;
         if (d.Charging)
         {
             if (d.Battery >= 100)
             {
                 battery = Properties.Resources.Charged;
             }
             else
             {
                 battery = Properties.Resources.Charging.Replace("*number*", d.Battery.ToString());
             }
         }
         else
         {
             battery = Properties.Resources.Battery.Replace("*number*", d.Battery.ToString());
         }
         return(d.MacAddress + " (" + d.ConnectionType + "), " + battery);
         //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
     }
     else
     {
         return(String.Empty);
     }
 }
Exemple #11
0
 private static ConnectionType ConnectionType(HidDevice d, IEAll4Device helper)
 {
     return(d.Capabilities.InputReportByteLength == helper.InputReportByteLengthUSB ? EAll4Windows.ConnectionType.USB : EAll4Windows.ConnectionType.BT);
 }
Exemple #12
0
        public static void updateLightBar(IEAll4Device ieAll4Device, int deviceNum, ControllerState cState, EAll4StateExposed eState, Mouse tp)
        {
            EAll4Color color;

            if (!defaultLight && !forcelight[deviceNum])
            {
                if (Global.ShiftColorOn[deviceNum] && Global.ShiftModifier[deviceNum] > 0 && shiftMod(ieAll4Device, deviceNum, cState, eState, tp))
                {
                    color = Global.ShiftColor[deviceNum];
                }
                else
                {
                    if (Global.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 (ieAll4Device.Charging)
                            {
                                counters[deviceNum] -= 1.5 * 3 / Global.Rainbow[deviceNum];
                            }
                            else
                            {
                                counters[deviceNum] += 1.5 * 3 / Global.Rainbow[deviceNum];
                            }
                        }
                        if (counters[deviceNum] < 0)
                        {
                            counters[deviceNum] = 180000;
                        }
                        if (counters[deviceNum] > 180000)
                        {
                            counters[deviceNum] = 0;
                        }
                        if (Global.LedAsBatteryIndicator[deviceNum])
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * ieAll4Device.Battery));
                        }
                        else
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        }
                    }
                    else if (Global.LedAsBatteryIndicator[deviceNum])
                    {
                        //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
                        {
                            EAll4Color fullColor = Global.MainColor[deviceNum];
                            EAll4Color lowColor  = Global.LowColor[deviceNum];

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


                    if (ieAll4Device.Battery <= Global.FlashAt[deviceNum] && !defaultLight && !ieAll4Device.Charging)
                    {
                        if (!(Global.FlashColor[deviceNum].Red == 0 &&
                              Global.FlashColor[deviceNum].Green == 0 &&
                              Global.FlashColor[deviceNum].Blue == 0))
                        {
                            color = Global.FlashColor[deviceNum];
                        }
                        if (Global.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 = Global.getTransitionedColor(color, new EAll4Color(0, 0, 0), fadetimer[deviceNum]);
                        }
                    }

                    if (Global.IdleDisconnectTimeout[deviceNum] > 0 && Global.LedAsBatteryIndicator[deviceNum] && (!ieAll4Device.Charging || ieAll4Device.Battery >= 100))
                    {//Fade lightbar by idle time
                        TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - ieAll4Device.lastActive.Ticks);
                        double   botratio  = timeratio.TotalMilliseconds;
                        double   topratio  = TimeSpan.FromSeconds(Global.IdleDisconnectTimeout[deviceNum]).TotalMilliseconds;
                        double   ratio     = ((botratio / topratio) * 100);
                        if (ratio >= 50 && ratio <= 100)
                        {
                            color = Global.getTransitionedColor(color, new EAll4Color(0, 0, 0), (uint)((ratio - 50) * 2));
                        }
                        else if (ratio >= 100)
                        {
                            color = Global.getTransitionedColor(color, new EAll4Color(0, 0, 0), 100);
                        }
                    }
                    if (ieAll4Device.Charging && ieAll4Device.Battery < 100)
                    {
                        switch (Global.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 = Global.getTransitionedColor(color, new EAll4Color(0, 0, 0), fadetimer[deviceNum]);
                            break;

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

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

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

            if (distanceprofile && !defaultLight)
            { //Thing I did for Distance
                float rumble = ieAll4Device.LeftHeavySlowRumble / 2.55f;
                byte  max    = Math.Max(color.Red, Math.Max(color.Green, color.Blue));
                if (ieAll4Device.LeftHeavySlowRumble > 100)
                {
                    color = Global.getTransitionedColor(new EAll4Color(max, max, 0), new EAll4Color(255, 0, 0), rumble);
                }
                else
                {
                    color = Global.getTransitionedColor(color, Global.getTransitionedColor(new EAll4Color(max, max, 0), new EAll4Color(255, 0, 0), 39.6078f), ieAll4Device.LeftHeavySlowRumble);
                }
            }
            EAll4HapticState haptics = new EAll4HapticState
            {
                LightBarColor = color
            };

            if (haptics.IsLightBarSet())
            {
                if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
                    haptics.LightBarExplicitlyOff    = true;
                }
                else if (ieAll4Device.Battery <= Global.FlashAt[deviceNum] && Global.FlashType[deviceNum] == 0 && !defaultLight && !ieAll4Device.Charging)
                {
                    int level = ieAll4Device.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 && ieAll4Device.LeftHeavySlowRumble > 155) //also part of Distance
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-ieAll4Device.LeftHeavySlowRumble + 265));
                    haptics.LightBarExplicitlyOff    = true;
                }
                else
                {
                    //haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
                    haptics.LightBarExplicitlyOff    = true;
                }
            }
            else
            {
                haptics.LightBarExplicitlyOff = true;
            }
            if (ieAll4Device.LightBarOnDuration != haptics.LightBarFlashDurationOn && ieAll4Device.LightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
            {
                haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
            }
            if (ieAll4Device.LightBarOnDuration == 1) //helps better reset the color
            {
                System.Threading.Thread.Sleep(5);
            }
            ieAll4Device.pushHapticState(haptics);
        }
Exemple #13
0
        public static bool shiftMod(IEAll4Device ieAll4Device, int deviceNum, ControllerState cState, EAll4StateExposed eState, Mouse tp)
        {
            bool shift;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            default: shift = false; break;
            }
            return(shift);
        }