Better handling of wireless devies that get turned off. The dongle still responds but it sends empty packets.

This commit is contained in:
IceStormNG
2023-07-26 21:01:39 +02:00
parent f9a8665290
commit 6c6c93b378
3 changed files with 48 additions and 6 deletions

View File

@@ -107,10 +107,27 @@ namespace GHelper.Peripherals.Mouse
public event EventHandler? Disconnect;
public event EventHandler? BatteryUpdated;
public event EventHandler? MouseReadyChanged;
private readonly string path;
public bool IsDeviceReady { get; protected set; }
private void SetDeviceReady(bool ready)
{
bool notify = false;
if (IsDeviceReady != ready)
{
notify = true;
}
IsDeviceReady = ready;
if (MouseReadyChanged is not null && notify)
{
MouseReadyChanged(this, EventArgs.Empty);
}
}
public bool Wireless { get; protected set; }
public int Battery { get; protected set; }
public bool Charging { get; protected set; }
@@ -271,10 +288,10 @@ namespace GHelper.Peripherals.Mouse
{
//Likely only the dongle connected and the mouse is either sleeping or turned off.
//The mouse will not respond with proper data, but empty responses at this point
IsDeviceReady = false;
SetDeviceReady(false);
return;
}
IsDeviceReady = true;
SetDeviceReady(true);
ReadProfile();
ReadDPI();
@@ -380,7 +397,13 @@ namespace GHelper.Peripherals.Mouse
Charging = ParseChargingState(response);
//If the device goes to standby it will not report battery state anymore.
IsDeviceReady = Battery > 0;
SetDeviceReady(Battery > 0);
if (!IsDeviceReady)
{
Logger.WriteLine(GetDisplayName() + ": Device gone");
return;
}
Logger.WriteLine(GetDisplayName() + ": Got Battery Percentage " + Battery + "% - Charging:" + Charging);