Hello
First of all, not Leonardo, but Micro. Just named topic for simpler search and understanding. My project is PS/2 to USB converter/adapter for my favorite mouse (very unique, 5 buttons and 2 wheels).
ISSUE:
When multiple applications startup or in some other ways cpu is busy for short moment, mouse cursor lags and then jump in different place. Rare, but false clicks happen too. Happens with NicoHood and default Arduino mouse code. Quick way to reproduce is by starting Chrome browser and after it's blank window appears in 1.5-2 seconds lag occurs. Win10 suffers horrible from this, Win7 is way better.
What i have found till now by using serial timing measurements, reading ps/2 port signals becomes very slow in those moments of lags, like 180-470 ms. It's because of code in that library which have cycles to wait valid signals, i did some modifications to replace infinite cycles to avoid spinning forever, but that still not works. Without arduino adapter regular usb mouse works fine. So it seems some issue with communication between OS and usb of the Arduino, Windows requests something by usb and that produce delay big enough to break reading ps/2 signals in right time. Or it's arduino sends data by usb somehow regulary and when OS is busy, arduino is waiting (but i do not execute any usb related code in those moments, not sure this is possible for non multithreaded controller, but hell knows).
I'm not much familiar with ps/2 protocol and just tried to fix some bugs which found in several libraries for ps/2 communication. Didn't find ps/2 library without mistakes (they just copy bugs of each other), so maybe somebody could suggest me the one. Or how to make things work, any idea is welcome.
EDIT: Attached source code. Problem somewhere in the PS2MouseHandler.cpp, when USB lag makes controller not execute in right time. Playing with cycles changes things, but not fix issue. And keep in mind i replaced "while" by "for" on purpose, otherwise infinite loops occur.
PS2MouseHandler.cpp (11.0 KB)
PS2MouseHandler.h (1.5 KB)
ps2tousb.ino (7.0 KB)