83 lines
2.4 KiB
Plaintext
83 lines
2.4 KiB
Plaintext
![]() |
# Sales Force Shpero
|
||
|
|
||
|
First, let's import Cylon:
|
||
|
|
||
|
Cylon = require '../..'
|
||
|
|
||
|
Now that we have Cylon imported, we can start defining our robot
|
||
|
|
||
|
class SalesforceRobot
|
||
|
|
||
|
Let's define the connections and devices:
|
||
|
|
||
|
connection:
|
||
|
name: 'sfcon'
|
||
|
adaptor: 'force'
|
||
|
sfuser: process.env.SF_USERNAME
|
||
|
sfpass: process.env.SF_SECURITY_TOKEN
|
||
|
orgCreds:
|
||
|
clientId: process.env.SF_CLIENT_ID
|
||
|
clientSecret: process.env.SF_CLIENT_SECRET
|
||
|
redirectUri: 'http://localhost:3000/oauth/_callback'
|
||
|
|
||
|
device: { name: 'salesforce', driver: 'force' }
|
||
|
|
||
|
Now that Cylon knows about the necessary hardware we're going to be using, we'll
|
||
|
tell it what work we want to do:
|
||
|
|
||
|
work: (me) ->
|
||
|
me.salesforce.on 'start', () ->
|
||
|
me.salesforce.subscribe '/topic/SpheroMsgOutbound', (data) ->
|
||
|
msg = "Sphero: #{data.sobject.Sphero_Name__c},"
|
||
|
msg += "Bucks: #{data.sobject.Bucks__c},"
|
||
|
msg += "SM_Id: #{data.sobject.Id}"
|
||
|
|
||
|
console.log msg
|
||
|
|
||
|
me.master.findRobot data.sobject.Sphero_Name__c, (err, spheroBot) ->
|
||
|
spheroBot.react spheroBot.devices.sphero
|
||
|
|
||
|
class SpheroRobot
|
||
|
totalBucks: 0
|
||
|
|
||
|
connection: { name: 'sphero', adaptor: 'sphero' }
|
||
|
|
||
|
device: { name: 'sphero', driver: 'sphero' }
|
||
|
|
||
|
react: (robot) =>
|
||
|
robot.setRGB 0x00FF00
|
||
|
robot.roll 90, Math.floor(Math.random() * 360)
|
||
|
|
||
|
work: (me) ->
|
||
|
me.sphero.on 'connect', ->
|
||
|
console.log 'Setting up Collision Detection...'
|
||
|
me.sphero.detectCollisions()
|
||
|
me.sphero.stop()
|
||
|
me.sphero.setRGB 0x00FF00
|
||
|
me.sphero.roll 90, Math.floor(Math.random() * 360)
|
||
|
|
||
|
me.sphero.on 'collision', (data) ->
|
||
|
me.sphero.setRGB 0x0000FF, me
|
||
|
me.sphero.stop()
|
||
|
|
||
|
data = JSON.stringify
|
||
|
spheroName: "#{me.name}"
|
||
|
bucks: "#{me.totalBucks++}"
|
||
|
|
||
|
me.master.findRobot 'salesforce', (err, sf) ->
|
||
|
sf.devices.salesforce.push 'SpheroController', 'POST', data
|
||
|
|
||
|
sfRobot = new SalesforceRobot()
|
||
|
sfRobot.name = "salesforce"
|
||
|
Cylon.robot sfRobot
|
||
|
|
||
|
spheroRobot = new SpheroRobot()
|
||
|
spheroRobot.name = 'ROY'
|
||
|
spheroRobot.connection.port = '/dev/rfcomm0'
|
||
|
Cylon.robot spheroRobot
|
||
|
|
||
|
Now that our robot knows what work to do, and the work it will be doing that
|
||
|
hardware with, we can start it:
|
||
|
|
||
|
Cylon.start()
|