Beispiel #1
0
 public static DS4Color getTransitionedColor(DS4Color c1, double ratio, DS4Color c2)
 {
     c1.red   = applyRatio(c1.red, c2.red, ratio);
     c1.green = applyRatio(c1.green, c2.green, ratio);
     c1.blue  = applyRatio(c1.blue, c2.blue, ratio);
     return(c1);
 }
Beispiel #2
0
 private void advColorDialog_OnUpdateColor(Color color, EventArgs e)
 {
     if (device < 4)
     {
         DS4Color dcolor = new DS4Color {
             red = color.R, green = color.G, blue = color.B
         };
         DS4LightBar.forcedColor[device] = dcolor;
         DS4LightBar.forcedFlash[device] = 0;
         DS4LightBar.forcelight[device]  = true;
     }
 }
Beispiel #3
0
        public bool Initialize()
        {
            newkey          = Global.Configuration.VarRegistry.GetVariable <DeviceKeys>($"{devicename}_devicekey");
            setRestoreColor = Color.Transparent;
            DS4Devices.findControllers();
            IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();

            if (!devices.Any())
            {
                return(false);
            }

            device    = devices.ElementAt(0);
            initColor = device.LightBarColor;

            if (!isInitialized)
            {
                try
                {
                    device.Report += SendColor;
                    device.Report += UpdateProperties;
                    device.StartUpdate();
                    Global.logger.Info("Initialized Dualshock");
                }
                catch (Exception e)
                {
                    Global.logger.Error("Could not initialize Dualshock" + e);
                    isInitialized = false;
                }
                if (device != null)
                {
                    isInitialized = true;
                    if (Global.Configuration.dualshock_first_time)
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            DualshockInstallInstructions instructions = new DualshockInstallInstructions();
                            instructions.ShowDialog();
                        });
                        Global.Configuration.dualshock_first_time = false;
                        Settings.ConfigManager.Save(Global.Configuration);
                    }
                }
            }

            return(isInitialized);
        }
Beispiel #4
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 Global.getCustomExtras(ind))
            {
                if (Mapping.getBoolMapping(p.Key, cState, eState, tp))
                {
                    helddown = p.Key;
                    break;
                }
            }
            if (helddown != DS4Controls.None)
            {
                string   p      = Global.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] = Global.getButtonMouseSensitivity(ind);
                        }
                        Global.setButtonMouseSensitivity(ind, extras[8]);
                    }
                }
                catch { }
            }
            else if (held[ind])
            {
                DS4LightBar.forcelight[ind]  = false;
                DS4LightBar.forcedFlash[ind] = 0;
                //Console.WriteLine(p.Key + " is done");
                Global.setButtonMouseSensitivity(ind, oldmouse[ind]);
                oldmouse[ind] = -1;
                setRumble(0, 0, ind);
                held[ind] = false;
            }
        }
Beispiel #5
0
 public bool Start(bool showlog = true)
 {
     if (x360Bus.Open() && x360Bus.Start())
     {
         if (showlog)
         {
             LogDebug(Properties.Resources.Starting);
         }
         DS4Devices.isExclusiveMode = Global.getUseExclusiveMode();
         if (showlog)
         {
             LogDebug(Properties.Resources.SearchingController);
             LogDebug(DS4Devices.isExclusiveMode ?  Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
         }
         try
         {
             DS4Devices.findControllers();
             IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
             int ind = 0;
             DS4LightBar.defualtLight = false;
             foreach (DS4Device device in devices)
             {
                 if (showlog)
                 {
                     LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                 }
                 WarnExclusiveModeFailure(device);
                 DS4Controllers[ind] = device;
                 device.Removal     -= DS4Devices.On_Removal;
                 device.Removal     += this.On_DS4Removal;
                 device.Removal     += DS4Devices.On_Removal;
                 touchPad[ind]       = new Mouse(ind, device);
                 DS4Color color = Global.loadColor(ind);
                 device.LightBarColor = color;
                 if (!Global.getDinputOnly(ind))
                 {
                     x360Bus.Plugin(ind);
                 }
                 device.Report += this.On_Report;
                 TouchPadOn(ind, device);
                 string filename = Path.GetFileName(Global.getAProfile(ind));
                 ind++;
                 if (showlog)
                 {
                     if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + filename))
                     {
                         string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", filename.Substring(0, filename.Length - 4));
                         LogDebug(prolog);
                         Log.LogToTray(prolog);
                     }
                     else
                     {
                         LogDebug("Controller " + ind + " is not using a profile");
                         Log.LogToTray("Controller " + ind + " is not using a profile");
                     }
                 }
                 if (ind >= 4) // out of Xinput devices!
                 {
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             LogDebug(e.Message);
             Log.LogToTray(e.Message);
         }
         running = true;
     }
     return(true);
 }
Beispiel #6
0
 private bool ColorsEqual(Color clr, DS4Color ds4clr)
 {
     return(clr.R == ds4clr.red &&
            clr.G == ds4clr.green &&
            clr.B == ds4clr.blue);
 }
Beispiel #7
0
        public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState)
        {
            DS4Color color;

            if (!defualtLight)
            {
                if (Global.getShiftColorOn(deviceNum) && Global.getShiftModifier(deviceNum) > 0 && shiftMod(device, deviceNum, cState, eState))
                {
                    color = Global.loadShiftColor(deviceNum);
                }
                else
                {
                    if (Global.getRainbow(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 / Global.getRainbow(deviceNum);
                            }
                            else
                            {
                                counters[deviceNum] += 1.5 * 3 / Global.getRainbow(deviceNum);
                            }
                        }
                        if (counters[deviceNum] < 0)
                        {
                            counters[deviceNum] = 180000;
                        }
                        if (Global.getLedAsBatteryIndicator(deviceNum))
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery));
                        }
                        else
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        }
                    }
                    else if (Global.getLedAsBatteryIndicator(deviceNum))
                    {
                        //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
                        {
                            DS4Color fullColor = new DS4Color
                            {
                                red   = Global.loadColor(deviceNum).red,
                                green = Global.loadColor(deviceNum).green,
                                blue  = Global.loadColor(deviceNum).blue
                            };

                            color = Global.loadLowColor(deviceNum);
                            DS4Color lowColor = new DS4Color
                            {
                                red   = color.red,
                                green = color.green,
                                blue  = color.blue
                            };

                            color = Global.getTransitionedColor(lowColor, fullColor, (uint)device.Battery);
                        }
                    }
                    else
                    {
                        color = Global.loadColor(deviceNum);
                    }


                    if (device.Battery <= Global.getFlashAt(deviceNum) && !defualtLight && !device.Charging)
                    {
                        if (!(Global.loadFlashColor(deviceNum).red == 0 &&
                              Global.loadFlashColor(deviceNum).green == 0 &&
                              Global.loadFlashColor(deviceNum).blue == 0))
                        {
                            color = Global.loadFlashColor(deviceNum);
                        }
                    }

                    if (Global.getIdleDisconnectTimeout(deviceNum) > 0 && Global.getLedAsBatteryIndicator(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(Global.getIdleDisconnectTimeout(deviceNum)).TotalMilliseconds;
                        double   ratio     = ((botratio / topratio) * 100);
                        if (ratio >= 50 && ratio <= 100)
                        {
                            color = Global.getTransitionedColor(color, new DS4Color {
                                red = 0, green = 0, blue = 0
                            }, (uint)((ratio - 50) * 2));
                        }
                        else if (ratio >= 100)
                        {
                            color = Global.getTransitionedColor(color, new DS4Color {
                                red = 0, green = 0, blue = 0
                            }, 100);
                        }
                    }
                    if (device.Charging && device.Battery < 100)
                    {
                        switch (Global.getChargingType(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 DS4Color {
                                red = 0, green = 0, blue = 0
                            }, fadetimer[deviceNum]);
                            break;

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

                        case 3:
                            color = Global.loadChargingColor(deviceNum);
                            break;

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

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

            if (haptics.IsLightBarSet())
            {
                if (device.Battery <= Global.getFlashAt(deviceNum) && !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);
        }