-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved mouse handling implementation
- Loading branch information
Showing
7 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2020 ruundii. All rights reserved. | ||
|
||
|
||
from hid_message_filter import HIDMessageFilter | ||
from mouse_message_filter import MouseMessageFilter | ||
|
||
|
||
# 0x67, 0x05, 0x01, 0x09, 0x02, // Unit (Mass: Gram, Luminous Intensity: Candela) | ||
# 0xA1, 0x01, // Collection (Application) | ||
# 0x09, 0x01, // Usage (0x01) | ||
# 0xA1, 0x00, // Collection (Physical) | ||
# 0x05, 0x09, // Usage Page (Button) | ||
# 0x19, 0x01, // Usage Minimum (0x01) | ||
# 0x29, 0x10, // Usage Maximum (0x10) | ||
# 0x15, 0x00, // Logical Minimum (0) | ||
# 0x25, 0x01, // Logical Maximum (1) | ||
# 0x95, 0x10, // Report Count (16) | ||
# 0x75, 0x01, // Report Size (1) | ||
# 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) | ||
# 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) | ||
# 0x16, 0x01, 0x80, // Logical Minimum (-32767) | ||
# 0x26, 0xFF, 0x7F, // Logical Maximum (32767) | ||
# 0x75, 0x10, // Report Size (16) | ||
# 0x95, 0x02, // Report Count (2) | ||
# 0x09, 0x30, // Usage (X) | ||
# 0x09, 0x31, // Usage (Y) | ||
# 0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) | ||
# 0x15, 0x81, // Logical Minimum (-127) | ||
# 0x25, 0x7F, // Logical Maximum (127) | ||
# 0x75, 0x08, // Report Size (8) | ||
# 0x95, 0x01, // Report Count (1) | ||
# 0x09, 0x38, // Usage (Wheel) | ||
# 0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) | ||
# 0x05, 0x0C, // Usage Page (Consumer) | ||
# 0x0A, 0x38, 0x02, // Usage (AC Pan) | ||
# 0x95, 0x01, // Report Count (1) | ||
# 0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) | ||
# 0xC0, // End Collection | ||
# 0xC0, // End Collection | ||
# | ||
# // 68 bytes | ||
|
||
|
||
class G502MessageFilter(MouseMessageFilter): | ||
# first 16 bits are flags for buttons. 01 is left button, 02 is right, 04 is scroll | ||
# second 16 bits are X -32767 to 32767 | ||
# third 16 bits are Y -32767 to 32767 | ||
# then 8 bits of wheel -127 to 127 | ||
# then AC pan | ||
|
||
def __init__(self): | ||
self.message_size = 8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright (c) 2020 ruundii. All rights reserved. | ||
|
||
|
||
from hid_message_filter import HIDMessageFilter | ||
from mouse_message_filter import MouseMessageFilter | ||
from bitarray import bitarray | ||
from bitarray.util import ba2int | ||
|
||
|
||
# Logitech USB-PS/2 Optical Mouse | ||
# 0x05, 0x01, // Usage Page (Generic Desktop) 0 | ||
# 0x09, 0x02, // Usage (Mouse) 2 | ||
# 0xa1, 0x01, // Collection (Application) 4 | ||
# 0x09, 0x01, // Usage (Pointer) 6 | ||
# 0xa1, 0x00, // Collection (Physical) 8 | ||
# 0x05, 0x09, // Usage Page (Button) 10 | ||
# 0x19, 0x01, // Usage Minimum (1) 12 | ||
# 0x29, 0x08, // Usage Maximum (8) 14 | ||
# 0x15, 0x00, // Logical Minimum (0) 16 | ||
# 0x25, 0x01, // Logical Maximum (1) 18 | ||
# 0x95, 0x08, // Report Count (8) 20 | ||
# 0x75, 0x01, // Report Size (1) 22 | ||
# 0x81, 0x02, // Input (Data,Var,Abs) 24 | ||
# 0x95, 0x00, // Report Count (0) 26 | ||
# 0x81, 0x03, // Input (Cnst,Var,Abs) 28 | ||
# 0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1) 30 | ||
# 0x09, 0x40, // Usage (Vendor Usage 0x40) 33 | ||
# 0x95, 0x02, // Report Count (2) 35 | ||
# 0x75, 0x08, // Report Size (8) 37 | ||
# 0x15, 0x81, // Logical Minimum (-127) 39 | ||
# 0x25, 0x7f, // Logical Maximum (127) 41 | ||
# 0x81, 0x02, // Input (Data,Var,Abs) 43 | ||
# 0x05, 0x01, // Usage Page (Generic Desktop) 45 | ||
# 0x09, 0x38, // Usage (Wheel) 47 | ||
# 0x15, 0x81, // Logical Minimum (-127) 49 | ||
# 0x25, 0x7f, // Logical Maximum (127) 51 | ||
# 0x75, 0x08, // Report Size (8) 53 | ||
# 0x95, 0x01, // Report Count (1) 55 | ||
# 0x81, 0x06, // Input (Data,Var,Rel) 57 | ||
# 0x09, 0x30, // Usage (X) 59 | ||
# 0x09, 0x31, // Usage (Y) 61 | ||
# 0x16, 0x01, 0xf8, // Logical Minimum (-2047) 63 | ||
# 0x26, 0xff, 0x07, // Logical Maximum (2047) 66 | ||
# 0x75, 0x0c, // Report Size (12) 69 | ||
# 0x95, 0x02, // Report Count (2) 71 | ||
# 0x81, 0x06, // Input (Data,Var,Rel) 73 | ||
# 0xc0, // End Collection 75 | ||
# 0xc0, // End Collection 76 | ||
|
||
|
||
|
||
class MX510MessageFilter(MouseMessageFilter): | ||
# first 8 bits are flags for buttons. 01 is left button, 02 is right, 04 is scroll | ||
# second 16 bits are vendor specific x and y, one byte each | ||
# then 8 bits of wheel -127 to 127 | ||
# then x and y from -2047 to 2047, 12 bits each | ||
|
||
def __init__(self): | ||
self.message_size = 7 | ||
|
||
def get_buttons_flags(self, msg): | ||
return msg[0:1]+b'\x00' | ||
|
||
def get_x(self, msg): | ||
a = bitarray() | ||
a.frombytes(msg[4:6]) | ||
return int.to_bytes(ba2int(a[12:16] + a[0:8], signed=True), 2, "little", signed=True) | ||
|
||
def get_y(self, msg): | ||
a = bitarray() | ||
a.frombytes(msg[5:7]) | ||
return int.to_bytes(ba2int(a[8:16]+a[0:4],signed=True), 2, "little", signed=True) | ||
|
||
def get_wheel(self, msg): | ||
return msg[3:4] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from mouse_message_filter import MouseMessageFilter | ||
from mouse_g502_message_filter import G502MessageFilter | ||
from mouse_mx510_message_filter import MX510MessageFilter | ||
|
||
m = MouseMessageFilter() | ||
g = G502MessageFilter() | ||
mx = MX510MessageFilter() | ||
|
||
#generic mouse test | ||
# Button: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: -1 | Y: -13 | Wheel: 0 | ||
print(m.filter_message_to_host(b'\x00\x00\xff\xff\xf3\xff\x00')==b'\xa1\x03\x00\x00\xff\xff\xf3\xff\x00') | ||
|
||
# Button: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: 1 | Y: 5 | Wheel: 0 | ||
print(m.filter_message_to_host(b'\x00\x00\x01\x00\x05\x00\x00')==b'\xa1\x03\x00\x00\x01\x00\x05\x00\x00') | ||
|
||
# Button: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: 0 | Y: 0 | Wheel: 1 | ||
print(m.filter_message_to_host(b'\x00\x00\x00\x00\x00\x00\x01')==b'\xa1\x03\x00\x00\x00\x00\x00\x00\x01') | ||
|
||
# Button: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: 0 | Y: 0 | Wheel: -1 | ||
print(m.filter_message_to_host(b'\x00\x00\x00\x00\x00\x00\xff')==b'\xa1\x03\x00\x00\x00\x00\x00\x00\xff') | ||
|
||
# Button: 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: 0 | Y: 0 | Wheel: 0 | ||
print(m.filter_message_to_host(b'\x05\x00\x00\x00\x00\x00\x00')==b'\xa1\x03\x05\x00\x00\x00\x00\x00\x00') | ||
|
||
|
||
#G502 mouse test | ||
# Button: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | X: -1 | Y: -13 | Wheel: 0 | AC Pan: 0 | ||
print(g.filter_message_to_host(b'\x00\x00\xff\xff\xf3\xff\x00\x00')==b'\xa1\x03\x00\x00\xff\xff\xf3\xff\x00') | ||
|
||
#MX510 mouse test | ||
from bitarray import bitarray | ||
from bitarray.util import ba2int | ||
|
||
# Button: 0 0 0 0 0 0 0 0 | # | 0xff000040: 23 , 12 | Wheel: 0 | X: 23 | Y: 12 | ||
#00 17 0c 00 17 c0 00 | ||
print(mx.filter_message_to_host(b'\x00\x17\x0c\x00\x17\xc0\x00')==b'\xa1\x03\x00\x00\x17\x00\x0c\x00\x00') | ||
|
||
|
||
# Button: 0 0 0 0 0 0 0 0 | # | 0xff000040: 15 , -42 | Wheel: 0 | X: 15 | Y: -42 | ||
#00 0f d6 00 0f 60 fd | ||
print(mx.filter_message_to_host(b'\x00\x0f\xd6\x00\x0f\x60\xfd')==b'\xa1\x03\x00\x00\x0f\x00\xd6\xff\x00') | ||
|
||
|
||
# Button: 0 0 0 0 0 0 0 0 | # | 0xff000040: -7 , 18 | Wheel: 0 | X: -7 | Y: 18 | ||
#00 f9 12 00 f9 2f 01 | ||
print(mx.filter_message_to_host(b'\x00\xf9\x12\x00\xf9\x2f\x01')==b'\xa1\x03\x00\x00\xf9\xff\x12\x00\x00') | ||
|
||
# Button: 1 1 0 0 0 0 0 0 | # | 0xff000040: 0 , 0 | Wheel: 0 | X: 0 | Y: 0 | ||
#03 00 00 00 00 00 00 | ||
print(mx.filter_message_to_host(b'\x03\x00\x00\x00\x00\x00\x00')==b'\xa1\x03\x03\x00\x00\x00\x00\x00\x00') | ||
|
||
# Button: 0 0 0 0 0 0 0 0 | # | 0xff000040: 0 , 0 | Wheel: -1 | X: 0 | Y: 0 | ||
#00 00 00 ff 00 00 00 | ||
print(mx.filter_message_to_host(b'\x00\x00\x00\xff\x00\x00\x00')==b'\xa1\x03\x00\x00\x00\x00\x00\x00\xff') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I don't think this approach is sustainable. I think we can configure these automatically (#23). If you want to give this a go, I'm happy to work on it with you.