Incomprehensible phenomena, compiler or library function bugs?

the ps/2 mouse emulator, 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

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

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: