Skip to content

Commit

Permalink
Merge pull request nefarius#615 from chrizonix/master
Browse files Browse the repository at this point in the history
Added custom color support for battery status (DS4).
  • Loading branch information
nefarius authored Jun 11, 2017
2 parents 28d344c + 07ddcc7 commit cc8f383
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 50 deletions.
49 changes: 47 additions & 2 deletions ScpControl/Bluetooth/Ds4/BthDs4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ private void SetLightBarColor(DsPadId value)
m_Queued = 1;
}

private void SetLightBarColorUInt(uint value)
{
System.Drawing.Color color = System.Drawing.Color.FromArgb((int) value);
double brightness = (double) GlobalConfiguration.Instance.Brightness / (double) 255;

if (GlobalConfiguration.Instance.IsLightBarDisabled)
{
_hidReport[R] = _hidReport[G] = _hidReport[B] = _hidReport[12] = _hidReport[13] = 0x00;
}
else
{
_hidReport[R] = (byte)(color.R * brightness);
_hidReport[G] = (byte)(color.G * brightness);
_hidReport[B] = (byte)(color.B * brightness);
}

m_Queued = 1;
}

#endregion

#region Public methods
Expand Down Expand Up @@ -277,7 +296,7 @@ protected override void Process(DateTime now)

if (!GlobalConfiguration.Instance.IsLightBarDisabled)
{
if (Battery < DsBattery.Medium)
if (Battery == DsBattery.Dying)
{
if (!_flash)
{
Expand All @@ -304,7 +323,33 @@ protected override void Process(DateTime now)
_brightness = GlobalConfiguration.Instance.Brightness;
}

if (XInputSlot.HasValue)
if (GlobalConfiguration.Instance.Ds4ShowBatteryInfo)
{
switch (Battery)
{
case DsBattery.Dying:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorDying);
break;
case DsBattery.Low:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorLow);
break;
case DsBattery.Medium:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorMedium);
break;
case DsBattery.High:
case DsBattery.Charging:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorHigh);
break;
case DsBattery.Full:
case DsBattery.Charged:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorFull);
break;
default:
SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorDying);
break;
}
}
else if (XInputSlot.HasValue)
{
SetLightBarColor((DsPadId) XInputSlot);
}
Expand Down
78 changes: 78 additions & 0 deletions ScpControl/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion ScpControl/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,23 @@
<Setting Name="ServiceProcessPriority" Provider="ScpControl.Utilities.PortableSettingsProvider" Type="System.Diagnostics.ProcessPriorityClass" Scope="User">
<Value Profile="(Default)">Normal</Value>
</Setting>
<Setting Name="Ds4ShowBatteryInfo" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="Ds4ColorFull" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Ds4ColorHigh" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Ds4ColorMedium" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Ds4ColorLow" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Ds4ColorDying" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>
5 changes: 3 additions & 2 deletions ScpControl/ScpControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath>
Expand Down Expand Up @@ -377,11 +378,11 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.1.29.4\build\portable-net+sl+win+wpa+wp\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.29.4\build\portable-net+sl+win+wpa+wp\Fody.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
39 changes: 38 additions & 1 deletion ScpControl/ScpCore/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -198,6 +199,42 @@ public bool Repair
set { Settings.Default.Ds4Repair = value; }
}

public bool Ds4ShowBatteryInfo
{
get { return Settings.Default.Ds4ShowBatteryInfo; }
set { Settings.Default.Ds4ShowBatteryInfo = value; }
}

public uint Ds4ColorFull
{
get { return Settings.Default.Ds4ColorFull; }
set { Settings.Default.Ds4ColorFull = value; }
}

public uint Ds4ColorHigh
{
get { return Settings.Default.Ds4ColorHigh; }
set { Settings.Default.Ds4ColorHigh = value; }
}

public uint Ds4ColorMedium
{
get { return Settings.Default.Ds4ColorMedium; }
set { Settings.Default.Ds4ColorMedium = value; }
}

public uint Ds4ColorLow
{
get { return Settings.Default.Ds4ColorLow; }
set { Settings.Default.Ds4ColorLow = value; }
}

public uint Ds4ColorDying
{
get { return Settings.Default.Ds4ColorDying; }
set { Settings.Default.Ds4ColorDying = value; }
}

public byte[] BdLink
{
get { return MBdLink; }
Expand Down Expand Up @@ -264,7 +301,7 @@ public ProcessPriorityClass ServiceProcessPriority
}

#endregion

#region Sound settings

public bool SoundsEnabled
Expand Down
20 changes: 19 additions & 1 deletion ScpControl/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@
<setting name="ServiceProcessPriority" serializeAs="String">
<value>Normal</value>
</setting>
<setting name="Ds4ShowBatteryInfo" serializeAs="String">
<value>False</value>
</setting>
<setting name="Ds4ColorFull" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorHigh" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorMedium" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorLow" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorDying" serializeAs="String">
<value>0</value>
</setting>
</ScpControl.Properties.Settings>
</userSettings>
<runtime>
Expand All @@ -178,4 +196,4 @@
</assemblyBinding>
</runtime>

</configuration>
</configuration>
20 changes: 19 additions & 1 deletion ScpServer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@
<setting name="DeadZoneR" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ShowBatteryInfo" serializeAs="String">
<value>False</value>
</setting>
<setting name="Ds4ColorFull" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorHigh" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorMedium" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorLow" serializeAs="String">
<value>0</value>
</setting>
<setting name="Ds4ColorDying" serializeAs="String">
<value>0</value>
</setting>
</ScpControl.Properties.Settings>
</userSettings>

Expand Down Expand Up @@ -144,4 +162,4 @@
</assemblyBinding>
</runtime>

</configuration>
</configuration>
Binary file added ScpSettings/ColorPicker.dll
Binary file not shown.
Binary file added ScpSettings/ColorPickerControls.dll
Binary file not shown.
15 changes: 15 additions & 0 deletions ScpSettings/Controls/ColorChooserControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl x:Class="ScpSettings.Controls.ColorChooserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="300" Loaded="UserControl_Loaded">
<Grid x:Name="MainGrid">
<DockPanel>
<Button Margin="5" Click="BrowseButton_Click">Choose...</Button>
<Label x:Name="lblText" Content="Full" HorizontalAlignment="Center" VerticalAlignment="Center" Height="28" Width="80" />
<Label x:Name="lblColor" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Background="AliceBlue" Height="20" />
</DockPanel>
</Grid>
</UserControl>
Loading

0 comments on commit cc8f383

Please sign in to comment.