mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Better handling of wireless devies that get turned off. The dongle still responds but it sends empty packets.
This commit is contained in:
@@ -89,6 +89,22 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
mouse.BatteryUpdated -= Mouse_BatteryUpdated;
|
mouse.BatteryUpdated -= Mouse_BatteryUpdated;
|
||||||
mouse.Disconnect -= Mouse_Disconnect;
|
mouse.Disconnect -= Mouse_Disconnect;
|
||||||
|
mouse.MouseReadyChanged -= Mouse_MouseReadyChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Mouse_MouseReadyChanged(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!mouse.IsDeviceReady)
|
||||||
|
{
|
||||||
|
this.Invoke(delegate
|
||||||
|
{
|
||||||
|
if (Disposing || IsDisposed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Mouse_BatteryUpdated(object? sender, EventArgs e)
|
private void Mouse_BatteryUpdated(object? sender, EventArgs e)
|
||||||
@@ -606,6 +622,10 @@ namespace GHelper
|
|||||||
for (int i = 0; i < mouse.DPIProfileCount() && i < 4; ++i)
|
for (int i = 0; i < mouse.DPIProfileCount() && i < 4; ++i)
|
||||||
{
|
{
|
||||||
AsusMouseDPI dpi = mouse.DpiSettings[i];
|
AsusMouseDPI dpi = mouse.DpiSettings[i];
|
||||||
|
if (dpi is null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (mouse.HasDPIColors())
|
if (mouse.HasDPIColors())
|
||||||
{
|
{
|
||||||
dpiButtons[i].Image = ControlHelper.TintImage(Properties.Resources.lighting_dot_24, dpi.Color);
|
dpiButtons[i].Image = ControlHelper.TintImage(Properties.Resources.lighting_dot_24, dpi.Color);
|
||||||
@@ -641,6 +661,7 @@ namespace GHelper
|
|||||||
|
|
||||||
mouse.Disconnect += Mouse_Disconnect;
|
mouse.Disconnect += Mouse_Disconnect;
|
||||||
mouse.BatteryUpdated += Mouse_BatteryUpdated;
|
mouse.BatteryUpdated += Mouse_BatteryUpdated;
|
||||||
|
mouse.MouseReadyChanged += Mouse_MouseReadyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSync_Click(object sender, EventArgs e)
|
private void ButtonSync_Click(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -107,10 +107,27 @@ namespace GHelper.Peripherals.Mouse
|
|||||||
|
|
||||||
public event EventHandler? Disconnect;
|
public event EventHandler? Disconnect;
|
||||||
public event EventHandler? BatteryUpdated;
|
public event EventHandler? BatteryUpdated;
|
||||||
|
public event EventHandler? MouseReadyChanged;
|
||||||
|
|
||||||
private readonly string path;
|
private readonly string path;
|
||||||
|
|
||||||
public bool IsDeviceReady { get; protected set; }
|
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 bool Wireless { get; protected set; }
|
||||||
public int Battery { get; protected set; }
|
public int Battery { get; protected set; }
|
||||||
public bool Charging { 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.
|
//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
|
//The mouse will not respond with proper data, but empty responses at this point
|
||||||
IsDeviceReady = false;
|
SetDeviceReady(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IsDeviceReady = true;
|
SetDeviceReady(true);
|
||||||
|
|
||||||
ReadProfile();
|
ReadProfile();
|
||||||
ReadDPI();
|
ReadDPI();
|
||||||
@@ -380,7 +397,13 @@ namespace GHelper.Peripherals.Mouse
|
|||||||
Charging = ParseChargingState(response);
|
Charging = ParseChargingState(response);
|
||||||
|
|
||||||
//If the device goes to standby it will not report battery state anymore.
|
//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);
|
Logger.WriteLine(GetDisplayName() + ": Got Battery Percentage " + Battery + "% - Charging:" + Charging);
|
||||||
|
|
||||||
|
|||||||
@@ -1096,13 +1096,11 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
b.Text = m.GetDisplayName() + "\n" + m.Battery + "%"
|
b.Text = m.GetDisplayName() + "\n" + m.Battery + "%"
|
||||||
+ (m.Charging ? "(" + Properties.Strings.Charging + ")" : "");
|
+ (m.Charging ? "(" + Properties.Strings.Charging + ")" : "");
|
||||||
b.Enabled = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Mouse is either not connected or in standby
|
//Mouse is either not connected or in standby
|
||||||
b.Text = m.GetDisplayName() + "\n(" + Properties.Strings.NotConnected + ")";
|
b.Text = m.GetDisplayName() + "\n(" + Properties.Strings.NotConnected + ")";
|
||||||
b.Enabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m.DeviceType())
|
switch (m.DeviceType())
|
||||||
@@ -1144,7 +1142,7 @@ namespace GHelper
|
|||||||
if (iph.DeviceType() == PeripheralType.Mouse)
|
if (iph.DeviceType() == PeripheralType.Mouse)
|
||||||
{
|
{
|
||||||
AsusMouse? am = iph as AsusMouse;
|
AsusMouse? am = iph as AsusMouse;
|
||||||
if (am is null)
|
if (am is null || !am.IsDeviceReady)
|
||||||
{
|
{
|
||||||
//Should not happen if all device classes are implemented correctly. But better safe than sorry.
|
//Should not happen if all device classes are implemented correctly. But better safe than sorry.
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user