forked from lubosz/wacom-utility
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wacom_identify.py
39 lines (34 loc) · 1.11 KB
/
wacom_identify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Identifies wacom tablet model
from wacom_data import tabletidentities
import os
class TabletIdClass:
def __init__(self, Cloak=""):
self.TabletIds = tabletidentities()
def Identify(self, Cloak=""):
if Cloak != "":
self.Data = ["iProduct " + Cloak]
else:
#self.Data = os.popen("lsusb -v | grep 'iProduct'").readlines()
self.Data = os.popen("lsusb").readlines()
self.Tablets = []
for item in self.Data:
if item.count("iProduct"): # Identify by model name
model = item.split(" ")[-1].replace("\n","")
tablet = self.IdentifyByModel(model)
if tablet:
self.Tablets.append(tablet)
else: # Identify by USB device code (more reliable)
code = item.split(" ")[5].split(":")
tablet = self.IdentifyByUSBId(code[0], code[1])
if tablet:
self.Tablets.append(tablet)
return self.Tablets
def IdentifyByModel(self,Model):
for item in self.TabletIds.Tablets:
if item.Model == Model:
return item
def IdentifyByUSBId(self,VendId, DevId):
if int(VendId,16) == 0x56a:
for item in self.TabletIds.Tablets:
if item.ProductId == int(DevId,16):
return item