Extract robot var init into separate function
This commit is contained in:
parent
b0b16d6129
commit
a7e8caf19d
48
lib/robot.js
48
lib/robot.js
|
@ -27,19 +27,6 @@ var Async = require("async"),
|
|||
// work - work to be performed when the Robot is started
|
||||
//
|
||||
// Returns a new Robot
|
||||
// Example (CoffeeScript):
|
||||
// Cylon.robot
|
||||
// name: "Spherobot!"
|
||||
//
|
||||
// connection:
|
||||
// name: "sphero", adaptor: "sphero", port: "/dev/rfcomm0"
|
||||
//
|
||||
// device:
|
||||
// name: "sphero", driver: "sphero"
|
||||
//
|
||||
// work: (me) ->
|
||||
// Utils.every 1.second(), ->
|
||||
// me.sphero.roll 60, Math.floor(Math.random() * 360//
|
||||
var Robot = module.exports = function Robot(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
|
@ -49,25 +36,14 @@ var Robot = module.exports = function Robot(opts) {
|
|||
"startDevices",
|
||||
"startConnections",
|
||||
"start",
|
||||
"initRobot",
|
||||
"initDevices",
|
||||
"initConnections"
|
||||
];
|
||||
|
||||
_.bindAll(this, methods);
|
||||
|
||||
this.name = opts.name || Robot.randomName();
|
||||
this.connections = {};
|
||||
this.devices = {};
|
||||
this.adaptors = {};
|
||||
this.drivers = {};
|
||||
this.commands = {};
|
||||
this.running = false;
|
||||
this.work = opts.work || opts.play;
|
||||
|
||||
if (!this.work) {
|
||||
this.work = function() { Logger.debug("No work yet."); };
|
||||
}
|
||||
|
||||
this.initRobot(opts);
|
||||
this.initConnections(opts);
|
||||
this.initDevices(opts);
|
||||
|
||||
|
@ -145,6 +121,26 @@ Robot.prototype.connection = function(name, conn) {
|
|||
return this;
|
||||
};
|
||||
|
||||
// Public: Initializes all vars for robot
|
||||
//
|
||||
// opts - options array passed to constructor
|
||||
//
|
||||
// Returns null
|
||||
Robot.prototype.initRobot = function(opts) {
|
||||
this.name = opts.name || Robot.randomName();
|
||||
this.connections = {};
|
||||
this.devices = {};
|
||||
this.adaptors = {};
|
||||
this.drivers = {};
|
||||
this.commands = {};
|
||||
this.running = false;
|
||||
this.work = opts.work || opts.play;
|
||||
|
||||
if (!this.work) {
|
||||
this.work = function() { Logger.debug("No work yet."); };
|
||||
}
|
||||
};
|
||||
|
||||
// Public: Initializes all connections for the robot
|
||||
//
|
||||
// opts - options array passed to constructor
|
||||
|
|
Loading…
Reference in New Issue