Extract robot var init into separate function

This commit is contained in:
deadprogram 2015-01-17 15:48:45 -08:00
parent b0b16d6129
commit a7e8caf19d
1 changed files with 22 additions and 26 deletions

View File

@ -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