Bladeren bron

add simple script to plot values to shell

Thomas B 3 maanden geleden
bovenliggende
commit
e938119fc2
2 gewijzigde bestanden met toevoegingen van 46 en 0 verwijderingen
  1. 38
    0
      client/fetch.py
  2. 8
    0
      client/plot.sh

+ 38
- 0
client/fetch.py Bestand weergeven

@@ -0,0 +1,38 @@
1
+#!/usr/bin/env python
2
+
3
+import usb.core
4
+import usb.util
5
+import time
6
+
7
+CUSTOM_RQ_ECHO = 0 # send back wValue and wIndex, for testing comms reliability
8
+CUSTOM_RQ_RESET = 1 # reset to bootloader
9
+CUSTOM_RQ_GET = 2 # get ldr value
10
+
11
+def is_target_device(dev):
12
+    if dev.manufacturer == "xythobuz.de" and dev.product == "AutoBrightness":
13
+        return True
14
+    return False
15
+
16
+# find our device
17
+dev = usb.core.find(idVendor=0x16c0, idProduct=0x05dc, custom_match=is_target_device)
18
+
19
+# was it found?
20
+if dev is None:
21
+    raise ValueError('Device not found')
22
+
23
+# configure the device
24
+dev.set_configuration()
25
+
26
+def read_u32(req, a=0, b=0):
27
+    r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, req, a, b, 4)
28
+    return int.from_bytes(r, "little")
29
+
30
+# check for proper connectivity
31
+if read_u32(CUSTOM_RQ_ECHO, 42, 23) != (42 | (23 << 16)):
32
+    raise ValueError("invalid echo response")
33
+
34
+# repeatedly print value
35
+while True:
36
+    r = read_u32(CUSTOM_RQ_GET)
37
+    print(time.time(), ";", r, flush=True)
38
+    time.sleep(0.25)

+ 8
- 0
client/plot.sh Bestand weergeven

@@ -0,0 +1,8 @@
1
+#!/bin/bash
2
+
3
+# https://github.com/tenox7/ttyplot
4
+
5
+# enter script directory
6
+cd "$(dirname "$0")"
7
+
8
+./fetch.py | ttyplot -t "Brightness"

Laden…
Annuleren
Opslaan