Merge pull request #8 from hybridgroup/event-triggering-fix

Fixes issue with events not being triggered in drivers because .start wa...
This commit is contained in:
Ron Evans 2013-10-25 18:08:47 -07:00
commit 9bfd8ce57d
6 changed files with 48 additions and 4 deletions

3
dist/device.js vendored
View File

@ -34,7 +34,8 @@
}
Device.prototype.start = function() {
return Logger.info("started");
Logger.info("Starting driver " + this.driver.name);
return this.driver.start();
};
Device.prototype.determineConnection = function(c) {

1
dist/robot.js vendored
View File

@ -114,6 +114,7 @@
for (n in _ref) {
device = _ref[n];
Logger.info("Starting device '" + device.name + "'...");
device.start();
_results.push(this[device.name] = device);
}
return _results;

View File

@ -0,0 +1,34 @@
spheron = require('spheron')
sphero = spheron.sphero()
spheroPort = '/dev/rfcomm0'
COLORS = spheron.toolbelt.COLORS
sphero.on('open', ->
console.log('EVENT OPEN!')
sphero.configureCollisionDetection(0x01, 0x20, 0x20, 0x20, 0x20, 0x50)
sphero.setRGB(COLORS.GREEN, false)
)
sphero.on('close', ->
console.log('EVENT CLOSE!')
)
sphero.on('end', ->
console.log('EVENT END!')
)
sphero.on('error', ->
console.log('EVENT ERROR!')
)
sphero.on('notification', (packet) ->
console.log('Packet contents:')
console.log(packet)
)
sphero.on('message', (packet) ->
console.log('Packet contents:')
console.log(packet)
)
sphero.open(spheroPort)

View File

@ -8,14 +8,20 @@ Cylon.robot
name: 'sphero', driver: 'sphero'
work: (me) ->
me.sphero.on 'connect', ->
Logger.info 'party started...'
me.sphero.on('connect', ->
Logger.info('Setting up Collision Detection...')
me.sphero.detectCollisions()
me.sphero.setRGB(0x00FF00)
)
me.sphero.on 'message', (data) ->
me.sphero.setRGB(0x0000FF)
Logger.info 'message:'
Logger.info data
me.sphero.on 'notification', (data) ->
me.sphero.setRGB(0xFF0000)
Logger.info 'notification:'
Logger.info data

View File

@ -21,7 +21,8 @@ module.exports = class Device extends EventEmitter
@addCommands(@driver)
start: ->
Logger.info "started"
Logger.info "Starting driver #{ @driver.name }"
@driver.start()
determineConnection: (c) ->
@robot.connections[c] if c

View File

@ -67,6 +67,7 @@ module.exports = class Robot
Logger.info "Starting devices..."
for n, device of @devices
Logger.info "Starting device '#{ device.name }'..."
device.start()
this[device.name] = device
requireAdaptor: (adaptorName, connection) ->