node-red-node-pi-gpio 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nrgpio.py +9 -14
- package/package.json +1 -1
package/nrgpio.py
CHANGED
|
@@ -171,24 +171,19 @@ if len(sys.argv) > 2:
|
|
|
171
171
|
data = 0
|
|
172
172
|
|
|
173
173
|
elif cmd == "mouse": # catch mice button events
|
|
174
|
-
|
|
174
|
+
f = open( "/dev/input/mice", "rb" )
|
|
175
175
|
oldbutt = 0
|
|
176
176
|
|
|
177
|
-
def getMouseEvent():
|
|
178
|
-
global oldbutt
|
|
179
|
-
global pin
|
|
180
|
-
buf = file.read(3)
|
|
181
|
-
pin = pin & 0x07
|
|
182
|
-
button = ord( buf[0] ) & pin # mask out just the required button(s)
|
|
183
|
-
if button != oldbutt: # only send if changed
|
|
184
|
-
oldbutt = button
|
|
185
|
-
print(button)
|
|
186
|
-
|
|
187
177
|
while True:
|
|
188
178
|
try:
|
|
189
|
-
|
|
179
|
+
buf = f.read(3)
|
|
180
|
+
pin = pin & 0x07
|
|
181
|
+
button = struct.unpack('3b',buf)[0] & pin # mask out just the required button(s)
|
|
182
|
+
if button != oldbutt: # only send if changed
|
|
183
|
+
oldbutt = button
|
|
184
|
+
print(button)
|
|
190
185
|
except:
|
|
191
|
-
|
|
186
|
+
f.close()
|
|
192
187
|
sys.exit(0)
|
|
193
188
|
|
|
194
189
|
elif cmd == "kbd": # catch keyboard button events
|
|
@@ -196,7 +191,7 @@ if len(sys.argv) > 2:
|
|
|
196
191
|
while not os.path.isdir("/dev/input/by-path"):
|
|
197
192
|
sleep(10)
|
|
198
193
|
infile = subprocess.check_output("ls /dev/input/by-path/ | grep -m 1 'kbd'", shell=True).strip()
|
|
199
|
-
infile_path = "/dev/input/by-path/" + infile
|
|
194
|
+
infile_path = "/dev/input/by-path/" + infile.decode("utf-8")
|
|
200
195
|
EVENT_SIZE = struct.calcsize('llHHI')
|
|
201
196
|
file = open(infile_path, "rb")
|
|
202
197
|
event = file.read(EVENT_SIZE)
|