mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Update Pi Hardware nodes that call python
Pibrella, PiLiter, PiLcd
This commit is contained in:
parent
11dfcd4a46
commit
1a9da583f1
0
hardware/PiLcd/nrlcd.py
Normal file → Executable file
0
hardware/PiLcd/nrlcd.py
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-pilcd",
|
"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.",
|
"description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ module.exports = function(RED) {
|
|||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname + '/nrlcd';
|
var gpioCommand = __dirname + '/nrlcd.py';
|
||||||
|
|
||||||
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
||||||
//util.log("Info : Ignoring Raspberry Pi specific node.");
|
//util.log("Info : Ignoring Raspberry Pi specific node.");
|
||||||
|
@ -20,7 +20,7 @@ module.exports = function(RED) {
|
|||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname+'/nrgpio';
|
var gpioCommand = __dirname+'/nrgpio.py';
|
||||||
|
|
||||||
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
||||||
//util.log("Info : Ignoring Raspberry Pi specific node.");
|
//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]) )) {
|
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
|
||||||
util.log("[rpi-gpio] Error : "+gpioCommand+" needs to be executable.");
|
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) {
|
function PiLiter(n) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-piliter",
|
"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.",
|
"description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ module.exports = function(RED) {
|
|||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname+'/nrgpio';
|
var gpioCommand = __dirname+'/nrgpio.py';
|
||||||
|
|
||||||
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
||||||
//util.log("Info : Ignoring Raspberry Pibrella specific node.");
|
//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]) )) {
|
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
|
||||||
util.log("[rpi-pibrella] Error : "+gpioCommand+" needs to be executable.");
|
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 = {};
|
var pinsInUse = {};
|
||||||
|
100
hardware/Pibrella/nrgpio.py
Normal file → Executable file
100
hardware/Pibrella/nrgpio.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Copyright 2014 IBM Corp.
|
# Copyright 2014 IBM Corp.
|
||||||
#
|
#
|
||||||
@ -18,6 +19,10 @@ import sys
|
|||||||
|
|
||||||
bounce = 20 # bounce time in mS to apply
|
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:
|
if len(sys.argv) > 1:
|
||||||
cmd = sys.argv[1].lower()
|
cmd = sys.argv[1].lower()
|
||||||
pin = int(sys.argv[2])
|
pin = int(sys.argv[2])
|
||||||
@ -33,17 +38,16 @@ if len(sys.argv) > 1:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = raw_input()
|
data = raw_input()
|
||||||
if data == "close":
|
if 'close' in data:
|
||||||
GPIO.cleanup(pin)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
p.ChangeDutyCycle(float(data))
|
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)
|
GPIO.cleanup(pin)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print "bad data: "+data
|
print "bad data: "+data
|
||||||
|
|
||||||
if cmd == "buzz":
|
elif cmd == "buzz":
|
||||||
#print "Initialised pin "+str(pin)+" to Buzz"
|
#print "Initialised pin "+str(pin)+" to Buzz"
|
||||||
GPIO.setup(pin,GPIO.OUT)
|
GPIO.setup(pin,GPIO.OUT)
|
||||||
p = GPIO.PWM(pin, 100)
|
p = GPIO.PWM(pin, 100)
|
||||||
@ -52,15 +56,14 @@ if len(sys.argv) > 1:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = raw_input()
|
data = raw_input()
|
||||||
if data == "close":
|
if 'close' in data:
|
||||||
GPIO.cleanup(pin)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif float(data) == 0:
|
elif float(data) == 0:
|
||||||
p.stop()
|
p.stop()
|
||||||
else:
|
else:
|
||||||
p.start(50)
|
p.start(50)
|
||||||
p.ChangeFrequency(float(data))
|
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)
|
GPIO.cleanup(pin)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@ -75,11 +78,10 @@ if len(sys.argv) > 1:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = raw_input()
|
data = raw_input()
|
||||||
if data == "close":
|
if 'close' in data:
|
||||||
GPIO.cleanup(pin)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
data = int(data)
|
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)
|
GPIO.cleanup(pin)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except:
|
except:
|
||||||
@ -108,12 +110,61 @@ if len(sys.argv) > 1:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = raw_input()
|
data = raw_input()
|
||||||
if data == "close":
|
if 'close' in data:
|
||||||
|
sys.exit(0)
|
||||||
|
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
|
||||||
GPIO.cleanup(pin)
|
GPIO.cleanup(pin)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except EOFError: # hopefully always caused by us sigint'ing the program
|
|
||||||
GPIO.cleanup(pin)
|
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)
|
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":
|
elif cmd == "rev":
|
||||||
print GPIO.RPI_REVISION
|
print GPIO.RPI_REVISION
|
||||||
@ -121,5 +172,26 @@ if len(sys.argv) > 1:
|
|||||||
elif cmd == "ver":
|
elif cmd == "ver":
|
||||||
print GPIO.VERSION
|
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:
|
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}"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-pibrella",
|
"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",
|
"description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user