Update Pi Hardware nodes that call python

Pibrella, PiLiter, PiLcd
This commit is contained in:
Dave Conway-Jones 2015-12-12 16:33:39 +00:00
parent 11dfcd4a46
commit 1a9da583f1
8 changed files with 94 additions and 22 deletions

0
hardware/PiLcd/nrlcd.py Normal file → Executable file
View File

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pilcd",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.",
"dependencies" : {
},

View File

@ -20,7 +20,7 @@ module.exports = function(RED) {
var spawn = require('child_process').spawn;
var fs = require('fs');
var gpioCommand = __dirname + '/nrlcd';
var gpioCommand = __dirname + '/nrlcd.py';
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");

View File

@ -20,7 +20,7 @@ module.exports = function(RED) {
var spawn = require('child_process').spawn;
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio';
var gpioCommand = __dirname+'/nrgpio.py';
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
@ -34,7 +34,7 @@ module.exports = function(RED) {
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-gpio] Error : "+gpioCommand+" needs to be executable.");
throw "Error : nrgpio must to be executable.";
throw "Error : " + gpioCommand + " must to be executable.";
}
function PiLiter(n) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-piliter",
"version" : "0.0.7",
"version" : "0.0.8",
"description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.",
"dependencies" : {
},

View File

@ -20,7 +20,7 @@ module.exports = function(RED) {
var spawn = require('child_process').spawn;
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio';
var gpioCommand = __dirname+'/nrgpio.py';
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pibrella specific node.");
@ -34,7 +34,7 @@ module.exports = function(RED) {
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-pibrella] Error : "+gpioCommand+" needs to be executable.");
throw "Error : nrgpio must to be executable.";
throw "Error : " + gpioCommand + " must to be executable.";
}
var pinsInUse = {};

100
hardware/Pibrella/nrgpio.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/python
#
# Copyright 2014 IBM Corp.
#
@ -18,6 +19,10 @@ import sys
bounce = 20 # bounce time in mS to apply
if sys.version_info >= (3,0):
print("Sorry - currently only configured to work with python 2.x")
sys.exit(1)
if len(sys.argv) > 1:
cmd = sys.argv[1].lower()
pin = int(sys.argv[2])
@ -33,17 +38,16 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
p.ChangeDutyCycle(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
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)
@ -52,15 +56,14 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
elif float(data) == 0:
p.stop()
else:
p.start(50)
p.ChangeFrequency(float(data))
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except Exception as ex:
@ -75,11 +78,10 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
data = int(data)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup(pin)
sys.exit(0)
except:
@ -108,18 +110,88 @@ if len(sys.argv) > 1:
while True:
try:
data = raw_input()
if data == "close":
GPIO.cleanup(pin)
if 'close' in data:
sys.exit(0)
except EOFError: # hopefully always caused by us sigint'ing the program
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
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 'close' in data:
sys.exit(0)
data = int(data)
except (EOFError, SystemExit): # 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 == "borg":
#print "Initialised BORG mode - "+str(pin)+
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
r = GPIO.PWM(11, 100)
g = GPIO.PWM(13, 100)
b = GPIO.PWM(15, 100)
r.start(0)
g.start(0)
b.start(0)
while True:
try:
data = raw_input()
if 'close' in data:
sys.exit(0)
c = data.split(",")
r.ChangeDutyCycle(float(c[0]))
g.ChangeDutyCycle(float(c[1]))
b.ChangeDutyCycle(float(c[2]))
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
GPIO.cleanup()
sys.exit(0)
except:
data = 0
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}"
print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}"

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pibrella",
"version" : "0.0.8",
"version" : "0.0.9",
"description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board",
"dependencies" : {
},