analgauge.py

changeset 1
31032bc7b0e6
child 4
99a5439f349f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/analgauge.py	Thu Feb 16 14:42:01 2017 +0100
@@ -0,0 +1,33 @@
+import usb.core
+from psutil import cpu_percent
+
+VALUE_MIN = 0x00
+VALUE_MAX = 0x88
+
+VENDOR_ID = 0x16c0
+PRODUCT_ID = 0x05df
+
+class AnalGauge:
+    def __init__(self):
+        self.dev = usb.core.find(
+            idVendor = VENDOR_ID,
+            idProduct = PRODUCT_ID
+        )
+
+    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()
+    while True:
+        pct = cpu_percent(interval=1)
+        g.update((VALUE_MAX * pct)/100)

mercurial