diff --git a/lib/robot.js b/lib/robot.js index 20fd764..ffcf0ff 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -315,30 +315,43 @@ 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) { - if (device.started === true) { - return cb.call(device); - } - - var str = "Starting device '" + name + "'"; - - if (device.pin) { - str += " on pin " + device.pin; - } - - log(str + "."); - device.started = true; - - return device.start.call(device, 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 callback.call(device); + } + + 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.started; +}; + /** * Halts the Robot, attempting to gracefully stop devices and connections. *