Thu, 16 Feb 2017 16:24:25 +0100
calibration tests added
import usb.core from psutil import cpu_percent from time import sleep from random import random from sys import exit #VALUE_MIN = 0x00 # TODO VALUE_MAX = 0x7B VENDOR_ID = 0x16c0 PRODUCT_ID = 0x05df class AnalGauge: def __init__(self): self.dev = usb.core.find( idVendor = VENDOR_ID, idProduct = PRODUCT_ID ) if not self.dev: print "AnalGauge Device not found!" exit(1) def update(self, d): try: data = [int(d)] result = self.dev.ctrl_transfer( 0x21, 0x9, wValue = 0x200, wIndex = 0x00, data_or_wLength = data ) except usb.core.USBError, e: self.dev.detach_kernel_driver(0) print(e) if __name__ == "__main__": g = AnalGauge() #g.update(VALUE_MAX) #exit() #while True: # g.update(random() * VALUE_MAX) # sleep(0.5) while True: pct = cpu_percent(interval=1) g.update((VALUE_MAX * pct)/100)