Correctly set up loopback adaptor

This commit is contained in:
Andrew Stewart 2013-10-23 10:10:25 -07:00
parent 72c357b64b
commit 541d70b66d
2 changed files with 11 additions and 10 deletions

View File

@ -8,12 +8,13 @@
'use strict';
exports.adaptor = (opts = {}) ->
new Loopback(opts)
module.exports =
adaptor: (opts = {}) ->
new Loopback(opts)
module.exports = class Loopback
class Loopback
self = this
constructor: (opts) ->
@name = opts.name

View File

@ -14,6 +14,7 @@ Device = require("./device")
module.exports = class Robot
self = this
@adaptors = {}
constructor: (opts = {}) ->
@name = opts.name or @constructor.randomName()
@ -67,14 +68,13 @@ module.exports = class Robot
device.start()
self[device.name] = device
requireAdaptor: (adaptorName, connection) ->
require("cylon-#{@adaptors[adaptorName]}").register(self) unless @adaptors[adaptorName]?
require(@adaptors[adaptorName]).adaptor(adaptorName)(connection: connection)
@requireAdaptor = (adaptorName, connection) ->
require("cylon-#{adaptorName}").register(self) unless self.adaptors[adaptorName]?
require(self.adaptors[adaptorName]).adaptor(name: adaptorName).connect(connection: connection)
registerAdaptor: (moduleName, adaptorName) ->
@adaptors ?= {}
return if @adaptors[adaptorName]?
@adaptors[adaptorName] = moduleName
return if self.adaptors[adaptorName]?
self.adaptors[adaptorName] = moduleName
requireDriver: (driverName, device) ->
require("cylon-#{@drivers[driverName]}").register(self) unless @drivers[driverName]?