From 027a82c17eaed69fc475c74afbf48602a8ad2ece Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Fri, 15 Nov 2013 12:00:48 -0600 Subject: [PATCH] Latest cylon example updates --- examples/sf-client.coffee | 2 +- examples/sf-sphero.coffee | 37 ++++++++++++++----------------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/examples/sf-client.coffee b/examples/sf-client.coffee index 69e450d..317a61d 100644 --- a/examples/sf-client.coffee +++ b/examples/sf-client.coffee @@ -6,7 +6,7 @@ faye = require('faye') namespace = require('node-namespace') -namespace 'Cylon.SF', -> +namespace 'SF', -> class @SFClient constructor: (opts) -> @client = null diff --git a/examples/sf-sphero.coffee b/examples/sf-sphero.coffee index 0a7cd14..07b1c91 100644 --- a/examples/sf-sphero.coffee +++ b/examples/sf-sphero.coffee @@ -1,8 +1,7 @@ require '../examples/sf-client' Cylon = require('..') -class SalesForceRobot - +Cylon.robot connection: name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' @@ -10,7 +9,7 @@ class SalesForceRobot name: 'sphero', driver: 'sphero' setupSF: -> - new Cylon.SF.SFClient(sfuser: sfuser, sfpass: sfpass, orgCredentials: orgCreds) + new SF.SFClient(this.sfCreds) sfCreds: { @@ -24,37 +23,29 @@ class SalesForceRobot } work: (me) -> - color = 0x00FF00 - bitFilter = 0xFFFF00 - me.sf = me.setupSF() - mw.sf.authenticate((msg) => - @spheroRoll(0x00FF00) - ) - me.sphero.on('connect', -> Logger.info('Setting up Collision Detection...') me.sphero.detectCollisions() me.sphero.stop() - @spheroRoll(0x00FF00) + me.sphero.setRGB(0x00FF00) + me.sphero.roll 90, Math.floor(Math.random() * 360) ) me.sphero.on 'collision', (data) -> Logger.info 'collision:' - me.sphero.setRGB(0xFF0000) + me.sphero.setRGB(0xFF0000, me) me.sphero.stop() console.log("Collision Data:") - console.log(data) - toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ data }\" }" - @sf.psh(toSend) + console.log(data[0][0]) + toSend = "{ \"identifier\" :\"#{ me.name }\", \"msg\": \"#{ 'hello' }\" }" + me.sf.push(toSend) - spheroRoll: (color) -> - me.sphero.setRGB(color) - me.sphero.roll 90, Math.floor(Math.random() * 360) + me.sf.authenticate((msg) => + Logger.info 'SF Outbound Msg:' + me.sphero.setRGB(0x00FF00) + me.sphero.roll 90, Math.floor(Math.random() * 360) + ) -robot = new SalesForceRobot - -Cylon.robot robot - -Cylon.start() +.start()