mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Handling of error responses from the mouse and some mice spam packets through the interface. Read again, until you get the matching USB packet or a timeout happens (aka: No data left in the buffer).
This commit is contained in:
@@ -240,6 +240,10 @@ namespace GHelper.Peripherals.Mouse
|
||||
#endif
|
||||
}
|
||||
|
||||
protected virtual bool IsMouseError(byte[] packet)
|
||||
{
|
||||
return packet[1] == 0xFF && packet[2] == 0xAA;
|
||||
}
|
||||
|
||||
protected virtual long MeasuredIO(Action<byte[]> ioFunc, byte[] param)
|
||||
{
|
||||
@@ -269,6 +273,23 @@ namespace GHelper.Peripherals.Mouse
|
||||
|
||||
if (IsPacketLoggerEnabled())
|
||||
Logger.WriteLine(GetDisplayName() + ": Read packet: " + ByteArrayToString(response));
|
||||
|
||||
if (IsMouseError(response))
|
||||
{
|
||||
Logger.WriteLine(GetDisplayName() + ": Mouse returned error (FF AA). Packet probably not supported by mouse firmware.");
|
||||
//Error. Mouse could not understand or process the sent packet
|
||||
return response;
|
||||
}
|
||||
|
||||
//Not the response we were looking for, continue reading
|
||||
while (response[0] != packet[0] || response[1] != packet[1] || response[2] != packet[2])
|
||||
{
|
||||
Logger.WriteLine(GetDisplayName() + ": Read wrong packet left in buffer: " + ByteArrayToString(response) + ". Retrying...");
|
||||
//Read again
|
||||
time = MeasuredIO(Read, response);
|
||||
Logger.WriteLine(GetDisplayName() + ": Read took " + time + "ms");
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user