analgauge.py

changeset 4
99a5439f349f
parent 1
31032bc7b0e6
child 6
b84252fe69c6
equal deleted inserted replaced
2:93b48be0aa53 4:99a5439f349f
1 import usb.core 1 import usb.core
2 from psutil import cpu_percent 2 from psutil import cpu_percent
3 from time import sleep
4 from random import random
5 from sys import exit
3 6
4 VALUE_MIN = 0x00 7 #VALUE_MIN = 0x00 # TODO
5 VALUE_MAX = 0x88 8 VALUE_MAX = 0x7B
6 9
7 VENDOR_ID = 0x16c0 10 VENDOR_ID = 0x16c0
8 PRODUCT_ID = 0x05df 11 PRODUCT_ID = 0x05df
9 12
10 class AnalGauge: 13 class AnalGauge:
11 def __init__(self): 14 def __init__(self):
12 self.dev = usb.core.find( 15 self.dev = usb.core.find(
13 idVendor = VENDOR_ID, 16 idVendor = VENDOR_ID,
14 idProduct = PRODUCT_ID 17 idProduct = PRODUCT_ID
15 ) 18 )
19 if not self.dev:
20 print "AnalGauge Device not found!"
21 exit(1)
16 22
17 def update(self, d): 23 def update(self, d):
18 try: 24 try:
19 data = [int(d)] 25 data = [int(d)]
20 result = self.dev.ctrl_transfer( 26 result = self.dev.ctrl_transfer(
26 self.dev.detach_kernel_driver(0) 32 self.dev.detach_kernel_driver(0)
27 print(e) 33 print(e)
28 34
29 if __name__ == "__main__": 35 if __name__ == "__main__":
30 g = AnalGauge() 36 g = AnalGauge()
37
38 #g.update(VALUE_MAX)
39 #exit()
40
41 #while True:
42 # g.update(random() * VALUE_MAX)
43 # sleep(0.5)
44
31 while True: 45 while True:
32 pct = cpu_percent(interval=1) 46 pct = cpu_percent(interval=1)
33 g.update((VALUE_MAX * pct)/100) 47 g.update((VALUE_MAX * pct)/100)

mercurial