Updated examples for Dreamforce 2013

This commit is contained in:
Edgar O Silva 2013-11-17 23:18:47 -06:00
parent 637e326c45
commit 8717ea5f98
2 changed files with 33 additions and 18 deletions

View File

@ -24,8 +24,9 @@ Cylon.robot
)
i = 0
every 2.seconds()
# push(apexPath, method, body)
every 2.seconds(), () ->
# push(apexPath, method, body)
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ i }\" }"
me.salesforce.push('SpheroController', 'POST', toSend)
.start()

View File

@ -1,13 +1,6 @@
Cylon = require('..')
bots = [
{ port: '/dev/rfcomm0', name: 'sphy-rgr' },
{ port: '/dev/rfcomm1', name: 'sphy-bpy' }
{ name: 'salesforce' }
]
class SalesforceRobot
connection:
name: 'sfcon',
adaptor: 'force',
@ -23,26 +16,38 @@ class SalesforceRobot
name: 'salesforce', driver: 'force'
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.Bucks__c }, SM_Id: #{ data.sobject.Id }"
bucks = data.sobject.Bucks__c
Logger.info "Sphero: #{ spheroName }, data Bucks: #{ bucks }, 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)
spheroBot.react(spheroBot.devices.sphero)
)
)
)
class SpheroRobot
totalBucks: 1
payingPower: true
connection:
name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0'
name: 'sphero', adaptor: 'sphero'
device:
name: 'sphero', driver: 'sphero'
react: (robot) =>
robot.setRGB(0x00FF00)
robot.roll 90, Math.floor(Math.random() * 360)
@payingPower = true
work: (me) ->
every 1.seconds(), () ->
me.totalBucks-- if payingPower and me.totalBucks > 0
if me.totalBucks == 0
me.sphero.setRGB(0x0000FF, me)
me.sphero.stop()
me.sphero.on 'connect', ->
Logger.info('Setting up Collision Detection...')
@ -52,18 +57,27 @@ class SpheroRobot
me.sphero.roll 90, Math.floor(Math.random() * 360)
me.sphero.on 'collision', (data) ->
me.sphero.setRGB(0xFF0000, me)
me.sphero.setRGB(0x0000FF, me)
me.sphero.stop()
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ 'Collision detected' }\" }"
me.payingPower = false
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ me.totalBucks++ }\" }"
me.master.findRobot('salesforce', (err, sf) ->
sf.devices.salesforce.push('SpheroController', 'POST', toSend)
)
sfRobot = new SalesforceRobot()
sfRobot.name = "salesforce"
Cylon.robot sfRobot
bots = [
{ port: '/dev/rfcomm0', name: 'ROY' },
{ port: '/dev/rfcomm1', name: 'GPG'}
]
for bot in bots
robot = if ( bot.name == 'salesforce' ) then new SalesforceRobot else new SpheroRobot
robot = new SpheroRobot
robot.connection.port = bot.port
robot.name = bot.name
console.log("Name: #{ robot.name }")
Cylon.robot robot
Cylon.start()