mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
ee0bd49918
commit
8b31a918a4
@ -218,7 +218,6 @@
|
|||||||
var pinsInUse = {};
|
var pinsInUse = {};
|
||||||
RED.nodes.registerType('rpi-gpio out',{
|
RED.nodes.registerType('rpi-gpio out',{
|
||||||
category: 'Raspberry Pi',
|
category: 'Raspberry Pi',
|
||||||
label: 'Raspberry Pi',
|
|
||||||
color:"#c6dbef",
|
color:"#c6dbef",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: { value:"" },
|
name: { value:"" },
|
||||||
@ -351,7 +350,6 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('rpi-mouse',{
|
RED.nodes.registerType('rpi-mouse',{
|
||||||
category: 'Raspberry Pi',
|
category: 'Raspberry Pi',
|
||||||
label: 'Raspberry Pi',
|
|
||||||
color:"#c6dbef",
|
color:"#c6dbef",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: { value:"" },
|
name: { value:"" },
|
||||||
@ -390,7 +388,6 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('rpi-keyboard',{
|
RED.nodes.registerType('rpi-keyboard',{
|
||||||
category: 'Raspberry Pi',
|
category: 'Raspberry Pi',
|
||||||
label: 'Raspberry Pi',
|
|
||||||
color:"#c6dbef",
|
color:"#c6dbef",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: { value:"" }
|
name: { value:"" }
|
||||||
|
@ -37,8 +37,13 @@ module.exports = function(RED) {
|
|||||||
fs.statSync("/usr/lib/python2.7/site-packages/RPi/GPIO"); // test on Arch
|
fs.statSync("/usr/lib/python2.7/site-packages/RPi/GPIO"); // test on Arch
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
RED.log.warn(RED._("rpi-gpio.errors.libnotfound"));
|
try {
|
||||||
throw "Warning : "+RED._("rpi-gpio.errors.libnotfound");
|
fs.statSync("/usr/lib/python2.7/dist-packages/RPi/GPIO"); // test on Hypriot
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
RED.log.warn(RED._("rpi-gpio.errors.libnotfound"));
|
||||||
|
throw "Warning : "+RED._("rpi-gpio.errors.libnotfound");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +84,7 @@ module.exports = function(RED) {
|
|||||||
node.child.stdout.on('data', function (data) {
|
node.child.stdout.on('data', function (data) {
|
||||||
var d = data.toString().trim().split("\n");
|
var d = data.toString().trim().split("\n");
|
||||||
for (var i = 0; i < d.length; i++) {
|
for (var i = 0; i < d.length; i++) {
|
||||||
if (node.running && node.buttonState !== -1 && !isNaN(Number(d[i]))) {
|
if (node.running && node.buttonState !== -1 && !isNaN(Number(d[i])) && node.buttonState !== d[i]) {
|
||||||
node.send({ topic:"pi/"+node.pin, payload:Number(d[i]) });
|
node.send({ topic:"pi/"+node.pin, payload:Number(d[i]) });
|
||||||
}
|
}
|
||||||
node.buttonState = d[i];
|
node.buttonState = d[i];
|
||||||
|
@ -99,9 +99,9 @@ if len(sys.argv) > 2:
|
|||||||
|
|
||||||
elif cmd == "in":
|
elif cmd == "in":
|
||||||
#print "Initialised pin "+str(pin)+" to IN"
|
#print "Initialised pin "+str(pin)+" to IN"
|
||||||
bounce = int(sys.argv[4])
|
bounce = float(sys.argv[4])
|
||||||
def handle_callback(chan):
|
def handle_callback(chan):
|
||||||
sleep(bounce/1000)
|
sleep(bounce/1000.0)
|
||||||
print GPIO.input(chan)
|
print GPIO.input(chan)
|
||||||
|
|
||||||
if sys.argv[3].lower() == "up":
|
if sys.argv[3].lower() == "up":
|
||||||
@ -112,7 +112,7 @@ if len(sys.argv) > 2:
|
|||||||
GPIO.setup(pin,GPIO.IN)
|
GPIO.setup(pin,GPIO.IN)
|
||||||
|
|
||||||
print GPIO.input(pin)
|
print GPIO.input(pin)
|
||||||
GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce)
|
GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=int(bounce))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user