mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-24 15:41:49 +01:00
Only update battery status for one controller instead of entire controller list
Event is also executed async now.
This commit is contained in:
parent
918870f256
commit
ea3b1401f0
@ -90,7 +90,7 @@ namespace DS4Windows
|
|||||||
|
|
||||||
private async void WarnExclusiveModeFailure(DS4Device device)
|
private async void WarnExclusiveModeFailure(DS4Device device)
|
||||||
{
|
{
|
||||||
if (DS4Devices.isExclusiveMode && !device.IsExclusive)
|
if (DS4Devices.isExclusiveMode && !device.isExclusive())
|
||||||
{
|
{
|
||||||
await System.Threading.Tasks.Task.Delay(5);
|
await System.Threading.Tasks.Task.Delay(5);
|
||||||
String message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.getMacAddress()) + " " + Properties.Resources.QuitOtherPrograms;
|
String message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.getMacAddress()) + " " + Properties.Resources.QuitOtherPrograms;
|
||||||
@ -104,53 +104,60 @@ namespace DS4Windows
|
|||||||
if (x360Bus.Open() && x360Bus.Start())
|
if (x360Bus.Open() && x360Bus.Start())
|
||||||
{
|
{
|
||||||
if (showlog)
|
if (showlog)
|
||||||
LogDebug(Properties.Resources.Starting);
|
LogDebug(Properties.Resources.Starting);
|
||||||
DS4Devices.isExclusiveMode = UseExclusiveMode;
|
|
||||||
|
DS4Devices.isExclusiveMode = getUseExclusiveMode();
|
||||||
if (showlog)
|
if (showlog)
|
||||||
{
|
{
|
||||||
LogDebug(Properties.Resources.SearchingController);
|
LogDebug(Properties.Resources.SearchingController);
|
||||||
LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
|
LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DS4Devices.findControllers();
|
DS4Devices.findControllers();
|
||||||
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
|
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
|
||||||
int ind = 0;
|
//int ind = 0;
|
||||||
DS4LightBar.defaultLight = false;
|
DS4LightBar.defaultLight = false;
|
||||||
foreach (DS4Device device in devices)
|
//foreach (DS4Device device in devices)
|
||||||
|
for (int i = 0, devCount = devices.Count(); i < devCount; i++)
|
||||||
{
|
{
|
||||||
|
DS4Device device = devices.ElementAt<DS4Device>(i);
|
||||||
if (showlog)
|
if (showlog)
|
||||||
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
|
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
|
||||||
|
|
||||||
WarnExclusiveModeFailure(device);
|
WarnExclusiveModeFailure(device);
|
||||||
DS4Controllers[ind] = device;
|
DS4Controllers[i] = device;
|
||||||
device.Removal -= DS4Devices.On_Removal;
|
device.Removal -= DS4Devices.On_Removal;
|
||||||
device.Removal += this.On_DS4Removal;
|
device.Removal += this.On_DS4Removal;
|
||||||
device.Removal += DS4Devices.On_Removal;
|
device.Removal += DS4Devices.On_Removal;
|
||||||
touchPad[ind] = new Mouse(ind, device);
|
touchPad[i] = new Mouse(i, device);
|
||||||
device.LightBarColor = MainColor[ind];
|
device.LightBarColor = getMainColor(i);
|
||||||
if (!DinputOnly[ind])
|
|
||||||
x360Bus.Plugin(ind);
|
if (!getDInputOnly(i))
|
||||||
|
x360Bus.Plugin(i);
|
||||||
|
|
||||||
device.Report += this.On_Report;
|
device.Report += this.On_Report;
|
||||||
TouchPadOn(ind, device);
|
TouchPadOn(i, device);
|
||||||
//string filename = ProfilePath[ind];
|
//string filename = ProfilePath[ind];
|
||||||
ind++;
|
//ind++;
|
||||||
if (showlog)
|
if (showlog)
|
||||||
{
|
{
|
||||||
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[ind - 1] + ".xml"))
|
if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml"))
|
||||||
{
|
{
|
||||||
string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", ProfilePath[ind - 1]);
|
string prolog = Properties.Resources.UsingProfile.Replace("*number*", i.ToString()).Replace("*Profile name*", ProfilePath[i]);
|
||||||
LogDebug(prolog);
|
LogDebug(prolog);
|
||||||
Log.LogToTray(prolog);
|
Log.LogToTray(prolog);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (ind).ToString());
|
string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (i).ToString());
|
||||||
LogDebug(prolog);
|
LogDebug(prolog);
|
||||||
Log.LogToTray(prolog);
|
Log.LogToTray(prolog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ind >= 4) // out of Xinput devices!
|
if (i >= 4) // out of Xinput devices!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,9 +166,12 @@ namespace DS4Windows
|
|||||||
LogDebug(e.Message);
|
LogDebug(e.Message);
|
||||||
Log.LogToTray(e.Message);
|
Log.LogToTray(e.Message);
|
||||||
}
|
}
|
||||||
running = true;
|
|
||||||
|
|
||||||
|
running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ControllerStatusChanged(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,18 +182,19 @@ namespace DS4Windows
|
|||||||
running = false;
|
running = false;
|
||||||
if (showlog)
|
if (showlog)
|
||||||
LogDebug(Properties.Resources.StoppingX360);
|
LogDebug(Properties.Resources.StoppingX360);
|
||||||
|
|
||||||
bool anyUnplugged = false;
|
bool anyUnplugged = false;
|
||||||
for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
|
for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
|
||||||
{
|
{
|
||||||
if (DS4Controllers[i] != null)
|
if (DS4Controllers[i] != null)
|
||||||
{
|
{
|
||||||
if (DCBTatStop && !DS4Controllers[i].Charging && showlog)
|
if (DCBTatStop && !DS4Controllers[i].isCharging() && showlog)
|
||||||
{
|
{
|
||||||
if (DS4Controllers[i].ConnectionType == ConnectionType.BT)
|
if (DS4Controllers[i].getConnectionType() == ConnectionType.BT)
|
||||||
{
|
{
|
||||||
DS4Controllers[i].DisconnectBT();
|
DS4Controllers[i].DisconnectBT();
|
||||||
}
|
}
|
||||||
else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA)
|
else if (DS4Controllers[i].getConnectionType() == ConnectionType.SONYWA)
|
||||||
{
|
{
|
||||||
DS4Controllers[i].DisconnectDongle(true);
|
DS4Controllers[i].DisconnectDongle(true);
|
||||||
}
|
}
|
||||||
@ -203,6 +214,7 @@ namespace DS4Windows
|
|||||||
touchPad[i] = null;
|
touchPad[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anyUnplugged)
|
if (anyUnplugged)
|
||||||
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
|
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
|
||||||
|
|
||||||
@ -218,6 +230,7 @@ namespace DS4Windows
|
|||||||
|
|
||||||
ControllerStatusChanged(this);
|
ControllerStatusChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +248,7 @@ namespace DS4Windows
|
|||||||
if (device.isDisconnectingStatus())
|
if (device.isDisconnectingStatus())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (QuickCharge && device?.getConnectionType() == ConnectionType.BT &&
|
if (getQuickCharge() && device?.getConnectionType() == ConnectionType.BT &&
|
||||||
(bool)device?.isCharging())
|
(bool)device?.isCharging())
|
||||||
{
|
{
|
||||||
device.DisconnectBT();
|
device.DisconnectBT();
|
||||||
@ -268,7 +281,7 @@ namespace DS4Windows
|
|||||||
touchPad[Index] = new Mouse(Index, device);
|
touchPad[Index] = new Mouse(Index, device);
|
||||||
device.LightBarColor = MainColor[Index];
|
device.LightBarColor = MainColor[Index];
|
||||||
device.Report += this.On_Report;
|
device.Report += this.On_Report;
|
||||||
if (!DinputOnly[Index])
|
if (!getDInputOnly(Index))
|
||||||
x360Bus.Plugin(Index);
|
x360Bus.Plugin(Index);
|
||||||
TouchPadOn(Index, device);
|
TouchPadOn(Index, device);
|
||||||
|
|
||||||
@ -290,6 +303,8 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ControllerStatusChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -549,7 +564,8 @@ namespace DS4Windows
|
|||||||
// Currently updates status of all devices in DS4Form when any battery
|
// Currently updates status of all devices in DS4Form when any battery
|
||||||
// state change occurs.
|
// state change occurs.
|
||||||
if (pState.Battery != cState.Battery)
|
if (pState.Battery != cState.Battery)
|
||||||
ControllerStatusChanged(this);
|
OnBatteryStatusChange(this, ind, cState.Battery);
|
||||||
|
//ControllerStatusChanged(this);
|
||||||
|
|
||||||
CheckForHotkeys(ind, cState, pState);
|
CheckForHotkeys(ind, cState, pState);
|
||||||
|
|
||||||
|
@ -142,6 +142,28 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BatteryReportArgs: EventArgs
|
||||||
|
{
|
||||||
|
private int index;
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public BatteryReportArgs(int index, int level)
|
||||||
|
{
|
||||||
|
this.index = index;
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex()
|
||||||
|
{
|
||||||
|
return this.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel()
|
||||||
|
{
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class MultiValueDict<Key, Value> : Dictionary<Key, List<Value>>
|
public class MultiValueDict<Key, Value> : Dictionary<Key, List<Value>>
|
||||||
{
|
{
|
||||||
public void Add(Key key, Value val)
|
public void Add(Key key, Value val)
|
||||||
@ -213,12 +235,26 @@ namespace DS4Windows
|
|||||||
ControllerStatusChange(sender, EventArgs.Empty);
|
ControllerStatusChange(sender, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static event EventHandler<BatteryReportArgs> BatteryStatusChange;
|
||||||
|
public static void OnBatteryStatusChange(object sender, int index, int level)
|
||||||
|
{
|
||||||
|
if (BatteryStatusChange != null)
|
||||||
|
{
|
||||||
|
BatteryReportArgs args = new BatteryReportArgs(index, level);
|
||||||
|
BatteryStatusChange(sender, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//general values
|
//general values
|
||||||
public static bool UseExclusiveMode
|
public static bool UseExclusiveMode
|
||||||
{
|
{
|
||||||
set { m_Config.useExclusiveMode = value; }
|
set { m_Config.useExclusiveMode = value; }
|
||||||
get { return m_Config.useExclusiveMode; }
|
get { return m_Config.useExclusiveMode; }
|
||||||
}
|
}
|
||||||
|
public static bool getUseExclusiveMode()
|
||||||
|
{
|
||||||
|
return m_Config.useExclusiveMode;
|
||||||
|
}
|
||||||
|
|
||||||
public static DateTime LastChecked
|
public static DateTime LastChecked
|
||||||
{
|
{
|
||||||
@ -256,6 +292,10 @@ namespace DS4Windows
|
|||||||
set { m_Config.quickCharge = value; }
|
set { m_Config.quickCharge = value; }
|
||||||
get { return m_Config.quickCharge; }
|
get { return m_Config.quickCharge; }
|
||||||
}
|
}
|
||||||
|
public static bool getQuickCharge()
|
||||||
|
{
|
||||||
|
return m_Config.quickCharge;
|
||||||
|
}
|
||||||
public static int FirstXinputPort
|
public static int FirstXinputPort
|
||||||
{
|
{
|
||||||
set { m_Config.firstXinputPort = value; }
|
set { m_Config.firstXinputPort = value; }
|
||||||
@ -356,6 +396,10 @@ namespace DS4Windows
|
|||||||
return m_Config.chargingType[index];
|
return m_Config.chargingType[index];
|
||||||
}
|
}
|
||||||
public static bool[] DinputOnly => m_Config.dinputOnly;
|
public static bool[] DinputOnly => m_Config.dinputOnly;
|
||||||
|
public static bool getDInputOnly(int index)
|
||||||
|
{
|
||||||
|
return m_Config.dinputOnly[index];
|
||||||
|
}
|
||||||
public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
|
public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
|
||||||
public static bool[] UseTPforControls => m_Config.useTPforControls;
|
public static bool[] UseTPforControls => m_Config.useTPforControls;
|
||||||
public static bool getUseTPforControls(int index)
|
public static bool getUseTPforControls(int index)
|
||||||
|
@ -25,6 +25,7 @@ namespace DS4Windows
|
|||||||
public string[] arguements;
|
public string[] arguements;
|
||||||
delegate void LogDebugDelegate(DateTime Time, String Data, bool warning);
|
delegate void LogDebugDelegate(DateTime Time, String Data, bool warning);
|
||||||
delegate void NotificationDelegate(object sender, DebugEventArgs args);
|
delegate void NotificationDelegate(object sender, DebugEventArgs args);
|
||||||
|
delegate void BatteryStatusDelegate(object sender, BatteryReportArgs args);
|
||||||
protected Label[] Pads, Batteries;
|
protected Label[] Pads, Batteries;
|
||||||
protected ComboBox[] cbs;
|
protected ComboBox[] cbs;
|
||||||
protected Button[] ebns;
|
protected Button[] ebns;
|
||||||
@ -300,6 +301,7 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
LoadP();
|
LoadP();
|
||||||
Global.ControllerStatusChange += ControllerStatusChange;
|
Global.ControllerStatusChange += ControllerStatusChange;
|
||||||
|
Global.BatteryStatusChange += BatteryStatusUpdate;
|
||||||
Enable_Controls(0, false);
|
Enable_Controls(0, false);
|
||||||
Enable_Controls(1, false);
|
Enable_Controls(1, false);
|
||||||
Enable_Controls(2, false);
|
Enable_Controls(2, false);
|
||||||
@ -921,6 +923,30 @@ namespace DS4Windows
|
|||||||
ControllerStatusChanged();
|
ControllerStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void BatteryStatusUpdate(object sender, BatteryReportArgs args)
|
||||||
|
{
|
||||||
|
if (this.InvokeRequired)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BatteryStatusDelegate d = new BatteryStatusDelegate(BatteryStatusUpdate);
|
||||||
|
this.BeginInvoke(d, new object[] { sender, args });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string battery;
|
||||||
|
int level = args.getLevel();
|
||||||
|
if (level >= 100)
|
||||||
|
battery = Properties.Resources.Full;
|
||||||
|
else
|
||||||
|
battery = level + "%+";
|
||||||
|
|
||||||
|
Batteries[args.getIndex()].Text = battery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void ControllerStatusChanged()
|
protected void ControllerStatusChanged()
|
||||||
{
|
{
|
||||||
String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
|
String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
|
||||||
|
@ -167,6 +167,10 @@ namespace DS4Windows
|
|||||||
|
|
||||||
public HidDevice HidDevice => hDevice;
|
public HidDevice HidDevice => hDevice;
|
||||||
public bool IsExclusive => HidDevice.IsExclusive;
|
public bool IsExclusive => HidDevice.IsExclusive;
|
||||||
|
public bool isExclusive()
|
||||||
|
{
|
||||||
|
return HidDevice.IsExclusive;
|
||||||
|
}
|
||||||
private bool isDisconnecting = false;
|
private bool isDisconnecting = false;
|
||||||
public bool IsDisconnecting
|
public bool IsDisconnecting
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user