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