diff options
author | xengineering <mail2xengineering@protonmail.com> | 2020-10-29 12:11:32 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2020-10-29 12:15:46 +0100 |
commit | 84b9ddcc2905f5d8667cfef1359b724c23d27365 (patch) | |
tree | 4e5a4c9ba39d8ec8c1a63a2bda4d7e9fc402ae40 /iot_barcode_device_handler | |
parent | 56503ecf9bccd9a318142e2946f84e5f57be5eeb (diff) | |
download | iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.tar iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.tar.zst iot-barcode-scanner-84b9ddcc2905f5d8667cfef1359b724c23d27365.zip |
Setup basic Systemd Units
Diffstat (limited to 'iot_barcode_device_handler')
-rwxr-xr-x | iot_barcode_device_handler | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/iot_barcode_device_handler b/iot_barcode_device_handler new file mode 100755 index 0000000..5c05aab --- /dev/null +++ b/iot_barcode_device_handler @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + + +"""Executable to read the Key Events from the Barcode Scanner (root Priviledges necessary)""" + + +import evdev +import os + +import iot_barcode.config as config + + +def main(): + + try: + # read config + cfg = config.get_config() + fifo_path = cfg["scanner"]["fifo_path"] + event_device_path = cfg["scanner"]["evdev_path"] + + # prepare fifo + os.makedirs(os.path.dirname(fifo_path), exist_ok=True) + os.mkfifo(fifo_path) + + barcode_scanner = evdev.InputDevice(event_device_path) + with barcode_scanner.grab_context(): + for event in barcode_scanner.read_loop(): + if event.type == evdev.ecodes.EV_KEY: + eventdata = evdev.categorize(event) + if eventdata.keystate: + with open(fifo_path, "w") as fifo: + fifo.write(eventdata.keycode) + fifo.flush() + + except KeyboardInterrupt: + pass + + finally: + os.remove(fifo_path) + + +if __name__ == "__main__": + main() |