diff --git a/nodes/core/hardware/36-rpi-gpio.html b/nodes/core/hardware/36-rpi-gpio.html
index 639e10bdb..31650b7c8 100644
--- a/nodes/core/hardware/36-rpi-gpio.html
+++ b/nodes/core/hardware/36-rpi-gpio.html
@@ -288,3 +288,47 @@
}
});
+
+
+
+
+
+
diff --git a/nodes/core/hardware/36-rpi-gpio.js b/nodes/core/hardware/36-rpi-gpio.js
index 9e8048e03..5ca353aad 100644
--- a/nodes/core/hardware/36-rpi-gpio.js
+++ b/nodes/core/hardware/36-rpi-gpio.js
@@ -38,6 +38,9 @@ module.exports = function(RED) {
throw "Error : nrgpio must to be executable.";
}
+ // the magic to make python print stuff immediately
+ process.env.PYTHONUNBUFFERED = 1;
+
var pinsInUse = {};
var pinTypes = {"out":"digital output", "tri":"input", "up":"input with pull up", "down":"input with pull down", "pwm":"PWM output"};
@@ -209,6 +212,48 @@ module.exports = function(RED) {
});
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
+ function PiMouseNode(n) {
+ RED.nodes.createNode(this,n);
+ this.butt = n.butt || 7;
+ var node = this;
+
+ node.child = spawn(gpioCommand+".py", ["mouse",node.butt]);
+ node.status({fill:"green",shape:"dot",text:"OK"});
+
+ node.child.stdout.on('data', function (data) {
+ data = Number(data);
+ if (data === 0) { node.send({ topic:"pi/mouse", button:data, payload:0 }); }
+ else { node.send({ topic:"pi/mouse", button:data, payload:1 }); }
+ });
+
+ node.child.stderr.on('data', function (data) {
+ if (RED.settings.verbose) { node.log("err: "+data+" :"); }
+ });
+
+ node.child.on('close', function (code) {
+ if (RED.settings.verbose) { node.log("ret: "+code+" :"); }
+ node.child = null;
+ node.running = false;
+ node.status({fill:"red",shape:"circle",text:""});
+ });
+
+ node.child.on('error', function (err) {
+ if (err.errno === "ENOENT") { node.warn('Command not found'); }
+ else if (err.errno === "EACCES") { node.warn('Command not executable'); }
+ else { node.log('error: ' + err); }
+ });
+
+ node.on("close", function() {
+ if (node.child != null) {
+ node.child.kill('SIGINT');
+ node.child = null;
+ }
+ node.status({fill:"red",shape:"circle",text:""});
+ if (RED.settings.verbose) { node.log("end"); }
+ });
+ }
+ RED.nodes.registerType("rpi-mouse",PiMouseNode);
+
RED.httpAdmin.get('/rpi-gpio/:id',function(req,res) {
res.send( JSON.stringify(pitype) );
});
diff --git a/nodes/core/hardware/nrgpio.py b/nodes/core/hardware/nrgpio.py
old mode 100644
new mode 100755
index 122a0f5ee..774dbfcfb
--- a/nodes/core/hardware/nrgpio.py
+++ b/nodes/core/hardware/nrgpio.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
#
# Copyright 2014 IBM Corp.
#
@@ -43,7 +44,7 @@ if len(sys.argv) > 1:
except Exception as ex:
print "bad data: "+data
- if cmd == "buzz":
+ elif cmd == "buzz":
#print "Initialised pin "+str(pin)+" to Buzz"
GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100)
@@ -115,11 +116,56 @@ if len(sys.argv) > 1:
GPIO.cleanup(pin)
sys.exit(0)
+ elif cmd == "byte":
+ #print "Initialised BYTE mode - "+str(pin)+
+ list = [7,11,13,12,15,16,18,22]
+ GPIO.setup(list,GPIO.OUT)
+
+ while True:
+ try:
+ data = raw_input()
+ if data == "close":
+ GPIO.cleanup()
+ sys.exit(0)
+ data = int(data)
+ except EOFError: # hopefully always caused by us sigint'ing the program
+ GPIO.cleanup()
+ sys.exit(0)
+ except:
+ data = 0
+ for bit in range(8):
+ if pin == 1:
+ mask = 1 << (7 - bit)
+ else:
+ mask = 1 << bit
+ GPIO.output(list[bit], data & mask)
+
elif cmd == "rev":
print GPIO.RPI_REVISION
elif cmd == "ver":
print GPIO.VERSION
+ elif cmd == "mouse": # catch mice button events
+ file = 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()
+ except:
+ file.close()
+ sys.exit(0)
+
else:
print "Bad parameters - {in|out|pwm} {pin} {value|up|down}"