Small cleanups in Device
This commit is contained in:
parent
8d3c89076d
commit
3b312def0d
|
@ -13,11 +13,6 @@ var EventEmitter = require('events').EventEmitter;
|
|||
var Logger = require('./logger'),
|
||||
Utils = require('./utils');
|
||||
|
||||
// The Artoo::Device class represents the interface to
|
||||
// a specific individual hardware devices. Examples would be a digital
|
||||
// thermometer connected to an Arduino, or a Sphero's accelerometer
|
||||
var Device;
|
||||
|
||||
// Public: Creates a new Device
|
||||
//
|
||||
// opts - object containing Device params
|
||||
|
@ -28,7 +23,7 @@ var Device;
|
|||
// driver - string name of the module the device driver logic lives in
|
||||
//
|
||||
// Returns a new Device
|
||||
module.exports = Device = function Device(opts) {
|
||||
var Device = module.exports = function Device(opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
|
@ -36,14 +31,13 @@ module.exports = Device = function Device(opts) {
|
|||
this.halt = Utils.bind(this.halt, this);
|
||||
this.start = Utils.bind(this.start, this);
|
||||
|
||||
this.self = this;
|
||||
this.robot = opts.robot;
|
||||
this.name = opts.name;
|
||||
this.pin = opts.pin;
|
||||
this.connection = this.determineConnection(opts.connection) || this.defaultConnection();
|
||||
this.driver = this.initDriver(opts);
|
||||
|
||||
Utils.proxyFunctionsToObject(this.driver.commands, this.driver, this.self);
|
||||
Utils.proxyFunctionsToObject(this.driver.commands, this.driver, this);
|
||||
};
|
||||
|
||||
Utils.subclass(Device, EventEmitter);
|
||||
|
@ -89,11 +83,11 @@ Device.prototype.toJSON = function() {
|
|||
|
||||
// Public: Retrieves the connections from the parent Robot instances
|
||||
//
|
||||
// c - name of the connection to fetch
|
||||
// conn - name of the connection to fetch
|
||||
//
|
||||
// Returns a Connection instance
|
||||
Device.prototype.determineConnection = function(c) {
|
||||
if (c) { return this.robot.connections[c]; }
|
||||
Device.prototype.determineConnection = function(conn) {
|
||||
return this.robot.connections[conn];
|
||||
};
|
||||
|
||||
// Public: Returns a default Connection to use
|
||||
|
@ -117,7 +111,10 @@ Device.prototype.defaultConnection = function() {
|
|||
//
|
||||
// Returns the set-up driver
|
||||
Device.prototype.initDriver = function(opts) {
|
||||
if (opts == null) { opts = {}; }
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
|
||||
Logger.debug("Loading driver '" + opts.driver + "'.");
|
||||
return this.robot.initDriver(opts.driver, this.self, opts);
|
||||
return this.robot.initDriver(opts.driver, this, opts);
|
||||
};
|
||||
|
|
|
@ -29,10 +29,6 @@ describe("Device", function() {
|
|||
});
|
||||
|
||||
describe("constructor", function() {
|
||||
it("sets @self as a circular reference", function() {
|
||||
expect(device.self).to.be.eql(device);
|
||||
});
|
||||
|
||||
it("sets @robot to the passed robot", function() {
|
||||
expect(device.robot).to.be.eql(robot);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue