Add working event and status to robot
This commit is contained in:
parent
e59f8f23cc
commit
cebb157704
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var Async, namespace,
|
var Async, EventEmitter, namespace,
|
||||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
__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; },
|
||||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||||
|
|
||||||
require('./cylon');
|
require('./cylon');
|
||||||
|
@ -31,10 +33,14 @@
|
||||||
|
|
||||||
Async = require("async");
|
Async = require("async");
|
||||||
|
|
||||||
|
EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
namespace('Cylon', function() {
|
namespace('Cylon', function() {
|
||||||
return this.Robot = (function() {
|
return this.Robot = (function(_super) {
|
||||||
var klass;
|
var klass;
|
||||||
|
|
||||||
|
__extends(Robot, _super);
|
||||||
|
|
||||||
klass = Robot;
|
klass = Robot;
|
||||||
|
|
||||||
function Robot(opts) {
|
function Robot(opts) {
|
||||||
|
@ -61,6 +67,7 @@
|
||||||
this.adaptors = {};
|
this.adaptors = {};
|
||||||
this.drivers = {};
|
this.drivers = {};
|
||||||
this.commands = [];
|
this.commands = [];
|
||||||
|
this.running = false;
|
||||||
this.registerAdaptor("./test/loopback", "loopback");
|
this.registerAdaptor("./test/loopback", "loopback");
|
||||||
this.registerAdaptor("./test/test-adaptor", "test");
|
this.registerAdaptor("./test/test-adaptor", "test");
|
||||||
this.registerDriver("./test/ping", "ping");
|
this.registerDriver("./test/ping", "ping");
|
||||||
|
@ -149,7 +156,10 @@
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return this.startConnections(function() {
|
return this.startConnections(function() {
|
||||||
return _this.robot.startDevices(function() {
|
return _this.robot.startDevices(function() {
|
||||||
return _this.robot.work.call(_this.robot, _this.robot);
|
_this.robot.work.call(_this.robot, _this.robot);
|
||||||
|
_this.running = true;
|
||||||
|
Logger.info("Working...");
|
||||||
|
return _this.robot.emit('working');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -275,7 +285,7 @@
|
||||||
|
|
||||||
return Robot;
|
return Robot;
|
||||||
|
|
||||||
})();
|
})(EventEmitter);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = Cylon.Robot;
|
module.exports = Cylon.Robot;
|
||||||
|
|
|
@ -19,11 +19,12 @@ require './digital-pin'
|
||||||
namespace = require 'node-namespace'
|
namespace = require 'node-namespace'
|
||||||
|
|
||||||
Async = require "async"
|
Async = require "async"
|
||||||
|
EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
# A Robot is the primary interface for interacting with a collection of physical
|
# A Robot is the primary interface for interacting with a collection of physical
|
||||||
# computing capabilities.
|
# computing capabilities.
|
||||||
namespace 'Cylon', ->
|
namespace 'Cylon', ->
|
||||||
class @Robot
|
class @Robot extends EventEmitter
|
||||||
klass = this
|
klass = this
|
||||||
|
|
||||||
# Public: Creates a new Robot
|
# Public: Creates a new Robot
|
||||||
|
@ -58,6 +59,7 @@ namespace 'Cylon', ->
|
||||||
@adaptors = {}
|
@adaptors = {}
|
||||||
@drivers = {}
|
@drivers = {}
|
||||||
@commands = []
|
@commands = []
|
||||||
|
@running = false
|
||||||
|
|
||||||
@registerAdaptor "./test/loopback", "loopback"
|
@registerAdaptor "./test/loopback", "loopback"
|
||||||
@registerAdaptor "./test/test-adaptor", "test"
|
@registerAdaptor "./test/test-adaptor", "test"
|
||||||
|
@ -130,6 +132,9 @@ namespace 'Cylon', ->
|
||||||
@startConnections =>
|
@startConnections =>
|
||||||
@robot.startDevices =>
|
@robot.startDevices =>
|
||||||
@robot.work.call(@robot, @robot)
|
@robot.work.call(@robot, @robot)
|
||||||
|
@running = true
|
||||||
|
Logger.info "Working..."
|
||||||
|
@robot.emit 'working'
|
||||||
|
|
||||||
# Public: Starts the Robot's connections and triggers a callback
|
# Public: Starts the Robot's connections and triggers a callback
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue