summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-10-19 17:37:34 +0200
committerxengineering <mail2xengineering@protonmail.com>2020-10-19 17:40:27 +0200
commit8c6cc785137489bb786eb00a895c633a1d51b932 (patch)
tree82878b79699f8f8230743048934646525c8814df
parentdd41aae7363672316851ebbd35961ae2bc89ff4c (diff)
downloadiot-barcode-scanner-8c6cc785137489bb786eb00a895c633a1d51b932.tar
iot-barcode-scanner-8c6cc785137489bb786eb00a895c633a1d51b932.tar.zst
iot-barcode-scanner-8c6cc785137489bb786eb00a895c633a1d51b932.zip
Implement Keymap
-rwxr-xr-x[-rw-r--r--]barcode_transmit_daemon.py21
-rw-r--r--iot_barcode_scanner/static.py14
2 files changed, 28 insertions, 7 deletions
diff --git a/barcode_transmit_daemon.py b/barcode_transmit_daemon.py
index 4edb72d..624550e 100644..100755
--- a/barcode_transmit_daemon.py
+++ b/barcode_transmit_daemon.py
@@ -4,6 +4,7 @@
"""Executable to transmit the Barcode Data to MQTT without root Priviledges"""
+from iot_barcode_scanner.static import KEYMAP
import iot_barcode_scanner.config as config
from iot_barcode_scanner.mqtt import MqttService
@@ -20,15 +21,21 @@ def main():
mqtt_service = MqttService(cfg)
mqtt_service.run()
+ barcode = ""
+
while True:
with open(fifo_path, "r") as fifo:
- text = fifo.read()
- mqtt_service.client.publish(
- topic,
- payload=text,
- qos=0,
- retain=False
- )
+ keycode = fifo.read()
+ character = KEYMAP[keycode]
+ barcode += character
+ if character is "\n":
+ mqtt_service.client.publish(
+ topic,
+ payload=barcode,
+ qos=0,
+ retain=False
+ )
+ barcode = ""
except KeyboardInterrupt:
pass
diff --git a/iot_barcode_scanner/static.py b/iot_barcode_scanner/static.py
index d81b00b..af76683 100644
--- a/iot_barcode_scanner/static.py
+++ b/iot_barcode_scanner/static.py
@@ -4,3 +4,17 @@
CONFIG_PATH = "/etc/xengineering.eu/iot_barcode_scanner/config.json"
+
+KEYMAP = {
+ "KEY_0": "0",
+ "KEY_1": "1",
+ "KEY_2": "2",
+ "KEY_3": "3",
+ "KEY_4": "4",
+ "KEY_5": "5",
+ "KEY_6": "6",
+ "KEY_7": "7",
+ "KEY_8": "8",
+ "KEY_9": "9",
+ "KEY_ENTER": "\n",
+}