Add function to dynamically start devices
This commit is contained in:
parent
4ec19961f8
commit
8921e902eb
33
lib/robot.js
33
lib/robot.js
|
@ -315,28 +315,41 @@ Robot.prototype.startDevices = function(callback) {
|
|||
|
||||
log("Starting devices.");
|
||||
|
||||
var starters = _.map(this.devices, function(device, name) {
|
||||
this[name] = device;
|
||||
|
||||
var starters = _.map(this.devices, function(device) {
|
||||
return function(cb) {
|
||||
return this.startDevice(device, cb);
|
||||
}.bind(this);
|
||||
}, this);
|
||||
|
||||
return _.parallel(starters, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts a single device on Robot
|
||||
*
|
||||
* @param {Object} device to start
|
||||
* @param {Function} callback function to be triggered after the device is
|
||||
* started
|
||||
* @return {void}
|
||||
*/
|
||||
Robot.prototype.startDevice = function(device, callback) {
|
||||
if (device.started === true) {
|
||||
return cb.call(device);
|
||||
return callback.call(device);
|
||||
}
|
||||
|
||||
var str = "Starting device '" + name + "'";
|
||||
var log = this.log;
|
||||
var str = "Starting device '" + device.name + "'";
|
||||
|
||||
if (device.pin) {
|
||||
str += " on pin " + device.pin;
|
||||
}
|
||||
|
||||
log(str + ".");
|
||||
this[device.name] = device;
|
||||
device.start.call(device, callback);
|
||||
device.started = true;
|
||||
|
||||
return device.start.call(device, cb);
|
||||
};
|
||||
}, this);
|
||||
|
||||
return _.parallel(starters, callback);
|
||||
return device.started;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue