From ecb271cfb1f4c3fd55f6457d34f94929e8720830 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 22 Apr 2017 07:00:12 -0700 Subject: [PATCH] Fixed readout of battery status ds4drv showed that the method used before was not correct --- DS4Windows/DS4Forms/DS4Form.cs | 7 +++++-- DS4Windows/DS4Library/DS4Device.cs | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 9d6734c..5281984 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -873,15 +873,16 @@ namespace DS4Windows { String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; 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); 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(); return; } + switch (Program.rootHub.getDS4Status(Index)) { 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; default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break; } + Batteries[Index].Text = Program.rootHub.getDS4Battery(Index); if (Pads[Index].Text != String.Empty) { @@ -920,6 +922,7 @@ namespace DS4Windows if (Program.rootHub.getShortDS4ControllerInfo(Index) != Properties.Resources.NoneText) tooltip += "\n" + (Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index); // Carefully stay under the 63 character limit. } + lbNoControllers.Visible = nocontrollers; tLPControllers.Visible = !nocontrollers; btnClear.Enabled = lvDebug.Items.Count > 0; diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 56f86a4..650799f 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -121,11 +121,15 @@ namespace DS4Windows private const int BT_OUTPUT_REPORT_LENGTH = 78; private const int BT_INPUT_REPORT_LENGTH = 547; // 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 // due to hardware. - private static int WARN_INTERVAL_BT = 20; - private static int WARN_INTERVAL_USB = 10; + private const int WARN_INTERVAL_BT = 20; + 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 string Mac; private DS4State cState = new DS4State(); @@ -625,12 +629,14 @@ namespace DS4Windows try { 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; if (inputReport[30] != priorInputReport30) { 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"; }