Created
May 5, 2024 18:40
-
-
Save zsteva/099512b4765bee9d12fa8b812efcd606 to your computer and use it in GitHub Desktop.
stu-500 converter u tablet
This file contains hidden or 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
| # [email protected] | |
| # 2024-05-05 | |
| from evdev import UInput, AbsInfo, ecodes as e | |
| import hid | |
| tablet_vendor_id = 1386 | |
| tablet_product_id = 161 | |
| WIDTH=10040+1 | |
| HEIGHT=7621+1 | |
| WIDTH_INCH=4.0157 | |
| HEIGHT_INCH=2.9921 | |
| HEIGHT_DPI=int(WIDTH / WIDTH_INCH) | |
| WIDTH_DPI=int(HEIGHT / HEIGHT_INCH) | |
| cap = { | |
| e.EV_KEY: [e.BTN_TOUCH, e.BTN_STYLUS], | |
| e.EV_ABS: [ | |
| (e.ABS_PRESSURE, AbsInfo(value=0, min=0, max=255, resolution=0)), | |
| (e.ABS_X, AbsInfo(value=0, min=0, max=WIDTH, resolution=WIDTH_DPI)), | |
| (e.ABS_Y, AbsInfo(value=0, min=0, max=HEIGHT, resolution=HEIGHT_DPI)) | |
| ] | |
| } | |
| ui = UInput(cap, name='tablet-device') | |
| tablet = hid.device() | |
| tablet.open(tablet_vendor_id, tablet_product_id) | |
| prev_button = 0; | |
| while True: | |
| buf = tablet.read(7) | |
| x = (buf[3] << 8) | buf[4] | |
| y = (buf[5] << 8) | buf[6] | |
| pres = buf[2] | |
| #print("x: ", x, "y:", y, "pres:", pres, buf) | |
| button = 1 if buf[1] > 128 else 0 | |
| ui.write(e.EV_ABS, e.ABS_X, x) | |
| ui.write(e.EV_ABS, e.ABS_Y, y) | |
| if button or prev_button: | |
| ui.write(e.EV_ABS, e.ABS_PRESSURE, pres) | |
| if prev_button != button: | |
| ui.write(e.EV_KEY, e.BTN_TOUCH, button) | |
| prev_button = button | |
| ui.syn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment