Merged better startup routine

This commit is contained in:
deadprogram 2013-10-28 15:31:39 -07:00
parent 9857a45a8a
commit 97b7335784
5 changed files with 16 additions and 18 deletions

2
dist/device.js vendored
View File

@ -10,6 +10,7 @@
(function() { (function() {
'use strict'; 'use strict';
var Device, EventEmitter, var Device, EventEmitter,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -24,6 +25,7 @@
if (opts == null) { if (opts == null) {
opts = {}; opts = {};
} }
this.start = __bind(this.start, this);
this.self = this; this.self = this;
this.robot = opts.robot; this.robot = opts.robot;
this.name = opts.name; this.name = opts.name;

15
dist/robot.js vendored
View File

@ -113,20 +113,17 @@
return Async.parallel(c, cb); return Async.parallel(c, cb);
}; };
Robot.prototype.startDevices = function(cb) { Robot.prototype.startDevices = function(callback) {
var d, device, n, _ref; var device, deviceStarters, n, _ref;
Logger.info("Starting devices..."); Logger.info("Starting devices...");
d = {}; deviceStarters = {};
_ref = this.devices; _ref = this.devices;
for (n in _ref) { for (n in _ref) {
device = _ref[n]; device = _ref[n];
this.robot[device.name] = device; this.robot[n] = device;
d[device.name] = function(callback) { deviceStarters[n] = device.start;
Logger.info("Starting device '" + device.name + "'...");
return device.start(callback);
};
} }
return Async.parallel(d, cb); return Async.parallel(deviceStarters, callback);
}; };
Robot.prototype.requireAdaptor = function(adaptorName, connection) { Robot.prototype.requireAdaptor = function(adaptorName, connection) {

View File

@ -12,6 +12,7 @@ Cylon.robot
] ]
work: (my) -> work: (my) ->
my.button.on 'push', -> my.led.toggle() my.button.on 'pushed', -> Logger.info 'wow' #my.led.toggle()
every 1.second(), -> my.led.toggle()
.start() .start()

View File

@ -21,7 +21,7 @@ module.exports = class Device extends EventEmitter
@driver = @requireDriver(opts.driver) @driver = @requireDriver(opts.driver)
proxyFunctionsToObject @driver.commands(), @driver, this proxyFunctionsToObject @driver.commands(), @driver, this
start: (callback) -> start: (callback) =>
msg = "Starting device '#{ @name }'" msg = "Starting device '#{ @name }'"
msg += " on pin #{@pin}" if @pin? msg += " on pin #{@pin}" if @pin?
Logger.info msg Logger.info msg

View File

@ -68,16 +68,14 @@ module.exports = class Robot
Async.parallel c, cb Async.parallel c, cb
startDevices: (cb) => startDevices: (callback) =>
Logger.info "Starting devices..." Logger.info "Starting devices..."
d = {} deviceStarters = {}
for n, device of @devices for n, device of @devices
@robot[device.name] = device @robot[n] = device
d[device.name] = (callback) -> deviceStarters[n] = device.start
Logger.info "Starting device '#{ device.name }'..."
device.start(callback)
Async.parallel d, cb Async.parallel deviceStarters, callback
requireAdaptor: (adaptorName, connection) -> requireAdaptor: (adaptorName, connection) ->
if @robot.adaptors[adaptorName]? if @robot.adaptors[adaptorName]?