mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Fix Pi keyboard an mouse events
This commit is contained in:
parent
a5235c7d7d
commit
9f81067d7d
@ -171,24 +171,19 @@ if len(sys.argv) > 2:
|
|||||||
data = 0
|
data = 0
|
||||||
|
|
||||||
elif cmd == "mouse": # catch mice button events
|
elif cmd == "mouse": # catch mice button events
|
||||||
file = open( "/dev/input/mice", "rb" )
|
f = open( "/dev/input/mice", "rb" )
|
||||||
oldbutt = 0
|
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:
|
while True:
|
||||||
try:
|
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:
|
except:
|
||||||
file.close()
|
f.close()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
elif cmd == "kbd": # catch keyboard button events
|
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"):
|
while not os.path.isdir("/dev/input/by-path"):
|
||||||
sleep(10)
|
sleep(10)
|
||||||
infile = subprocess.check_output("ls /dev/input/by-path/ | grep -m 1 'kbd'", shell=True).strip()
|
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')
|
EVENT_SIZE = struct.calcsize('llHHI')
|
||||||
file = open(infile_path, "rb")
|
file = open(infile_path, "rb")
|
||||||
event = file.read(EVENT_SIZE)
|
event = file.read(EVENT_SIZE)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-pi-gpio",
|
"name": "node-red-node-pi-gpio",
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"description": "The basic Node-RED node for Pi GPIO",
|
"description": "The basic Node-RED node for Pi GPIO",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user