analgauge.py

Thu, 16 Feb 2017 14:50:25 +0100

author
mbayer
date
Thu, 16 Feb 2017 14:50:25 +0100
changeset 3
93fe2226cbc8
parent 1
31032bc7b0e6
child 4
99a5439f349f
permissions
-rw-r--r--

Added schematics and PCB layout

1
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
1 import usb.core
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
2 from psutil import cpu_percent
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
3
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
4 VALUE_MIN = 0x00
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
5 VALUE_MAX = 0x88
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
6
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
7 VENDOR_ID = 0x16c0
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
8 PRODUCT_ID = 0x05df
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
9
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
10 class AnalGauge:
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
11 def __init__(self):
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
12 self.dev = usb.core.find(
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
13 idVendor = VENDOR_ID,
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
14 idProduct = PRODUCT_ID
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
15 )
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
16
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
17 def update(self, d):
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
18 try:
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
19 data = [int(d)]
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
20 result = self.dev.ctrl_transfer(
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
21 0x21, 0x9,
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
22 wValue = 0x200, wIndex = 0x00,
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
23 data_or_wLength = data
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
24 )
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
25 except usb.core.USBError, e:
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
26 self.dev.detach_kernel_driver(0)
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
27 print(e)
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
28
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
29 if __name__ == "__main__":
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
30 g = AnalGauge()
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
31 while True:
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
32 pct = cpu_percent(interval=1)
31032bc7b0e6 added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
33 g.update((VALUE_MAX * pct)/100)

mercurial