Updated examles for salesforce.
This commit is contained in:
parent
756f1e7818
commit
637e326c45
|
@ -19,11 +19,13 @@ Cylon.robot
|
||||||
|
|
||||||
me.salesforce.on('start', () ->
|
me.salesforce.on('start', () ->
|
||||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
||||||
Logger.info "Sphero: #{ data.sobject.Sphero_Name__c }, data Content: #{ data.sobject.Content__c }, SM_Id: #{ data.sobject.Id }"
|
Logger.info "Sphero: #{ data.sobject.Sphero_Name__c }, Bucks: #{ data.sobject.Bucks__c }, SM_Id: #{ data.sobject.Id }"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
every 2.seconds()
|
||||||
# push(apexPath, method, body)
|
# push(apexPath, method, body)
|
||||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Salesforce Bot #2' }\" }"
|
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ i }\" }"
|
||||||
me.salesforce.push('SpheroController', 'POST', toSend)
|
me.salesforce.push('SpheroController', 'POST', toSend)
|
||||||
.start()
|
.start()
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SalesforceRobot
|
||||||
me.salesforce.on('start', () ->
|
me.salesforce.on('start', () ->
|
||||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
||||||
spheroName = data.sobject.Sphero_Name__c
|
spheroName = data.sobject.Sphero_Name__c
|
||||||
Logger.info "Sphero: #{ spheroName }, data Content: #{ data.sobject.Content__c }, SM_Id: #{ data.sobject.Id }"
|
Logger.info "Sphero: #{ spheroName }, data Content: #{ data.sobject.Bucks__c }, SM_Id: #{ data.sobject.Id }"
|
||||||
me.master.findRobot(spheroName, (err, spheroBot) ->
|
me.master.findRobot(spheroName, (err, spheroBot) ->
|
||||||
spheroBot.devices.sphero.setRGB(0x00FF00)
|
spheroBot.devices.sphero.setRGB(0x00FF00)
|
||||||
spheroBot.devices.sphero.roll 90, Math.floor(Math.random() * 360)
|
spheroBot.devices.sphero.roll 90, Math.floor(Math.random() * 360)
|
||||||
|
@ -54,7 +54,7 @@ class SpheroRobot
|
||||||
me.sphero.on 'collision', (data) ->
|
me.sphero.on 'collision', (data) ->
|
||||||
me.sphero.setRGB(0xFF0000, me)
|
me.sphero.setRGB(0xFF0000, me)
|
||||||
me.sphero.stop()
|
me.sphero.stop()
|
||||||
toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'Collision detected' }\" }"
|
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ 'Collision detected' }\" }"
|
||||||
me.master.findRobot('salesforce', (err, sf) ->
|
me.master.findRobot('salesforce', (err, sf) ->
|
||||||
sf.devices.salesforce.push('SpheroController', 'POST', toSend)
|
sf.devices.salesforce.push('SpheroController', 'POST', toSend)
|
||||||
)
|
)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class SalesforceRobot
|
||||||
)
|
)
|
||||||
|
|
||||||
class SpheroRobot
|
class SpheroRobot
|
||||||
totalBucks: 0
|
totalBucks: 1
|
||||||
payingPower: true
|
payingPower: true
|
||||||
|
|
||||||
connection:
|
connection:
|
||||||
|
@ -69,8 +69,11 @@ class SpheroRobot
|
||||||
@payingPower = true
|
@payingPower = true
|
||||||
|
|
||||||
work: (me) ->
|
work: (me) ->
|
||||||
every 1.seconds, () ->
|
every 1.seconds(), () ->
|
||||||
me.totalBucks-- if payingPower and me.totalBucks > 0
|
me.totalBucks-- if payingPower and me.totalBucks > 0
|
||||||
|
if me.totalBucks == 0
|
||||||
|
me.sphero.setRGB(0x0000FF, me)
|
||||||
|
me.sphero.stop()
|
||||||
|
|
||||||
me.sphero.on 'connect', ->
|
me.sphero.on 'connect', ->
|
||||||
Logger.info('Setting up Collision Detection...')
|
Logger.info('Setting up Collision Detection...')
|
||||||
|
@ -80,7 +83,7 @@ class SpheroRobot
|
||||||
me.sphero.roll 90, Math.floor(Math.random() * 360)
|
me.sphero.roll 90, Math.floor(Math.random() * 360)
|
||||||
|
|
||||||
me.sphero.on 'collision', (data) ->
|
me.sphero.on 'collision', (data) ->
|
||||||
me.sphero.setRGB(0xFF0000, me)
|
me.sphero.setRGB(0x0000FF, me)
|
||||||
me.sphero.stop()
|
me.sphero.stop()
|
||||||
me.payingPower = false
|
me.payingPower = false
|
||||||
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ me.totalBucks++ }\" }"
|
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ me.totalBucks++ }\" }"
|
||||||
|
|
Loading…
Reference in New Issue