From 8717ea5f98a463f23270a7be3574fe97bbd16e3b Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Sun, 17 Nov 2013 23:18:47 -0600 Subject: [PATCH] Updated examples for Dreamforce 2013 --- examples/salesforce.coffee | 5 +++-- examples/sf-sphero.coffee | 46 +++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/examples/salesforce.coffee b/examples/salesforce.coffee index dd1e6f9..4e2b48a 100644 --- a/examples/salesforce.coffee +++ b/examples/salesforce.coffee @@ -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() diff --git a/examples/sf-sphero.coffee b/examples/sf-sphero.coffee index a974de3..c0b49d7 100644 --- a/examples/sf-sphero.coffee +++ b/examples/sf-sphero.coffee @@ -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()