Harvie / ps2dev

Arduino library to emulate PS2 keyboard/mouse
MIT License
114 stars 27 forks source link

strange question, compiler bug ? #3

Closed liumazi closed 4 years ago

liumazi commented 4 years ago

Hi Harvie ! thanks for your code, i have a question

the ps2_mouse, i modify code:


void setup() { unsigned char val;

Serial.begin(9600);

// send the mouse start up mouse.write(0xAA); Serial.println("setup 1");

mouse.write(0x00); Serial.println("setup 2");

delay(10); }

int n = 0;

void loop() { unsigned char c; if ((digitalRead(3)==LOW) || (digitalRead(2) == LOW)) { Serial.print("try read "); Serial.println(n, HEX);

while (mouse.read(&c)) 
{
  Serial.print("read fail ");
  Serial.println(n, HEX);
}
Serial.println("read ok");

//mousecommand(c);

n++;

}

Serial.println("end read");

//if (enabled) { // // move the mouse diagonally // delta_x = 1; // delta_y = 1; // write_packet() ; //}

delay(50); }

Weirdly, comment out "mousecommand", will endless loop in "while (mouse.read(&c)) " by first called

liumazi commented 4 years ago

print log: 16:02:27.891 -> 16:02:27.891 -> setup 1 16:02:29.502 -> setup 2 16:02:29.502 -> try read 0 16:02:29.536 -> read fail 0 16:02:29.570 -> read fail 0 16:02:29.604 -> read fail 0 16:02:29.638 -> read fail 0 16:02:29.638 -> read fail 0 16:02:29.672 -> read fail 0 16:02:29.705 -> read fail 0 16:02:29.739 -> read fail 0 16:02:29.772 -> read fail 0 16:02:29.806 -> read fail 0 16:02:29.840 -> read fail 0 16:02:29.874 -> read fail 0 16:02:29.907 -> read fail 0 16:02:29.941 -> read fail 0 16:02:29.974 -> read fail 0

liumazi commented 4 years ago

if do not comment out "mousecommand", the print log:

15:49:36.372 -> setup 1 15:49:37.993 -> setup 2 15:49:37.993 -> end read 15:49:38.027 -> try read 0 15:49:38.061 -> read ok 15:49:38.061 -> mousecommand 15:49:38.061 -> FF 15:49:38.061 -> end read 15:49:38.095 -> try read 1 15:49:38.095 -> read ok 15:49:38.129 -> mousecommand 15:49:38.129 -> F2 15:49:38.129 -> end read 15:49:38.163 -> try read 2 15:49:38.163 -> read ok 15:49:38.163 -> mousecommand 15:49:38.197 -> E8 15:49:38.197 -> end read 15:49:38.197 -> try read 3 15:49:38.231 -> read ok 15:49:38.231 -> mousecommand 15:49:38.231 -> E6 15:49:38.265 -> end read 15:49:38.265 -> try read 4 15:49:38.265 -> read ok 15:49:38.299 -> mousecommand 15:49:38.299 -> E6 15:49:38.299 -> end read 15:49:38.333 -> try read 5 15:49:38.333 -> read ok 15:49:38.333 -> mousecommand 15:49:38.367 -> E6 15:49:38.367 -> end read 15:49:38.367 -> try read 6 15:49:38.401 -> read ok 15:49:38.401 -> mousecommand 15:49:38.401 -> E9 15:49:38.401 -> end read 15:49:38.435 -> end read 15:49:38.469 -> end read 15:49:38.538 -> end read 15:49:38.572 -> end read 15:49:38.640 -> end read 15:49:38.674 -> end read 15:49:38.742 -> end read 15:49:38.776 -> end read 15:49:38.844 -> end read 15:49:38.878 -> end read 15:49:38.946 -> end read 15:49:38.980 -> end read 15:49:39.048 -> end read 15:49:39.082 -> end read 15:49:39.116 -> end read 15:49:39.184 -> end read 15:49:39.218 -> end read 15:49:39.287 -> end read 15:49:39.321 -> end read 15:49:39.389 -> end read 15:49:39.423 -> end read 15:49:39.491 -> try read 7 15:49:39.491 -> read ok 15:49:39.491 -> mousecommand 15:49:39.525 -> E8 15:49:39.525 -> end read 15:49:39.559 -> try read 8 15:49:39.559 -> read ok 15:49:39.559 -> mousecommand 15:49:39.593 -> F3 15:49:39.593 -> end read 15:49:39.593 -> try read 9 15:49:39.627 -> read ok 15:49:39.627 -> mousecommand 15:49:39.627 -> F3 15:49:39.661 -> end read 15:49:39.661 -> try read A 15:49:39.661 -> read ok 15:49:39.695 -> mousecommand 15:49:39.695 -> F3 15:49:39.695 -> end read 15:49:39.729 -> try read B 15:49:39.729 -> read ok 15:49:39.729 -> mousecommand 15:49:39.763 -> F2 15:49:39.763 -> end read 15:49:39.797 -> try read C 15:49:39.797 -> read ok 15:49:39.797 -> mousecommand 15:49:39.831 -> F3 15:49:39.831 -> end read 15:49:39.831 -> try read D 15:49:39.864 -> read ok 15:49:39.864 -> mousecommand 15:49:39.864 -> F3 15:49:39.864 -> end read 15:49:39.898 -> try read E 15:49:39.898 -> read ok 15:49:39.932 -> mousecommand 15:49:39.932 -> F3 15:49:39.932 -> end read 15:49:39.966 -> try read F 15:49:39.966 -> read ok 15:49:39.966 -> mousecommand 15:49:40.000 -> F2 15:49:40.000 -> end read 15:49:40.000 -> try read 10 15:49:40.035 -> read ok 15:49:40.035 -> mousecommand 15:49:40.035 -> F3 15:49:40.069 -> end read 15:49:40.069 -> try read 11 15:49:40.103 -> read ok 15:49:40.103 -> mousecommand 15:49:40.103 -> E8 15:49:40.103 -> end read 15:49:40.137 -> try read 12 15:49:40.137 -> read ok 15:49:40.171 -> mousecommand 15:49:40.171 -> F4 15:49:40.171 -> end read 15:49:40.171 -> end read 15:49:40.239 -> end read 15:49:40.273 -> end read 15:49:40.341 -> end read 15:49:40.374 -> end read

Harvie commented 4 years ago

Hello, i've never used the mouse. Only the keyboard. Maybe there are some bugs. I don't have time to fix this, but if you figure the problem, i will be more than happy to review and merge your modifications.

liumazi commented 4 years ago

To make ps2_mouse work ok, only modify setup() like this: (Otherwise while will loop forever)

void setup() { unsigned char val;

Serial.begin(9600);

// send the mouse start up mouse.write(0xAA); mouse.write(0x00);

delay(10); }


But I wonder, why mousecommand will disturb the first time while (mouse.read(&c)) .. :(

Harvie commented 4 years ago

Thanks for figuring this. Can you please make pull request, so i can merge the changes to repository?

liumazi commented 4 years ago

I created the pull request, and my source code for usb mouse to ps/2 : https://github.com/liumazi/MzMouse