void ApplePS2SynapticsTouchPad:: dispatchRelativePointerEventWithPacket( UInt8 * packet, UInt32 packetSize ) { // // Process the three byte relative format packet that was retreived from the // trackpad. The format of the bytes is as follows: // // 7 6 5 4 3 2 1 0 // ----------------------- // YO XO YS XS 1 M R L // X7 X6 X5 X4 X3 X3 X1 X0 (X delta) // Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 (Y delta) // UInt32 buttons = 0; SInt32 dx, dy; AbsoluteTime now; if ( (packet[0] & 0x1) ) buttons |= 0x1; // left button (bit 0 in packet) if ( (packet[0] & 0x2) ) buttons |= 0x2; // right button (bit 1 in packet) if ( (packet[0] & 0x4) ) buttons |= 0x4; // middle button (bit 2 in packet) dx = ((packet[0] & 0x10) ? 0xffffff00 : 0 ) | packet[1]; dy = -(((packet[0] & 0x20) ? 0xffffff00 : 0 ) | packet[2]); clock_get_uptime(&now); dispatchRelativePointerEvent(dx, dy, buttons, now); }
void ApplePS2Mouse::dispatchRelativePointerEventWithPacket(UInt8 * packet, UInt32 packetSize) { // // Process the three byte mouse packet that was retreived from the mouse. // The format of the bytes is as follows: // // 7 6 5 4 3 2 1 0 // YO XO YS XS 1 M R L // X7 X6 X5 X4 X3 X3 X1 X0 // Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 // Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0 <- fourth byte returned only for Intellimouse type // // 0 0 B5 B4 Z3 Z2 Z1 Z0 <- fourth byte for 5-button wheel mouse mode // UInt32 buttons = 0; SInt32 dx; SInt32 dy; SInt16 dz = 0; AbsoluteTime now; if ( (packet[0] & 0x1) ) buttons |= 0x1; // left button (bit 0 in packet) if ( (packet[0] & 0x2) ) buttons |= 0x2; // right button (bit 1 in packet) if ( (packet[0] & 0x4) ) buttons |= 0x4; // middle button (bit 2 in packet) dx = ((packet[0] & 0x10) ? 0xffffff00 : 0 ) | packet[1]; dy = -(((packet[0] & 0x20) ? 0xffffff00 : 0 ) | packet[2]); clock_get_uptime((uint64_t *)&now); if ( packetSize > 3 ) { // Pull out fourth and fifth buttons. if (_type == kMouseTypeIntellimouseExplorer) { if (packet[3] & 0x10) buttons |= 0x8; // fourth button (bit 4 in packet) if (packet[3] & 0x20) buttons |= 0x10; // fifth button (bit 5 in packet) } dispatchRelativePointerEvent(dx, dy, buttons, now); // // We treat the 4th byte in the packet as a 8-bit signed Z value. // There are mice that can report only 4-bits for the Z data, and // use two of the remaining 4 bits for buttons 4 and 5. To enable // the 5-button mouse mode, the command sequence should be: // // setMouseSampleRate(200); // setMouseSampleRate(200); // setMouseSampleRate(80); // // Those devices will return 0x04 for the device ID. // // %%KCD - As it turns out, the valid range for scroll data from // PS2 mice is -8 to +7, thus the upper four bits are just a sign // bit. If we just sign extend the lower four bits, the scroll // calculation works for normal scrollwheel mice and five button mice. dz = (SInt16)(((SInt8)(packet[3] << 4)) >> 4); if ( dz ) { // // The Z counter is negative on an upwards scroll (away from the user), // and positive when scrolling downwards. Invert this before passing to // HID/CG. // dispatchScrollWheelEvent(-dz, 0, 0, now); } } else {