Thu, 16 Feb 2017 16:24:25 +0100
calibration tests added
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 |
4 | 3 | from time import sleep |
4 | from random import random | |
5 | from sys import exit | |
1
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
6 | |
4 | 7 | #VALUE_MIN = 0x00 # TODO |
8 | VALUE_MAX = 0x7B | |
1
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 | VENDOR_ID = 0x16c0 |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
11 | PRODUCT_ID = 0x05df |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
12 | |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
13 | class AnalGauge: |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
14 | def __init__(self): |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
15 | self.dev = usb.core.find( |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
16 | idVendor = VENDOR_ID, |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
17 | idProduct = PRODUCT_ID |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
18 | ) |
4 | 19 | if not self.dev: |
20 | print "AnalGauge Device not found!" | |
21 | exit(1) | |
1
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
22 | |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
23 | def update(self, d): |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
24 | try: |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
25 | data = [int(d)] |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
26 | result = self.dev.ctrl_transfer( |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
27 | 0x21, 0x9, |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
28 | wValue = 0x200, wIndex = 0x00, |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
29 | data_or_wLength = data |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
30 | ) |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
31 | except usb.core.USBError, e: |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
32 | self.dev.detach_kernel_driver(0) |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
33 | print(e) |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
34 | |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
35 | if __name__ == "__main__": |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
36 | g = AnalGauge() |
4 | 37 | |
38 | #g.update(VALUE_MAX) | |
39 | #exit() | |
40 | ||
41 | #while True: | |
42 | # g.update(random() * VALUE_MAX) | |
43 | # sleep(0.5) | |
44 | ||
1
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
45 | while True: |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
46 | pct = cpu_percent(interval=1) |
31032bc7b0e6
added firmware and python client
Malte Di Donato <mdd@neo-soft.org>
parents:
diff
changeset
|
47 | g.update((VALUE_MAX * pct)/100) |