Much along the way to adaptor/driver registration and loading
This commit is contained in:
parent
42cd14cf14
commit
132282d4c2
|
@ -0,0 +1,11 @@
|
|||
var cylon = require('..');
|
||||
|
||||
// Initialize the robot
|
||||
var robot = cylon.robot({
|
||||
work: function() {
|
||||
every((1).second(), function() { Logger.info("hello, human!"); });
|
||||
}
|
||||
});
|
||||
|
||||
// start working
|
||||
robot.start();
|
|
@ -13,8 +13,6 @@ Device = require("./device")
|
|||
|
||||
module.exports = class Robot
|
||||
self = this
|
||||
@connections = {}
|
||||
@devices = {}
|
||||
|
||||
constructor: (opts = {}) ->
|
||||
@name = opts.name or @constructor.randomName()
|
||||
|
@ -66,5 +64,20 @@ 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)
|
||||
|
||||
registerAdaptor: (moduleName, adaptorName) ->
|
||||
@adaptors ?= {}
|
||||
return if @adaptors[adaptorName]?
|
||||
@adaptors[adaptorName] = moduleName
|
||||
|
||||
requireDriver: (driverName, device) ->
|
||||
console.log "load the driver"
|
||||
require("cylon-#{@drivers[driverName]}").register(self) unless @drivers[driverName]?
|
||||
require(@drivers[driverName]).driver(driverName)(device: device)
|
||||
|
||||
registerDriver: (moduleName, driverName) ->
|
||||
@drivers ?= {}
|
||||
return if @drivers[driverName]?
|
||||
@drivers[driverName] = moduleName
|
||||
|
|
|
@ -5,6 +5,7 @@ Robot = source("robot")
|
|||
|
||||
describe "Device", ->
|
||||
robot = new Robot(name: 'me')
|
||||
requireDriver = sinon.stub(robot, 'requireDriver')
|
||||
device = new Device(name: "devisive", driver: 'driving', robot: robot)
|
||||
|
||||
it "should belong to a robot", ->
|
||||
|
@ -15,4 +16,6 @@ describe "Device", ->
|
|||
|
||||
it "should use default connection if none specified"
|
||||
it "should use connection if one is specified"
|
||||
it "should have an driver"
|
||||
|
||||
it "should require a driver", ->
|
||||
requireDriver.should.be.called
|
||||
|
|
Loading…
Reference in New Issue