Fixed readout of battery status

ds4drv showed that the method used before was not
correct
This commit is contained in:
Travis Nickles 2017-04-22 07:00:12 -07:00
parent 3c7aa0d477
commit ecb271cfb1
2 changed files with 16 additions and 7 deletions

View File

@ -873,15 +873,16 @@ namespace DS4Windows
{ {
String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
bool nocontrollers = true; bool nocontrollers = true;
for (Int32 Index = 0; Index < Pads.Length; Index++) for (Int32 Index = 0, PadsLen = Pads.Length; Index < PadsLen; Index++)
{ {
Pads[Index].Text = Program.rootHub.getDS4MacAddress(Index); Pads[Index].Text = Program.rootHub.getDS4MacAddress(Index);
DS4Device d = Program.rootHub.DS4Controllers[Index]; DS4Device d = Program.rootHub.DS4Controllers[Index];
if (QuickCharge && d?.ConnectionType == ConnectionType.BT && (bool)d?.Charging) if (QuickCharge && d?.getConnectionType() == ConnectionType.BT && (bool)d?.isCharging())
{ {
d.DisconnectBT(); d.DisconnectBT();
return; return;
} }
switch (Program.rootHub.getDS4Status(Index)) switch (Program.rootHub.getDS4Status(Index))
{ {
case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break; case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break;
@ -889,6 +890,7 @@ namespace DS4Windows
case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break; case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break;
default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break; default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break;
} }
Batteries[Index].Text = Program.rootHub.getDS4Battery(Index); Batteries[Index].Text = Program.rootHub.getDS4Battery(Index);
if (Pads[Index].Text != String.Empty) if (Pads[Index].Text != String.Empty)
{ {
@ -920,6 +922,7 @@ namespace DS4Windows
if (Program.rootHub.getShortDS4ControllerInfo(Index) != Properties.Resources.NoneText) if (Program.rootHub.getShortDS4ControllerInfo(Index) != Properties.Resources.NoneText)
tooltip += "\n" + (Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index); // Carefully stay under the 63 character limit. tooltip += "\n" + (Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index); // Carefully stay under the 63 character limit.
} }
lbNoControllers.Visible = nocontrollers; lbNoControllers.Visible = nocontrollers;
tLPControllers.Visible = !nocontrollers; tLPControllers.Visible = !nocontrollers;
btnClear.Enabled = lvDebug.Items.Count > 0; btnClear.Enabled = lvDebug.Items.Count > 0;

View File

@ -121,11 +121,15 @@ namespace DS4Windows
private const int BT_OUTPUT_REPORT_LENGTH = 78; private const int BT_OUTPUT_REPORT_LENGTH = 78;
private const int BT_INPUT_REPORT_LENGTH = 547; private const int BT_INPUT_REPORT_LENGTH = 547;
// Use large value for worst case scenario // Use large value for worst case scenario
private static int READ_STREAM_TIMEOUT = 100; private const int READ_STREAM_TIMEOUT = 100;
// Isolated BT report can have latency as high as 15 ms // Isolated BT report can have latency as high as 15 ms
// due to hardware. // due to hardware.
private static int WARN_INTERVAL_BT = 20; private const int WARN_INTERVAL_BT = 20;
private static int WARN_INTERVAL_USB = 10; private const int WARN_INTERVAL_USB = 10;
// Maximum values for battery level when no USB cable is connected
// and when a USB cable is connected
private const int BATTERY_MAX = 8;
private const int BATTERY_MAX_USB = 11;
private HidDevice hDevice; private HidDevice hDevice;
private string Mac; private string Mac;
private DS4State cState = new DS4State(); private DS4State cState = new DS4State();
@ -625,12 +629,14 @@ namespace DS4Windows
try try
{ {
charging = (inputReport[30] & 0x10) != 0; charging = (inputReport[30] & 0x10) != 0;
battery = (inputReport[30] & 0x0f) * 10; int maxBatteryValue = charging ? BATTERY_MAX_USB : BATTERY_MAX;
int tempBattery = (inputReport[30] & 0x0f) * 100 / maxBatteryValue;
battery = Math.Min((byte)tempBattery, (byte)100);
cState.Battery = (byte)battery; cState.Battery = (byte)battery;
if (inputReport[30] != priorInputReport30) if (inputReport[30] != priorInputReport30)
{ {
priorInputReport30 = inputReport[30]; priorInputReport30 = inputReport[30];
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> power subsystem octet: 0x" + inputReport[30].ToString("x02")); //Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> power subsystem octet: 0x" + inputReport[30].ToString("x02"));
} }
} }
catch { currerror = "Index out of bounds: battery"; } catch { currerror = "Index out of bounds: battery"; }