178 add litcoffee and js

This commit is contained in:
xixebombilla 2014-02-20 18:29:18 -06:00
parent 07a7a2c137
commit 29101a2890
49 changed files with 53515 additions and 0 deletions

BIN
examples/.DS_Store vendored Normal file

Binary file not shown.

BIN
examples/beaglebone_blink/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'beaglebone',
adaptor: 'beaglebone'
},
device: {
name: 'led',
driver: 'led',
pin: 'P9_12'
},
work: function(my) {
return every(1..second(), function() {
return my.led.toggle();
});
}
}).start();

View File

@ -0,0 +1,30 @@
# Beaglebone Blink
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
# Initialize the robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'beaglebone', adaptor: 'beaglebone'
device:
name: 'led', driver: 'led', pin: 'P9_12'
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: (my) ->
# we do our thing here
every 1.second(), -> my.led.toggle()
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/beaglebone_blinkm/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,35 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'beaglebone',
adaptor: 'beaglebone'
},
device: {
name: 'pixel',
driver: 'blinkm',
pin: 'P9_20'
},
work: function(my) {
var color;
my.pixel.stopScript();
my.pixel.goToRGB(255, 0, 0);
my.pixel.fadeToRGB(0, 255, 0);
my.pixel.fadeToHSB(100, 180, 90);
my.pixel.fadeToRandomRGB(0, 0, 255);
my.pixel.fadeToRandomHSB(100, 180, 90);
my.pixel.playLightScript(1, 0, 0);
my.pixel.stopScript();
my.pixel.setFadeSpeed(50);
my.pixel.setTimeAdjust(50);
color = my.pixel.getRGBColor();
if (typeof err === "undefined" || err === null) {
console.log(color);
}
return my.pixel.getRGBColor(function(err, data) {
if (err == null) {
return console.log(data);
}
});
}
}).start();

View File

@ -0,0 +1,53 @@
# Beaglebone BlinkM
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'beaglebone', adaptor: 'beaglebone'
device:
name: 'pixel', driver: 'blinkm', pin: 'P9_20'
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: (my) ->
# we do our thing here
my.pixel.stopScript()
# You can pass a callback to all blinkm functions as the last param,
# If you do the command would be executed asynchronously.
# For write operations you get an (err) param passed back,
# null/undefined for success, and containing the error y any encountered.
#
# Write BlimkM commands.
my.pixel.goToRGB(255, 0, 0)
my.pixel.fadeToRGB(0, 255, 0)
my.pixel.fadeToHSB(100, 180, 90)
my.pixel.fadeToRandomRGB(0, 0, 255)
my.pixel.fadeToRandomHSB(100, 180, 90)
my.pixel.playLightScript(1, 0, 0)
my.pixel.stopScript()
my.pixel.setFadeSpeed(50)
my.pixel.setTimeAdjust(50)
# For read commands you get (err, data) passed back to the callback,
# data contains the read data buffer, in case of Sync call (no callback)
# you get a regular return.
color = my.pixel.getRGBColor()
console.log(color) unless err?
# Example getting the color usinc async call and a callback
my.pixel.getRGBColor((err, data) ->
console.log(data) unless err?
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/beaglebone_button/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,24 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'beaglebone',
adaptor: 'beaglebone'
},
devices: [
{
name: 'led',
driver: 'led',
pin: 'P9_12'
}, {
name: 'button',
driver: 'button',
pin: 'P9_14'
}
],
work: function(my) {
return my.button.on('push', function() {
return my.led.toggle();
});
}
}).start();

View File

@ -0,0 +1,32 @@
# Beaglebone Button
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
# Initialize the robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'beaglebone', adaptor: 'beaglebone'
devices:
[
{name: 'led', driver: 'led', pin: 'P9_12'},
{name: 'button', driver: 'button', pin: 'P9_14'}
]
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: (my) ->
my.button.on 'push', () -> my.led.toggle()
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/beaglebone_led/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,25 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'beaglebone',
adaptor: 'beaglebone'
},
device: {
name: 'led',
driver: 'led',
pin: 'P9_14'
},
work: function(my) {
var brightness, fade;
brightness = 0;
fade = 5;
return every(0.05.seconds(), function() {
brightness += fade;
my.led.brightness(brightness);
if ((brightness === 0) || (brightness === 255)) {
return fade = -fade;
}
});
}
}).start();

View File

@ -0,0 +1,32 @@
# Beaglebone Led Brightness
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
# Initialize the robot
Cylon.robot
Let's define the connections and devices:
connection: { name: 'beaglebone', adaptor: 'beaglebone' }
device: { name: 'led', driver: 'led', pin: 'P9_14' }
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: (my) ->
# we do our thing here
brightness = 0
fade = 5
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)
fade = -fade if (brightness is 0) or (brightness is 255)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/beaglebone_servo/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,26 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'beaglebone',
adaptor: 'beaglebone'
},
device: {
name: 'servo',
driver: 'servo',
pin: 'P9_14'
},
work: function(my) {
var angle, increment;
angle = 30;
increment = 40;
return every(1..seconds(), function() {
angle += increment;
my.servo.angle(angle);
console.log("Current Angle: " + (my.servo.currentAngle()));
if ((angle === 30) || (angle === 150)) {
return increment = -increment;
}
});
}
}).start();

View File

@ -0,0 +1,50 @@
# Beaglebone Servo
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection: { name: 'beaglebone', adaptor: 'beaglebone' }
device: { name: 'servo', driver: 'servo', pin: 'P9_14' }
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: (my) ->
# Be carefull with your servo angles or you might DAMAGE the servo!
# Cylon uses a 50hz/s (20ms period) frequency and a Duty Cycle
# of 0.5ms to 2.5ms to control the servo angle movement.
#
# This means:
# 1. 0.5ms == 0 degrees
# 2. 1.5ms == 90 degrees
# 3. 2.5ms == 180 degrees
# (It is usually safe to start with a 90 degree angle, 1.5ms duty
# cycle in most servos)
#
# Please review your servo datasheet to make sure of correct
# angle range and the Freq/MS Duty cycle it requires.
# If more servo support is needed leave us a comment, raise an
# issue or help us add more support.
angle = 30
increment = 40
every 1.seconds(), ->
angle += increment
my.servo.angle angle
console.log "Current Angle: #{my.servo.currentAngle()}"
increment = -increment if (angle is 30) or (angle is 150)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,18 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'digispark',
adaptor: 'digispark'
},
device: {
name: 'led',
driver: 'led',
pin: 1
},
work: function(my) {
return every(1..second(), function() {
return my.led.toggle();
});
}
}).start();

View File

@ -0,0 +1,28 @@
# Digispark Blink
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
# Initialize the robot
Cylon.robot
Let's define the connections and devices:
connection: { name: 'digispark', adaptor: 'digispark'}
device: { name: 'led', driver: 'led', pin: 1 }
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: (my) ->
every 1.second(), -> my.led.toggle()
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,33 @@
# Leapmotion Arduino
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connections: [
{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
{ name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
]
devices: [
{ name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' },
{ name: 'led', driver: 'led', pin: 13, connection: 'arduino' }
]
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: (my) ->
my.leapmotion.on 'frame', (frame) ->
if (frame.hands.length > 0) then my.led.turnOn() else my.led.turnOff()
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,31 @@
# MPL115A2
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'mpl115a2', driver: 'mpl115a2'
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: (my) ->
my.mpl115a2.on 'start', ->
my.mpl115a2.getTemperature((data) ->
Logger.info "temperature #{data['temperature']}, pressure #{data['pressure']}"
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/opencv_display_camera/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,29 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'opencv',
adaptor: 'opencv'
},
devices: [
{
name: 'window',
driver: 'window'
}, {
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "" + __dirname + "/examples/opencv/haarcascade_frontalface_alt.xml"
}
],
work: function(my) {
return my.camera.once('cameraReady', function() {
console.log('The camera is ready!');
my.camera.on('frameReady', function(err, im) {
console.log("FRAMEREADY!");
return my.window.show(im, 40);
});
return every(50, my.camera.readFrame);
});
}
}).start();

View File

@ -0,0 +1,60 @@
# Display Camera
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "#{ __dirname }/examples/opencv/haarcascade_frontalface_alt.xml"
} # Default camera is 0
]
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: (my) ->
my.camera.once('cameraReady', ->
console.log('The camera is ready!')
# We listen for frame ready event, when triggered
# we display the frame/image passed as an argument
# and we tell the window to wait 40 milliseconds
my.camera.on('frameReady', (err, im) ->
console.log("FRAMEREADY!")
my.window.show(im, 40)
#my.camera.readFrame()
)
# Here we have two options to start reading frames from
# the camera feed.
# 1. As fast as possible triggering the next frame read
# in the listener for frameReady, if you need video
# as smooth as possible uncomment #my.camera.readFrame()
# in the listener above and the one below this comment.
#
# my.camera.readFrame()
#
# 2. Use an interval of time to try and get aset amount
# of frames per second (FPS), in the next example
# we are trying to get 1 frame every 50 milliseconds
# (20 FPS).
#
every 50, my.camera.readFrame
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

BIN
examples/opencv_display_image/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,27 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'opencv',
adaptor: 'opencv'
},
devices: [
{
name: 'window',
driver: 'window'
}, {
name: 'camera',
driver: 'camera',
camera: 1
}
],
work: function(my) {
return my.camera.on('cameraReady', function() {
console.log('THE CAMERA IS READY!');
my.camera.on('frameReady', function(err, im) {
return my.window.show(im, 5000);
});
return my.camera.readFrame();
});
}
}).start();

View File

@ -0,0 +1,36 @@
# Display Image from Camera
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{ name: 'camera', driver: 'camera', camera: 1 }
]
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: (my) ->
my.camera.on('cameraReady', ->
console.log('THE CAMERA IS READY!')
my.camera.on('frameReady', (err, im) ->
my.window.show(im, 5000)
)
my.camera.readFrame()
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

File diff suppressed because it is too large Load Diff

BIN
examples/opencv_face_detection/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,37 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'opencv',
adaptor: 'opencv'
},
devices: [
{
name: 'window',
driver: 'window'
}, {
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "" + __dirname + "/haarcascade_frontalface_alt.xml"
}
],
work: function(my) {
return my.camera.once('cameraReady', function() {
console.log('The camera is ready!');
my.camera.on('facesDetected', function(err, im, faces) {
var face, _i, _len;
for (_i = 0, _len = faces.length; _i < _len; _i++) {
face = faces[_i];
im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], [0, 255, 0], 2);
}
my.window.show(im, 40);
return my.camera.readFrame();
});
my.camera.on('frameReady', function(err, im) {
return my.camera.detectFaces(im);
});
return my.camera.readFrame();
});
}
}).start();

View File

@ -0,0 +1,74 @@
# Face Detection
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "#{ __dirname }/haarcascade_frontalface_alt.xml"
} # Default camera is 0
]
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: (my) ->
# We setup our face detection once the camera is ready to
# siplays images, we used once to make sure the event listeners
# are only registered once.
my.camera.once('cameraReady', ->
console.log('The camera is ready!')
# We add a listener for the facesDetected event
# here we will get (err, image/frame, faces) params.
# The faces param is an array conaining any face detected
# in the frame (im).
my.camera.on('facesDetected', (err, im, faces) ->
# We loop trhough the faces and manipulate the image
# to display a square in the coordinates for the detected
# faces.
for face in faces
im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], [0,255,0], 2)
# Once the image has been updated with rectangles around
# detected faces we display it in our window.
my.window.show(im, 40)
# After displaying the updated image we trigger another
# frame read to ensure the fastest processing possible.
# We could also use an interval to try and get a set
# amount of processed frames per second, see below.
my.camera.readFrame()
)
# We listen for frameReady event, when triggered
# we start the face detection passsing the frame
# that we jsut got.
my.camera.on('frameReady', (err, im) ->
my.camera.detectFaces(im)
)
# Here we could also try to get a set amount of processed FPS
# by setting an interval and reading frames every set amount
# of time. We could just uncomment the next line and commenting
# out the my.camera.readFrame() in the facesDetected listener
# as well as the one two lines below.
#every 150, my.camera.readFrame
my.camera.readFrame()
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'raspi',
adaptor: 'raspi'
},
device: {
name: 'pixel',
driver: 'blinkm'
},
work: function(my) {
var color;
my.pixel.stopScript();
my.pixel.goToRGB(255, 0, 0);
my.pixel.fadeToRGB(0, 255, 0);
my.pixel.fadeToRGB(0, 0, 255);
color = my.pixel.getRGBColor();
console.log(color);
return my.pixel.getRGBColor(function(err, data) {
if (err == null) {
return console.log(data);
}
});
}
}).start();

View File

@ -0,0 +1,63 @@
# Raspberry Pi BlinkM
First, let's import Cylon:
Cylon = require('../..')
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'raspi', adaptor: 'raspi'
device:
name: 'pixel', driver: 'blinkm'
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: (my) ->
# Before you can use and work with I2C in the raspberry pi you
# need to configure it, follow the instructions to enable it here:
#
# http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
# We first stop the BlinkM light script
my.pixel.stopScript()
# You can pass a callback to all blinkm functions as the last param,
# If you do the command would be executed asynchronously.
# For write operations you get an (err) param passed back,
# null/undefined for success, and containing the error y any encountered.
# BlimkM Write Commands.
my.pixel.goToRGB(255, 0, 0)
my.pixel.fadeToRGB(0, 255, 0)
my.pixel.fadeToRGB(0, 0, 255)
#my.pixel.fadeToHSB(100, 180, 90)
#my.pixel.fadeToRandomRGB(0, 0, 255)
#my.pixel.fadeToRandomHSB(100, 180, 90)
#my.pixel.playLightScript(1, 0, 0)
#my.pixel.stopScript()
#my.pixel.setFadeSpeed(50)
#my.pixel.setTimeAdjust(50)
# For read commands you get (err, data) passed back to the callback,
# data contains the read data buffer, in case of Sync call (no callback)
# you get a regular return with the data buffer.
color = my.pixel.getRGBColor()
console.log(color)
# Example getting the color usinc async call and a callback
my.pixel.getRGBColor((err, data) ->
console.log(data) unless err?
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,46 @@
# Sales Force
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
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
i = 0
every 2.seconds(), () ->
data = JSON.stringify { spheroName: "#{me.name}", bucks: "#{i}" }
me.salesforce.push 'SpheroController', 'POST', data
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,51 @@
# Sales force Client
'use strict'
namespace = require 'node-namespace'
nforce = require 'nforce'
Faye = require 'faye'
namespace 'SF', ->
class @SFClient
constructor: (opts) ->
@client = null
@outboundMessages = []
@sfuser = opts.sfuserjeje ok
@sfpass = opts.sfpass
@orgCreds = opts.orgCredentials
@org = nforce.createConnection @orgCreds
_processOutboundMessages: () ->
# Do work here
_handleStreamingAPI: (outboundCB) ->
client = new Faye.Client("#{@oauth.instance_url}/cometd/28.0")
client.setHeader "Authorization", "OAuth #{@oauth.access_token}"
subscription = client.subscribe '/topic/SpheroMsgOutbound', outboundCB
console.log "Streaming API Connected..."
authenticate: (outboundCB) ->
@org.authenticate {username: @sfuser, password: @sfpass}, (err, _oauth) =>
if err
console.log 'unable to authenticate to sfdc'
console.log err
process.exit 1
else
console.log "authenticated"
@oauth = _oauth
@_handleStreamingAPI outboundCB
@_processOutboundMessages()
push: (msg) ->
jsonString = msg
console.log "SpheroController post msg:"
console.log msg
methodData = {uri:'SpheroController', method: 'POST', body: jsonString}
@org.apexRest methodData, @oauth, (err, resp) =>
console.log if err then err else resp

View File

@ -0,0 +1,82 @@
# 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()

View File

@ -0,0 +1,38 @@
# Sales Force Test
require '../examples/sf-client'
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'
sf = new Cylon.SF.SFClient
sfuser: sfuser
sfpass: sfpass
orgCredentials: orgCreds
cc = 0
sf.authenticate (msg) ->
string = "^ Sphero Name: #{msg.sobject.Sphero_Name__c},"
string += " Msg Content:#{ msg.sobject.Content__c }"
string += ", SM Id:#{ msg.sobject.Id }"
console.log "Printed from callback in client program.program"
console.log string + "\n"
myId = null
message = "hello"
detail = "Some Stuff for details"
setInterval () =>
cc++
myId = cc
data = JSON.stringify { identifier: "run3#{myId}", msg: message }
sf.push data
, 1000

View File

@ -0,0 +1,39 @@
# Skynet Blink
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connections: [
{ name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
# { name: 'skynet', adaptor: 'skynet', uuid: "742401f1-87a4-11e3-834d-670dadc0ddbf", token: "xjq9h3yzhemf5hfrme8y08fh0sm50zfr" }
{ name: 'skynet', adaptor: 'skynet', host: 'localhost', portNumber: 3000, uuid: "18676eb1-9997-11e3-8c2a-f18a07a72684", token: "vbeo289aik65hfr1lns8vst273nmi" }
]
device: { name: 'led', driver: 'led', pin: 13, connection: 'arduino' }
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: (my) ->
Logger.info "connected..."
my.connections['skynet'].on 'message', (channel, data) ->
console.log(data)
data = JSON.parse(data)
if data.red is 'on'
console.log("red on request received from skynet");
my.led.turnOn()
else if data.red is 'off'
console.log("red off request received from skynet");
my.led.turnOff()
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -0,0 +1,150 @@
# Sphero Pebble Sales Force
First, let's import Cylon:
Cylon = require '../..'
Next up, we'll configure the API Cylon will serve, telling it to serve on port
`8080`.
Cylon.api host: '0.0.0.0', port: '8080'
Now that we have Cylon imported, we can start defining our pebble robot
class PebbleRobot
Let's define the connections and devices:
connection: { name: 'pebble', adaptor: 'pebble' }
device: { name: 'pebble', driver: 'pebble' }
message: (robot, msg) =>
robot.message_queue().push(msg)
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.pebble.on 'connect', -> console.log "Connected!"
Let's define our Sales Force 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' }
spheroReport: {}
Tell it what work we want to do:
work: (me) ->
me.salesforce.on 'start', () ->
me.salesforce.subscribe '/topic/SpheroMsgOutbound', (data) ->
name = data.sobject.Sphero_Name__c
bucks = data.sobject.Bucks__c
msg = "Sphero: #{name},"
msg += "data Bucks: #{bucks},"
msg += "SM_Id: #{data.sobject.Id}"
console.log msg
me.master.findRobot name, (err, spheroBot) ->
spheroBot.react spheroBot.devices.sphero
me.spheroReport[name] = bucks
toPebble = ""
toPebble += "#{key}: $#{val}\n" for key, val of me.spheroReport
me.master.findRobot 'pebble', (error, pebbleBot) ->
pebbleBot.message pebbleBot.devices.pebble, toPebble
Let's define our Sphero robot
class SpheroRobot
totalBucks: 1
payingPower: true
connection: { name: 'sphero', adaptor: 'sphero' }
device: { name: 'sphero', driver: 'sphero' }
react: (device) ->
device.setRGB 0x00FF00
device.roll 90, Math.floor(Math.random() * 360)
@payingPower = true
bankrupt: () ->
every 3.seconds(), () =>
if @payingPower and @totalBucks > 0
@totalBucks += -1
if @totalBucks is 0
@sphero.setRGB 0xFF000
@sphero.stop()
changeDirection: () ->
every 1.seconds(), () =>
@sphero.roll 90, Math.floor(Math.random() * 360) if @payingPower
Tell it what work we want to do:
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.bankrupt()
me.changeDirection()
me.sphero.on 'collision', (data) ->
me.sphero.setRGB 0x0000FF
me.sphero.stop()
me.payingPower = false
data = JSON.stringify
spheroName: "#{me.name}",
bucks: "#{me.totalBucks++}"
me.master.findRobot 'salesforce', (err, sf) ->
sf.devices.salesforce.push "SpheroController", "POST", data
salesforceRobot = new SalesforceRobot()
salesforceRobot.name = "salesforce"
Cylon.robot salesforceRobot
pebbleRobot = new PebbleRobot()
pebbleRobot.name = "pebble"
Cylon.robot pebbleRobot
bots = [
{ port: '/dev/tty.Sphero-ROY-AMP-SPP', name: 'ROY' },
{ port: '/dev/tty.Sphero-GBO-AMP-SPP', name: 'GBO'},
{ port: '/dev/tty.Sphero-RRY-AMP-SPP', name: 'RRY'}
]
for bot in bots
robot = new SpheroRobot
robot.connection.port = bot.port
robot.name = bot.name
Cylon.robot robot
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()