analgauge.py

changeset 6
b84252fe69c6
parent 4
99a5439f349f
equal deleted inserted replaced
5:06ccfef112fc 6:b84252fe69c6
1 """
2 Simple CPU load Display
3
4 On Linux simply run with
5 python analgauge.py &
6
7 On Windows:
8 Make sure to install libusb-win32-devel-filter-1.2.6.0.exe
9 from here: https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/
10 Then assign a filter to the connected device matching VENDOR_ID and PRODUCT_ID
11
12 pythonw.exe analgauge.py
13 """
1 import usb.core 14 import usb.core
2 from psutil import cpu_percent 15 from psutil import cpu_percent
3 from time import sleep 16 from time import sleep
4 from random import random 17 from random import random
5 from sys import exit 18 from sys import exit, platform
6 19
7 #VALUE_MIN = 0x00 # TODO 20 #VALUE_MIN = 0x00 # TODO
8 VALUE_MAX = 0x7B 21 VALUE_MAX = 0x78
9 22
10 VENDOR_ID = 0x16c0 23 VENDOR_ID = 0x16c0
11 PRODUCT_ID = 0x05df 24 PRODUCT_ID = 0x05df
12 25
13 class AnalGauge: 26 class AnalGauge:
17 idProduct = PRODUCT_ID 30 idProduct = PRODUCT_ID
18 ) 31 )
19 if not self.dev: 32 if not self.dev:
20 print "AnalGauge Device not found!" 33 print "AnalGauge Device not found!"
21 exit(1) 34 exit(1)
35 self.dev.set_configuration()
22 36
23 def update(self, d): 37 def update(self, d):
24 try: 38 try:
25 data = [int(d)] 39 data = [int(d)]
26 result = self.dev.ctrl_transfer( 40 result = self.dev.ctrl_transfer(
27 0x21, 0x9, 41 0x21, 0x9,
28 wValue = 0x200, wIndex = 0x00, 42 wValue = 0x200, wIndex = 0x00,
29 data_or_wLength = data 43 data_or_wLength = data
30 ) 44 )
31 except usb.core.USBError, e: 45 except usb.core.USBError, e:
32 self.dev.detach_kernel_driver(0) 46 if platform == "linux":
47 self.dev.detach_kernel_driver(0)
48 else:
49 exit(1)
33 print(e) 50 print(e)
34 51
35 if __name__ == "__main__": 52 if __name__ == "__main__":
36 g = AnalGauge() 53 g = AnalGauge()
37 54

mercurial