(self, buf)
return DS4Report(
            # Left analog stick
            buf[1], buf[2],

            # Right analog stick
            buf[3], buf[4],

            # L2 and R2 analog
            buf[8], buf[9],

            # DPad up, down, left, right
            (dpad in (0, 1, 7)), (dpad in (3, 4, 5)),
            (dpad in (5, 6, 7)), (dpad in (1, 2, 3)),

            # Buttons cross, circle, square, triangle
            (buf[5] & 32) != 0, (buf[5] & 64) != 0,
            (buf[5] & 16) != 0, (buf[5] & 128) != 0,

            # L1, L2 and L3 buttons
            (buf[6] & 1) != 0, (buf[6] & 4) != 0, (buf[6] & 64) != 0,

            # R1, R2,and R3 buttons
            (buf[6] & 2) != 0, (buf[6] & 8) != 0, (buf[6] & 128) != 0,

            # Share and option buttons
            (buf[6] & 16) != 0, (buf[6] & 32) != 0,

            # Trackpad and PS buttons
            (buf[7] & 2) != 0, (buf[7] & 1) != 0,

            # Acceleration
            S16LE.unpack_from(buf, 13)[0],
            S16LE.unpack_from(buf, 15)[0],
            S16LE.unpack_from(buf, 17)[0],

            # Orientation
            -(S16LE.unpack_from(buf, 19)[0]),
            S16LE.unpack_from(buf, 21)[0],
            S16LE.unpack_from(buf, 23)[0],

            # Trackpad touch 1: id, active, x, y
            buf[35] & 0x7f, (buf[35] >> 7) == 0,
            ((buf[37] & 0x0f) << 8) | buf[36],
            buf[38] << 4 | ((buf[37] & 0xf0) >> 4),

            # Trackpad touch 2: id, active, x, y
            buf[39] & 0x7f, (buf[39] >> 7) == 0,
            ((buf[41] & 0x0f) << 8) | buf[40],
            buf[42] << 4 | ((buf[41] & 0xf0) >> 4),

            # Timestamp and battery
            buf[7] >> 2,
            buf[30] % 16,

            # External inputs (usb, audio, mic)
            (buf[30] & 16) != 0, (buf[30] & 32) != 0,
            (buf[30] & 64) != 0
        )
Parse a buffer containing a HID report.
Parse a buffer containing a HID report.
Parse a buffer containing a HID report .
def parse_report(self, buf):
        """Parse a buffer containing a HID report."""
        dpad = buf[5] % 16

        return DS4Report(
            # Left analog stick
            buf[1], buf[2],

            # Right analog stick
            buf[3], buf[4],

            # L2 and R2 analog
            buf[8], buf[9],

            # DPad up, down, left, right
            (dpad in (0, 1, 7)), (dpad in (3, 4, 5)),
            (dpad in (5, 6, 7)), (dpad in (1, 2, 3)),

            # Buttons cross, circle, square, triangle
            (buf[5] & 32) != 0, (buf[5] & 64) != 0,
            (buf[5] & 16) != 0, (buf[5] & 128) != 0,

            # L1, L2 and L3 buttons
            (buf[6] & 1) != 0, (buf[6] & 4) != 0, (buf[6] & 64) != 0,

            # R1, R2,and R3 buttons
            (buf[6] & 2) != 0, (buf[6] & 8) != 0, (buf[6] & 128) != 0,

            # Share and option buttons
            (buf[6] & 16) != 0, (buf[6] & 32) != 0,

            # Trackpad and PS buttons
            (buf[7] & 2) != 0, (buf[7] & 1) != 0,

            # Acceleration
            S16LE.unpack_from(buf, 13)[0],
            S16LE.unpack_from(buf, 15)[0],
            S16LE.unpack_from(buf, 17)[0],

            # Orientation
            -(S16LE.unpack_from(buf, 19)[0]),
            S16LE.unpack_from(buf, 21)[0],
            S16LE.unpack_from(buf, 23)[0],

            # Trackpad touch 1: id, active, x, y
            buf[35] & 0x7f, (buf[35] >> 7) == 0,
            ((buf[37] & 0x0f) << 8) | buf[36],
            buf[38] << 4 | ((buf[37] & 0xf0) >> 4),

            # Trackpad touch 2: id, active, x, y
            buf[39] & 0x7f, (buf[39] >> 7) == 0,
            ((buf[41] & 0x0f) << 8) | buf[40],
            buf[42] << 4 | ((buf[41] & 0xf0) >> 4),

            # Timestamp and battery
            buf[7] >> 2,
            buf[30] % 16,

            # External inputs (usb, audio, mic)
            (buf[30] & 16) != 0, (buf[30] & 32) != 0,
            (buf[30] & 64) != 0
        )
def parse_report ( self , buf ) : dpad = buf [ 5 ] % 16 return DS4Report ( # Left analog stick buf [ 1 ] , buf [ 2 ] , # Right analog stick buf [ 3 ] , buf [ 4 ] , # L2 and R2 analog buf [ 8 ] , buf [ 9 ] , # DPad up, down, left, right ( dpad in ( 0 , 1 , 7 ) ) , ( dpad in ( 3 , 4 , 5 ) ) , ( dpad in ( 5 , 6 , 7 ) ) , ( dpad in ( 1 , 2 , 3 ) ) , # Buttons cross, circle, square, triangle ( buf [ 5 ] & 32 ) != 0 , ( buf [ 5 ] & 64 ) != 0 , ( buf [ 5 ] & 16 ) != 0 , ( buf [ 5 ] & 128 ) != 0 , # L1, L2 and L3 buttons ( buf [ 6 ] & 1 ) != 0 , ( buf [ 6 ] & 4 ) != 0 , ( buf [ 6 ] & 64 ) != 0 , # R1, R2,and R3 buttons ( buf [ 6 ] & 2 ) != 0 , ( buf [ 6 ] & 8 ) != 0 , ( buf [ 6 ] & 128 ) != 0 , # Share and option buttons ( buf [ 6 ] & 16 ) != 0 , ( buf [ 6 ] & 32 ) != 0 , # Trackpad and PS buttons ( buf [ 7 ] & 2 ) != 0 , ( buf [ 7 ] & 1 ) != 0 , # Acceleration S16LE . unpack_from ( buf , 13 ) [ 0 ] , S16LE . unpack_from ( buf , 15 ) [ 0 ] , S16LE . unpack_from ( buf , 17 ) [ 0 ] , # Orientation - ( S16LE . unpack_from ( buf , 19 ) [ 0 ] ) , S16LE . unpack_from ( buf , 21 ) [ 0 ] , S16LE . unpack_from ( buf , 23 ) [ 0 ] , # Trackpad touch 1: id, active, x, y buf [ 35 ] & 0x7f , ( buf [ 35 ] >> 7 ) == 0 , ( ( buf [ 37 ] & 0x0f ) << 8 ) | buf [ 36 ] , buf [ 38 ] << 4 | ( ( buf [ 37 ] & 0xf0 ) >> 4 ) , # Trackpad touch 2: id, active, x, y buf [ 39 ] & 0x7f , ( buf [ 39 ] >> 7 ) == 0 , ( ( buf [ 41 ] & 0x0f ) << 8 ) | buf [ 40 ] , buf [ 42 ] << 4 | ( ( buf [ 41 ] & 0xf0 ) >> 4 ) , # Timestamp and battery buf [ 7 ] >> 2 , buf [ 30 ] % 16 , # External inputs (usb, audio, mic) ( buf [ 30 ] & 16 ) != 0 , ( buf [ 30 ] & 32 ) != 0 , ( buf [ 30 ] & 64 ) != 0 )