mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
more fun trying to close Pi and Arduin nodes async style with done()
(more consistent use of call done().)
This commit is contained in:
parent
7576878ba5
commit
0709a118e3
@ -43,14 +43,15 @@ module.exports = function(RED) {
|
||||
node.log("version "+node.board.boardVersion);
|
||||
});
|
||||
|
||||
node.on('close', function() {
|
||||
node.on('close', function(done) {
|
||||
if (node.board) {
|
||||
try {
|
||||
node.board.close(function() {
|
||||
done();
|
||||
node.log("port closed");
|
||||
});
|
||||
} catch(e) { }
|
||||
}
|
||||
} catch(e) { done(); }
|
||||
} else { done(); }
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("arduino-board",ArduinoNode);
|
||||
|
@ -91,7 +91,7 @@ module.exports = function(RED) {
|
||||
node.running = false;
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
if (RED.settings.verbose) { node.log("closed"); }
|
||||
node.done();
|
||||
if (node.done) { node.done(); }
|
||||
});
|
||||
|
||||
node.child.on('error', function (err) {
|
||||
@ -109,10 +109,11 @@ module.exports = function(RED) {
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
delete pinsInUse[node.pin];
|
||||
if (node.child != null) {
|
||||
node.done = done;
|
||||
node.child.stdin.write(" close "+node.pin);
|
||||
node.child.kill('SIGKILL');
|
||||
}
|
||||
node.done = done;
|
||||
else { done(); }
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
|
||||
@ -173,7 +174,7 @@ module.exports = function(RED) {
|
||||
node.running = false;
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
if (RED.settings.verbose) { node.log("closed"); }
|
||||
node.done();
|
||||
if (node.done) { node.done(); }
|
||||
});
|
||||
|
||||
node.child.on('error', function (err) {
|
||||
@ -191,10 +192,11 @@ module.exports = function(RED) {
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
delete pinsInUse[node.pin];
|
||||
if (node.child != null) {
|
||||
node.done = done;
|
||||
node.child.stdin.write(" close "+node.pin);
|
||||
node.child.kill('SIGKILL');
|
||||
}
|
||||
node.done = done;
|
||||
else { done(); }
|
||||
});
|
||||
|
||||
}
|
||||
@ -237,7 +239,7 @@ module.exports = function(RED) {
|
||||
node.running = false;
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
if (RED.settings.verbose) { node.log("closed"); }
|
||||
node.done();
|
||||
if (node.done) { node.done(); }
|
||||
});
|
||||
|
||||
node.child.on('error', function (err) {
|
||||
@ -249,10 +251,11 @@ module.exports = function(RED) {
|
||||
node.on("close", function(done) {
|
||||
node.status({fill:"red",shape:"circle",text:""});
|
||||
if (node.child != null) {
|
||||
node.done = done;
|
||||
node.child.kill('SIGINT');
|
||||
node.child = null;
|
||||
}
|
||||
node.done = done;
|
||||
else { done(); }
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("rpi-mouse",PiMouseNode);
|
||||
|
@ -140,6 +140,34 @@ if len(sys.argv) > 1:
|
||||
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 data == "close":
|
||||
GPIO.cleanup()
|
||||
sys.exit(0)
|
||||
c = data.split(",")
|
||||
r.ChangeDutyCycle(float(c[0]))
|
||||
g.ChangeDutyCycle(float(c[1]))
|
||||
b.ChangeDutyCycle(float(c[2]))
|
||||
except EOFError: # hopefully always caused by us sigint'ing the program
|
||||
GPIO.cleanup()
|
||||
sys.exit(0)
|
||||
except:
|
||||
data = 0
|
||||
|
||||
elif cmd == "rev":
|
||||
print GPIO.RPI_REVISION
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user