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() {
'use strict';
var Device, EventEmitter,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__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; };
@ -24,6 +25,7 @@
if (opts == null) {
opts = {};
}
this.start = __bind(this.start, this);
this.self = this;
this.robot = opts.robot;
this.name = opts.name;

15
dist/robot.js vendored
View File

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

View File

@ -12,6 +12,7 @@ Cylon.robot
]
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()

View File

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

View File

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