コード例 #1
0
        public string getShortDS4ControllerInfo(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                string battery;
                if (!d.IsAlive())
                {
                    battery = "...";
                }

                if (d.isCharging())
                {
                    if (d.getBattery() >= 100)
                    {
                        battery = Properties.Resources.Full;
                    }
                    else
                    {
                        battery = d.getBattery() + "%+";
                    }
                }
                else
                {
                    battery = d.getBattery() + "%";
                }

                return(d.getConnectionType() + " " + battery);
            }
            else
            {
                return(Properties.Resources.NoneText);
            }
        }
コード例 #2
0
        public string getDS4Status(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                return(d.getConnectionType() + "");
            }
            else
            {
                return(Properties.Resources.NoneText);
            }
        }
コード例 #3
0
        public string getDS4ControllerInfo(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                if (!d.IsAlive())
                {
                    return(Properties.Resources.Connecting);
                }

                string battery;
                if (d.isCharging())
                {
                    if (d.getBattery() >= 100)
                    {
                        battery = Properties.Resources.Charged;
                    }
                    else
                    {
                        battery = Properties.Resources.Charging.Replace("*number*", d.getBattery().ToString());
                    }
                }
                else
                {
                    battery = Properties.Resources.Battery.Replace("*number*", d.getBattery().ToString());
                }

                return(d.getMacAddress() + " (" + d.getConnectionType() + "), " + battery);
                //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
            }
            else
            {
                return(string.Empty);
            }
        }
コード例 #4
0
        //Called when DS4 is disconnected or timed out
        protected virtual void On_DS4Removal(object sender, EventArgs e)
        {
            DS4Device device = (DS4Device)sender;
            int       ind    = -1;

            for (int i = 0, arlength = DS4Controllers.Length; ind == -1 && i < arlength; i++)
            {
                if (DS4Controllers[i] != null && device.getMacAddress() == DS4Controllers[i].getMacAddress())
                {
                    ind = i;
                }
            }

            if (ind != -1)
            {
                bool removingStatus = false;
                lock (device.removeLocker)
                {
                    if (!device.IsRemoving)
                    {
                        removingStatus    = true;
                        device.IsRemoving = true;
                    }
                }

                if (removingStatus)
                {
                    CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
                    if (!useDInputOnly[ind])
                    {
                        bool unplugResult = x360Bus.Unplug(ind);
                        int  xinputIndex  = x360Bus.FirstController + ind;
                        if (unplugResult)
                        {
                            LogDebug("X360 Controller # " + xinputIndex + " unplugged");
                        }
                        else
                        {
                            LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
                        }
                    }

                    string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
                    if (device.getBattery() <= 20 &&
                        device.getConnectionType() == ConnectionType.BT && !device.isCharging())
                    {
                        removed += ". " + Properties.Resources.ChargeController;
                    }

                    LogDebug(removed);
                    Log.LogToTray(removed);

                    /*Stopwatch sw = new Stopwatch();
                     * sw.Start();
                     * while (sw.ElapsedMilliseconds < XINPUT_UNPLUG_SETTLE_TIME)
                     * {
                     *  // Use SpinWait to keep control of current thread. Using Sleep could potentially
                     *  // cause other events to get run out of order
                     *  System.Threading.Thread.SpinWait(500);
                     * }
                     * sw.Stop();
                     */

                    device.IsRemoved    = true;
                    device.Synced       = false;
                    DS4Controllers[ind] = null;
                    touchPad[ind]       = null;
                    lag[ind]            = false;
                    inWarnMonitor[ind]  = false;
                    useDInputOnly[ind]  = true;
                    System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
                    OnControllerRemoved(this, ind);
                }
            }
        }
コード例 #5
0
        public bool HotPlug(SynchronizationContext uiContext)
        {
            if (running)
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                //foreach (DS4Device device in devices)
                for (int i = 0, devlen = devices.Count(); i < devlen; i++)
                {
                    DS4Device device = devices.ElementAt(i);

                    if (device.isDisconnectingStatus())
                    {
                        continue;
                    }

                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++)
                        {
                            if (DS4Controllers[Index] != null &&
                                DS4Controllers[Index].getMacAddress() == device.getMacAddress())
                            {
                                return(true);
                            }
                        }

                        return(false);
                    })())
                    {
                        continue;
                    }

                    for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++)
                    {
                        if (DS4Controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
                            Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
                            task.Start();
                            DS4Controllers[Index] = device;
                            device.setUiContext(uiContext);
                            device.Removal      += this.On_DS4Removal;
                            device.Removal      += DS4Devices.On_Removal;
                            device.SyncChange   += this.On_SyncChange;
                            device.SyncChange   += DS4Devices.UpdateSerial;
                            device.SerialChange += this.On_SerialChange;
                            touchPad[Index]      = new Mouse(Index, device);
                            device.LightBarColor = getMainColor(Index);
                            device.Report       += this.On_Report;
                            if (!getDInputOnly(Index) && device.isSynced())
                            {
                                int xinputIndex = x360Bus.FirstController + Index;
                                LogDebug("Plugging in X360 Controller #" + xinputIndex);
                                bool xinputResult = x360Bus.Plugin(Index);
                                if (xinputResult)
                                {
                                    LogDebug("X360 Controller # " + xinputIndex + " connected");
                                    useDInputOnly[Index] = false;
                                }
                                else
                                {
                                    LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
                                    useDInputOnly[Index] = true;
                                }
                            }

                            TouchPadOn(Index, device);
                            CheckProfileOptions(Index, device);
                            device.StartUpdate();

                            //string filename = Path.GetFileName(ProfilePath[Index]);
                            if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]);
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString());
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }

                            break;
                        }
                    }
                }
            }

            return(true);
        }
コード例 #6
0
        public bool Stop(bool showlog = true)
        {
            if (running)
            {
                running    = false;
                runHotPlug = false;

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppingX360);
                }

                bool anyUnplugged = false;
                for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
                {
                    DS4Device tempDevice = DS4Controllers[i];
                    if (tempDevice != null)
                    {
                        if (DCBTatStop && !tempDevice.isCharging())
                        {
                            if (tempDevice.getConnectionType() == ConnectionType.BT)
                            {
                                tempDevice.StopUpdate();
                                tempDevice.DisconnectBT(true);
                            }
                            else if (tempDevice.getConnectionType() == ConnectionType.SONYWA)
                            {
                                tempDevice.StopUpdate();
                                tempDevice.DisconnectDongle(true);
                            }
                        }
                        else
                        {
                            DS4LightBar.forcelight[i]  = false;
                            DS4LightBar.forcedFlash[i] = 0;
                            DS4LightBar.defaultLight   = true;
                            DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i],
                                                       ExposedState[i], touchPad[i]);
                            tempDevice.IsRemoved = true;
                            Thread.Sleep(50);
                        }

                        CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
                        x360Bus.Unplug(i);
                        useDInputOnly[i]  = true;
                        anyUnplugged      = true;
                        DS4Controllers[i] = null;
                        touchPad[i]       = null;
                        lag[i]            = false;
                        inWarnMonitor[i]  = false;
                    }
                }

                if (anyUnplugged)
                {
                    Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
                }

                x360Bus.UnplugAll();
                x360Bus.Stop();

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppingDS4);
                }

                DS4Devices.stopControllers();

                if (_udpServer != null)
                {
                    _udpServer.Stop();
                }

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppedDS4Windows);
                }
            }

            runHotPlug = false;
            return(true);
        }
コード例 #7
0
        public bool Start(object tempui, bool showlog = true)
        {
            if (x360Bus.Open() && x360Bus.Start())
            {
                if (showlog)
                {
                    LogDebug(Properties.Resources.Starting);
                }

                LogDebug("Connection to Scp Virtual Bus established");

                DS4Devices.isExclusiveMode = 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.defaultLight = false;
                    //foreach (DS4Device device in devices)

                    for (int i = 0, devCount = devices.Count(); i < devCount; i++)
                    {
                        DS4Device device = devices.ElementAt(i);
                        if (showlog)
                        {
                            LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
                        }

                        Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
                        task.Start();

                        DS4Controllers[i] = device;
                        device.setUiContext(tempui as SynchronizationContext);
                        device.Removal      += this.On_DS4Removal;
                        device.Removal      += DS4Devices.On_Removal;
                        device.SyncChange   += this.On_SyncChange;
                        device.SyncChange   += DS4Devices.UpdateSerial;
                        device.SerialChange += this.On_SerialChange;
                        touchPad[i]          = new Mouse(i, device);
                        device.LightBarColor = getMainColor(i);

                        if (!getDInputOnly(i) && device.isSynced())
                        {
                            int xinputIndex = x360Bus.FirstController + i;
                            LogDebug("Plugging in X360 Controller #" + xinputIndex);
                            bool xinputResult = x360Bus.Plugin(i);
                            if (xinputResult)
                            {
                                LogDebug("X360 Controller # " + xinputIndex + " connected");
                                useDInputOnly[i] = false;
                            }
                            else
                            {
                                LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
                                useDInputOnly[i] = true;
                            }
                        }

                        device.Report += this.On_Report;
                        TouchPadOn(i, device);
                        CheckProfileOptions(i, device, true);
                        device.StartUpdate();
                        //string filename = ProfilePath[ind];
                        //ind++;
                        if (showlog)
                        {
                            if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml"))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]);
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (i + 1).ToString());
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                        }

                        if (i >= 4) // out of Xinput devices!
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.Message);
                    Log.LogToTray(e.Message);
                }

                running = true;

                if (_udpServer != null)
                {
                    var UDP_SERVER_PORT = 26760;

                    try
                    {
                        _udpServer.Start(UDP_SERVER_PORT);
                        LogDebug("UDP server listening on port " + UDP_SERVER_PORT);
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode);

                        LogDebug(errMsg, true);
                        Log.LogToTray(errMsg, true, true);
                    }
                }
            }
            else
            {
                string logMessage = "Could not connect to Scp Virtual Bus Driver. Please check the status of the System device in Device Manager";
                LogDebug(logMessage);
                Log.LogToTray(logMessage);
            }

            runHotPlug = true;
            return(true);
        }
コード例 #8
0
ファイル: ControlService.cs プロジェクト: kevinypw/DS4Windows
        public bool Start(object tempui, bool showlog = true)
        {
            if (x360Bus.Open() && x360Bus.Start())
            {
                if (showlog)
                {
                    LogDebug(Properties.Resources.Starting);
                }

                LogDebug("Connection to Scp Virtual Bus established");

                DS4Devices.isExclusiveMode = 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.defaultLight = false;
                    //foreach (DS4Device device in devices)

                    for (int i = 0, devCount = devices.Count(); i < devCount; i++)
                    {
                        DS4Device device = devices.ElementAt(i);
                        if (showlog)
                        {
                            LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
                        }

                        Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
                        task.Start();

                        DS4Controllers[i] = device;
                        device.setUiContext(tempui as SynchronizationContext);
                        device.Removal      += this.On_DS4Removal;
                        device.Removal      += DS4Devices.On_Removal;
                        device.SyncChange   += this.On_SyncChange;
                        device.SyncChange   += DS4Devices.UpdateSerial;
                        device.SerialChange += this.On_SerialChange;
                        if (device.isValidSerial() && containsLinkedProfile(device.getMacAddress()))
                        {
                            ProfilePath[i] = getLinkedProfile(device.getMacAddress());
                        }
                        else
                        {
                            ProfilePath[i] = OlderProfilePath[i];
                        }
                        LoadProfile(i, false, this, false, false);
                        touchPad[i]          = new Mouse(i, device);
                        device.LightBarColor = getMainColor(i);

                        if (!getDInputOnly(i) && device.isSynced())
                        {
                            int xinputIndex = x360Bus.FirstController + i;
                            LogDebug("Plugging in X360 Controller #" + xinputIndex);
                            bool xinputResult = x360Bus.Plugin(i);
                            if (xinputResult)
                            {
                                useDInputOnly[i] = false;
                                LogDebug("X360 Controller # " + xinputIndex + " connected");
                            }
                            else
                            {
                                useDInputOnly[i] = true;
                                LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
                            }
                        }

                        int tempIdx = i;
                        device.Report += (sender, e) =>
                        {
                            this.On_Report(sender, e, tempIdx);
                        };
                        TouchPadOn(i, device);
                        CheckProfileOptions(i, device, true);
                        device.StartUpdate();
                        //string filename = ProfilePath[ind];
                        //ind++;
                        if (showlog)
                        {
                            if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml"))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]);
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (i + 1).ToString());
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                        }

                        if (i >= 4) // out of Xinput devices!
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.Message);
                    Log.LogToTray(e.Message);
                }

                running = true;
            }
            else
            {
                string logMessage = "Could not connect to Scp Virtual Bus Driver. Please check the status of the System device in Device Manager";
                LogDebug(logMessage);
                Log.LogToTray(logMessage);
            }

            runHotPlug = true;
            return(true);
        }
コード例 #9
0
ファイル: DS4LightBar.cs プロジェクト: ras-silent/DS4Windows
        public static void updateLightBar(DS4Device device, int deviceNum)
        {
            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))
                    {
                        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)
                                {
                                    elapsed = elapsed / 40;
                                    ratio   = 100.0 * (elapsed / PULSE_FLASH_SEGMENTS);
                                }
                                else
                                {
                                    ratio = 100.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                            else
                            {
                                if (elapsed < PULSE_FLASH_DURATION)
                                {
                                    elapsed = elapsed / 40;
                                    ratio   = (0 - 100.0) * (elapsed / PULSE_FLASH_SEGMENTS) + 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), elapsed = ratio;
                    if (ratio >= 50.0 && ratio < 100.0)
                    {
                        color = getTransitionedColor(color, new DS4Color(0, 0, 0),
                                                     (uint)(-100.0 * (elapsed = 0.02 * (ratio - 50.0)) * (elapsed - 2.0)));
                    }
                    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)
                                {
                                    elapsed = elapsed / 40;
                                    ratio   = 100.0 * (elapsed / PULSE_CHARGING_SEGMENTS);
                                }
                                else
                                {
                                    ratio = 100.0;
                                    fadewatches[deviceNum].Stop();
                                }
                            }
                            else
                            {
                                if (elapsed < PULSE_CHARGING_DURATION)
                                {
                                    elapsed = elapsed / 40;
                                    ratio   = (0 - 100.0) * (elapsed / PULSE_CHARGING_SEGMENTS) + 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;
            }

            device.pushHapticState(ref haptics);
        }