I have got my hands on the old PS2 mouse library, and have reworked most of the code directly into my project.
I've been using this (http://www.computer-engineering.org/ps2mouse/) site to help me figure out what's what, and so far everything seems to be working smoothly, but I've hit a wall and I can't figure out how to fix the fact that the library only reads 8 bits for movement, when it's supposed to be 9 bits (2-complement 9-bit), and I cannot figure out how to do it.
Here is my current code for reading data from the mouse:
unsigned char read2(boolean vrbs, boolean mvmnt) {
unsigned char packet = 0x00;
unsigned char i;
unsigned char bob = 0x01;
gohi(clock);
gohi(data);
delayMicroseconds(50);
while (digitalRead(clock) == HIGH);
// delayMicroseconds(5); // not sure why.
while (digitalRead(clock) == LOW); // eat start bit
for (i=0; i <= 7 + mvmnt; i++) {
while (digitalRead(clock) == HIGH);
if (digitalRead(data) == HIGH) {
packet = packet | bob;
}
while (digitalRead(clock) == LOW);
bob = bob << 1;
}
// eat parity bit, ignore it.
while (digitalRead(clock) == HIGH);
while (digitalRead(clock) == LOW);
// eat stop bit
while (digitalRead(clock) == HIGH);
while (digitalRead(clock) == LOW);
golo(clock); // hold incoming data
if (vrbs == 1)
Serial << "Mouse says " << _HEX(packet) << endl;
return packet;
}
I've left in the original comments, but most of them make no sense to me.
Eg, I turned off the Microsecond delay and it's working just fine for me..
Anyway, hopefully somebody out there knows what's going on here, because I sure don't :~