necroware / ps2-serial-mouse-adapter

PS/2 to serial port mouse adapter
GNU General Public License v3.0
68 stars 12 forks source link

KVM Compatibility and Fix - Streaming Mode #9

Open morphinejh opened 1 year ago

morphinejh commented 1 year ago

This is for information and, possibly, integration.

I have a TRENDnet TK-423K that I have tried with a few types of PS/2 to serial connections. I couldn't get any of them to work consistently.

However, since you were kind enough to share this project publicly, I was able to adapt your code to get it all working! Turns out the KVM will not work in any mode except Streaming mode. In order to get it to work with the KVM switch that I have, I had to speed up the code execution - it seemed to get out of sync on the PS/2 side or stream too much information on the RS-232 side...

My solution was to use direct Port writes where ever possible as well as instantiate the mouse class directly in streaming mode from the start. Rather than initiating it and then resetting to put it in streaming mode. One issue with the code as it is now, is that bool m_stream is only set when initialized - therefore it is never fully in streaming mode after a mouse.reset() call. The check for: If (m_stream) within Ps2Mouse.cpp was always false since the constructor showed: Ps2Mouse::Ps2Mouse(byte clockPin, byte dataPin) : m_clockPin(clockPin), m_dataPin(dataPin), m_stream(false) {}

This essentially made it always send a command request for data, which came back all zeroes when the mouse was set to be in streaming mode. I don't know if this behavior is universal though, as I have only been able to test on the KVM switch.

The way I have written the adapted code makes it only compatible with an Arduino Pro Mini due to the direct Port writes. However it could be adapted to another model easily. There are also new DEBUG statements that can be turned on/off. I did trying adapting just the new streaming mode constructor, but it didn't work correctly either. I believe due to the delays in Arduino's digitalWrite() and digitalRead().

Check out the fork and let me know your thoughts: https://github.com/morphinejh/ps2-serial-mouse-adapter

EDIT: Board v0.7 used for testing

sweetlilmre commented 1 month ago

@morphinejh I had a look at your fork. Direct port access is definitely the way to go here, so great addition. Why don't you raise a pull request against this repo, it would be nice to get your changes into the official source.

I have some comments on your changes, if you are interested I can fork your repo and make a pull request against it?

morphinejh commented 1 month ago

Not a problem. I'll check it out once you do.