analgauge.py

changeset 1
31032bc7b0e6
child 4
99a5439f349f
equal deleted inserted replaced
0:9e9b2c78bd31 1:31032bc7b0e6
1 import usb.core
2 from psutil import cpu_percent
3
4 VALUE_MIN = 0x00
5 VALUE_MAX = 0x88
6
7 VENDOR_ID = 0x16c0
8 PRODUCT_ID = 0x05df
9
10 class AnalGauge:
11 def __init__(self):
12 self.dev = usb.core.find(
13 idVendor = VENDOR_ID,
14 idProduct = PRODUCT_ID
15 )
16
17 def update(self, d):
18 try:
19 data = [int(d)]
20 result = self.dev.ctrl_transfer(
21 0x21, 0x9,
22 wValue = 0x200, wIndex = 0x00,
23 data_or_wLength = data
24 )
25 except usb.core.USBError, e:
26 self.dev.detach_kernel_driver(0)
27 print(e)
28
29 if __name__ == "__main__":
30 g = AnalGauge()
31 while True:
32 pct = cpu_percent(interval=1)
33 g.update((VALUE_MAX * pct)/100)

mercurial