Update example
This commit is contained in:
parent
6587cd146a
commit
50b4ab3a06
|
@ -3,8 +3,8 @@ Cylon = require('..')
|
|||
Cylon.api host: '0.0.0.0', port: '8080'
|
||||
|
||||
bots = [
|
||||
{ port: '/dev/rfcomm0', name: 'sphero-roy' },
|
||||
{ port: '/dev/rfcomm1', name: 'sphero-gpg' }
|
||||
{ port: '/dev/rfcomm0', name: 'ROY' },
|
||||
{ port: '/dev/rfcomm1', name: 'GPG' }
|
||||
{ port: '', name: 'salesforce' },
|
||||
{ port: '', name: 'pebble' }
|
||||
]
|
||||
|
@ -34,29 +34,37 @@ class SalesforceRobot
|
|||
device:
|
||||
name: 'salesforce', driver: 'force'
|
||||
|
||||
work: (me) ->
|
||||
spheroReport:{}
|
||||
|
||||
work: (me) ->
|
||||
me.salesforce.on('start', () ->
|
||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
||||
spheroName = data.sobject.Sphero_Name__c
|
||||
Logger.info "Sphero: #{ spheroName }, data Content: #{ data.sobject.Content__c }, SM_Id: #{ data.sobject.Id }"
|
||||
counter = data.sobject.Content__c
|
||||
Logger.info "Sphero: #{ spheroName }, data Content: #{ counter }, SM_Id: #{ data.sobject.Id }"
|
||||
me.master.findRobot(spheroName, (err, spheroBot) ->
|
||||
spheroBot.devices.sphero.setRGB(0x00FF00)
|
||||
spheroBot.devices.sphero.roll 90, Math.floor(Math.random() * 360)
|
||||
)
|
||||
me.master.findRobot('pebble', (error, robot) ->
|
||||
robot.devices.pebble.message_queue().push(spheroName)
|
||||
me.spheroReport[spheroName] = counter
|
||||
toPebble = ""
|
||||
for key, val of me.spheroReport
|
||||
toPebble += "#{key}: #{val}\n"
|
||||
me.master.findRobot('pebble', (error, pebbleBot) ->
|
||||
pebbleBot.devices.pebble.message_queue().push(toPebble)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
class SpheroRobot
|
||||
total_collisions: 0
|
||||
connection:
|
||||
name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0'
|
||||
name: 'sphero', adaptor: 'sphero'
|
||||
|
||||
device:
|
||||
name: 'sphero', driver: 'sphero'
|
||||
|
||||
|
||||
work: (me) ->
|
||||
|
||||
me.sphero.on 'connect', ->
|
||||
|
@ -69,7 +77,7 @@ class SpheroRobot
|
|||
me.sphero.on 'collision', (data) ->
|
||||
me.sphero.setRGB(0xFF0000, me)
|
||||
me.sphero.stop()
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Collision detected' }\" }"
|
||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ me.total_collisions++ }\" }"
|
||||
me.master.findRobot('salesforce', (err, sf) ->
|
||||
sf.devices.salesforce.push('SpheroController', 'POST', toSend)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue