From 9f81067d7d56c44e7fa8912e005a4e8537be164a Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 16 Nov 2021 22:57:09 +0000 Subject: [PATCH] Fix Pi keyboard an mouse events --- hardware/PiGpio/nrgpio.py | 23 +++++++++-------------- hardware/PiGpio/package.json | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/hardware/PiGpio/nrgpio.py b/hardware/PiGpio/nrgpio.py index 4b5b9875..4bfb605f 100755 --- a/hardware/PiGpio/nrgpio.py +++ b/hardware/PiGpio/nrgpio.py @@ -171,24 +171,19 @@ if len(sys.argv) > 2: data = 0 elif cmd == "mouse": # catch mice button events - file = open( "/dev/input/mice", "rb" ) + f = open( "/dev/input/mice", "rb" ) oldbutt = 0 - def getMouseEvent(): - global oldbutt - global pin - buf = file.read(3) - pin = pin & 0x07 - button = ord( buf[0] ) & pin # mask out just the required button(s) - if button != oldbutt: # only send if changed - oldbutt = button - print(button) - while True: try: - getMouseEvent() + buf = f.read(3) + pin = pin & 0x07 + button = struct.unpack('3b',buf)[0] & pin # mask out just the required button(s) + if button != oldbutt: # only send if changed + oldbutt = button + print(button) except: - file.close() + f.close() sys.exit(0) elif cmd == "kbd": # catch keyboard button events @@ -196,7 +191,7 @@ if len(sys.argv) > 2: while not os.path.isdir("/dev/input/by-path"): sleep(10) infile = subprocess.check_output("ls /dev/input/by-path/ | grep -m 1 'kbd'", shell=True).strip() - infile_path = "/dev/input/by-path/" + infile + infile_path = "/dev/input/by-path/" + infile.decode("utf-8") EVENT_SIZE = struct.calcsize('llHHI') file = open(infile_path, "rb") event = file.read(EVENT_SIZE) diff --git a/hardware/PiGpio/package.json b/hardware/PiGpio/package.json index 75a2d491..787f300b 100644 --- a/hardware/PiGpio/package.json +++ b/hardware/PiGpio/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-pi-gpio", - "version": "2.0.0", + "version": "2.0.1", "description": "The basic Node-RED node for Pi GPIO", "dependencies" : { },