aboutsummaryrefslogtreecommitdiffhomepage
path: root/Stomps/read_stomp.py
diff options
context:
space:
mode:
authorThomas Van Iseghem <[email protected]>2023-09-13 19:07:14 +0200
committerThomas Van Iseghem <[email protected]>2023-09-13 19:07:14 +0200
commit16d990783c9b2367a4854cd539e8efa83668ef69 (patch)
treef614c3100ade4f8cdf0d03bf5aabcf944fc89551 /Stomps/read_stomp.py
parent3f726f67f29ba78ae32bc726611e068c695962b8 (diff)
downloadOpenCortex-16d990783c9b2367a4854cd539e8efa83668ef69.tar.gz
OpenCortex-16d990783c9b2367a4854cd539e8efa83668ef69.zip
Created basic script for reading stomp data traffic + stomp bytes explained
Diffstat (limited to 'Stomps/read_stomp.py')
-rw-r--r--Stomps/read_stomp.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Stomps/read_stomp.py b/Stomps/read_stomp.py
new file mode 100644
index 0000000..516db24
--- /dev/null
+++ b/Stomps/read_stomp.py
@@ -0,0 +1,50 @@
+class StompEvent:
+ def __init__(self, raw_bytes):
+ self.raw_bytes = raw_bytes
+ self.action = "unknown"
+ self.value = "unknown"
+ self.decode_bytes()
+
+ def print_bytes(self):
+ bytes_str = ""
+ for i in range(len(self.raw_bytes)):
+ bytes_str = bytes_str + self.raw_bytes[i].encode('hex') + ' '
+ print bytes_str
+ print '---'*32
+
+ def decode_bytes(self):
+ action_byte_1 = self.raw_bytes[10].encode('hex')
+ action_byte_2 = self.raw_bytes[11].encode('hex')
+ value_byte = self.raw_bytes[12].encode('hex')
+
+ if(action_byte_1 == "11" and action_byte_2 == "01"):
+ self.action = "button"
+ elif(action_byte_1 == "08" and action_byte_2 == "00"):
+ self.action = "rotary"
+
+ if(value_byte == "00"):
+ self.value = "released"
+ elif(value_byte == "01"):
+ if(self.action == "button"):
+ self.value = "pressed"
+ elif(self.action == "rotary"):
+ self.value = "clock wise"
+ elif(value_byte == "ff"):
+ self.value = "counter clock"
+
+ def __str__(self):
+ return "Action: " + self.action + " | Value: " + self.value
+
+with open('/dev/zencoder/knob_stomp2', 'rb') as file:
+ byte_buffer = []
+ while True:
+ byte = file.read(1)
+ if not byte:
+ break
+
+ byte_buffer.append(byte)
+ if len(byte_buffer) is 32:
+ event = StompEvent(byte_buffer)
+ print event
+ event.print_bytes()
+ byte_buffer = [] \ No newline at end of file