Merged better startup routine
This commit is contained in:
parent
9857a45a8a
commit
97b7335784
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]?
|
||||
|
|
Loading…
Reference in New Issue