Correctly set up loopback adaptor
This commit is contained in:
parent
72c357b64b
commit
541d70b66d
|
@ -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
|
||||
|
||||
|
|
|
@ -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]?
|
||||
|
|
Loading…
Reference in New Issue