aboutsummaryrefslogtreecommitdiffhomepage
path: root/Stomps/read_stomp.py
diff options
context:
space:
mode:
Diffstat (limited to 'Stomps/read_stomp.py')
-rw-r--r--Stomps/read_stomp.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/Stomps/read_stomp.py b/Stomps/read_stomp.py
index 516db24..65dcdae 100644
--- a/Stomps/read_stomp.py
+++ b/Stomps/read_stomp.py
@@ -1,8 +1,15 @@
+# Quick and simple Python 2 script to read the raw bytes,
+# from a stomp device on the Quad Cortex.
+
+from datetime import datetime
+
class StompEvent:
def __init__(self, raw_bytes):
self.raw_bytes = raw_bytes
self.action = "unknown"
self.value = "unknown"
+ self.system_epoch = datetime.now().strftime("%s")
+ self.system_datetime = datetime.now()
self.decode_bytes()
def print_bytes(self):
@@ -13,15 +20,20 @@ class StompEvent:
print '---'*32
def decode_bytes(self):
+ self.decode_action()
+ self.decode_value()
+ self.decode_time()
+
+ def decode_action(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"
+ def decode_value(self):
+ value_byte = self.raw_bytes[12].encode('hex')
if(value_byte == "00"):
self.value = "released"
elif(value_byte == "01"):
@@ -32,8 +44,18 @@ class StompEvent:
elif(value_byte == "ff"):
self.value = "counter clock"
+ def decode_time(self):
+ # the first 4 bytes form the time
+ time_bytes = self.raw_bytes[0:4]
+ time_bytes.reverse()
+ time_hex = ""
+ for i in range(len(time_bytes)):
+ time_hex = time_hex + time_bytes[i].encode('hex')
+ self.epoch = int(time_hex, 16)
+ self.date_time = datetime.fromtimestamp(self.epoch)
+
def __str__(self):
- return "Action: " + self.action + " | Value: " + self.value
+ return "Action: " + self.action + "\nValue: " + self.value + "\nEpoch: " + str(self.epoch) + "\nDatetime: " + str(self.date_time)
with open('/dev/zencoder/knob_stomp2', 'rb') as file:
byte_buffer = []