Skip to content

Commit

Permalink
Added Battery Status for USB Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizonix committed Aug 5, 2018
1 parent 906499b commit 63c8589
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions ScpControl/Usb/Ds4/UsbDs4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ private void SetLightBarColor(DsPadId value)
}
}

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);
}
}

#endregion

#region Actions
Expand Down Expand Up @@ -314,9 +331,35 @@ protected override void Process(DateTime now)
_brightness = 0x00;
}

// set light bar color reflecting pad ID
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)
{
// set light bar color reflecting pad ID
SetLightBarColor((DsPadId) XInputSlot);
}

Expand Down

0 comments on commit 63c8589

Please sign in to comment.