static void MouseAndPingerLoop(UsbStream mouse, UsbStream pinger) { // Allocate in and out packets for "TinyBooter" simulation WireProtocol.WP_Packet inPacket; // Allocate packet for Pinger input UInt16 seq = 0; // Initialize Pinger packet sequence number // While done button is not pressed while (buttons.done.Read()) { // Perform these operations once every 10 milliseconds (actually a bit more than 10 milliseconds) // We've asked the host to query for mouse info at least every 10 milliseconds, but it actually // queries every 8 milliseconds - it's OK not to respond to every query. Thread.Sleep(10); byte xChange = 0; byte yChange = 0; // Make the mouse move by 3 steps each sample time if any movement button is pressed if (!buttons.up.Read()) { yChange = 0xFD; } if (!buttons.down.Read()) { yChange = 3; } if (!buttons.left.Read()) { xChange = 0xFD; } if (!buttons.right.Read()) { xChange = 3; } // Report to host the condition of "movement" or of the buttons SendMouseReport(mouse, !buttons.b1.Read(), !buttons.b2.Read(), !buttons.b3.Read(), xChange, yChange); // If a good WireProtocol packet was received from the host if (WireProtocol.ReadPacket(pinger, out inPacket)) { RespondToPacket(pinger, inPacket, seq); } } // Wait for the done button to be released while (!buttons.done.Read()) { ; } }
static void PingerLoop(UsbStream pinger) { // Allocate in and out packets for "TinyBooter" simulation WireProtocol.WP_Packet inPacket; // Allocate packet for Pinger input UInt16 seq = 0; // Initialize Pinger packet sequence number // While the done button is not pressed while (buttons.done.Read()) { Thread.Sleep(10); // No need to respond in a hurry if (WireProtocol.ReadPacket(pinger, out inPacket)) { RespondToPacket(pinger, inPacket, seq); } } // Wait for the done button to be released while (!buttons.done.Read()) { ; } }