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'; 'use strict';
exports.adaptor = (opts = {}) -> module.exports =
new Loopback(opts) adaptor: (opts = {}) ->
new Loopback(opts)
module.exports = class Loopback class Loopback
self = this self = this
constructor: (opts) -> constructor: (opts) ->
@name = opts.name @name = opts.name

View File

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