Browse Source

moved scripts to .data

Toastie 2 years ago
parent
commit
0574afa9de
2 changed files with 30 additions and 2 deletions
  1. 2 2
      rfidac/Dockerfile
  2. 28 0
      rfidac/data/rfid-test.py

+ 2 - 2
rfidac/Dockerfile

@@ -3,14 +3,14 @@ FROM arm32v6/alpine
 ARG gid_input=${gid_input}
 
 RUN echo "rfidac:x:100:105:RFIC AC,,,:/opt:/sbin/nologin" >> /etc/passwd \
- && apk add --no-cache --update python3 \
+ && apk add --no-cache --update bash python3 \
  && pip3 install --upgrade pip setuptools \
  && apk add --no-cache linux-headers gcc musl-dev python3-dev \
  && pip3 install evdev \
  && apk del linux-headers gcc musl-dev python3-dev \
  && apk add --no-cache mpc
 
-ADD rfid-test.py /opt/rfid-test.py
+ADD ./data/rfid-test.py /opt/rfid-test.py
 
 USER rfidac
 

+ 28 - 0
rfidac/data/rfid-test.py

@@ -0,0 +1,28 @@
+#! /usr/bin/python3
+
+import os
+import subprocess
+import logging
+from shutil import copyfile
+from datetime import datetime
+from evdev import InputDevice, ecodes
+
+logging.basicConfig(level=logging.DEBUG)
+
+def read_rfid():
+    combined_string = ""
+    for event in InputDevice("/dev/input/event0").read_loop():
+        if event.type == ecodes.EV_KEY and event.value == 0:  # value 0 = release key
+            if event.code == 28:  # code 28 = KEY_ENTER
+                return combined_string
+            # [4:5]? .. KEY[] starts with 'KEY_' and we expect one char
+            combined_string += ecodes.KEY[event.code][4:5] 
+
+last_rfid = None
+last_ts = datetime.now()
+while True:
+    rfid = read_rfid()
+    seconds_gone = (datetime.now() - last_ts).total_seconds()
+    print(rfid)
+    last_ts = datetime.now()
+    last_rfid = rfid