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