Fix JSHint violations in examples

This commit is contained in:
Andrew Stewart 2014-12-13 16:19:25 -08:00
parent 5315c8b9ae
commit 3e960c48a1
25 changed files with 311 additions and 203 deletions

View File

@ -1,13 +1,15 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.api({ Cylon.api({
host: '0.0.0.0', host: "0.0.0.0",
port: '8080' port: "8080"
}); });
var bots = { var bots = {
'Thelma': '/dev/rfcomm0', "Thelma": "/dev/rfcomm0",
'Louise': '/dev/rfcomm1' "Louise": "/dev/rfcomm1"
}; };
Object.keys(bots).forEach(function(name) { Object.keys(bots).forEach(function(name) {
@ -17,11 +19,11 @@ Object.keys(bots).forEach(function(name) {
name: name, name: name,
connections: { connections: {
sphero: { adaptor: 'sphero', port: port } sphero: { adaptor: "sphero", port: port }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
work: function(my) { work: function(my) {

View File

@ -1,3 +1,5 @@
"use strict";
var Cylon = require("../.."); var Cylon = require("../..");
var bots = [ var bots = [
@ -26,10 +28,10 @@ bots.forEach(function(bot) {
}, },
work: function(my) { work: function(my) {
my.skynet.on('message', function(data) { my.skynet.on("message", function(data) {
if (data.led13 === 'on') { if (data.led13 === "on") {
my.led13.turnOn(); my.led13.turnOn();
} else if (data.led13 === 'off') { } else if (data.led13 === "off") {
my.led13.turnOff(); my.led13.turnOff();
} }

View File

@ -1,11 +1,13 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
var arduinos = [ var arduinos = [
{ {
name: "arduino0", name: "arduino0",
port: "/dev/ttyACM0", port: "/dev/ttyACM0",
devices: { devices: {
led00: { driver: 'led', pin: 13 } led00: { driver: "led", pin: 13 }
} }
}, },
@ -13,9 +15,9 @@ var arduinos = [
name: "arduin01", name: "arduin01",
port: "/dev/ttyACM1", port: "/dev/ttyACM1",
devices: { devices: {
led10: { driver: 'led', pin: 11 } led10: { driver: "led", pin: 11 },
led11: { driver: 'led', pin: 12 } led11: { driver: "led", pin: 12 },
led12: { driver: 'led', pin: 13 } led12: { driver: "led", pin: 13 }
} }
} }
]; ];
@ -25,7 +27,7 @@ Cylon.robot({
connections: { connections: {
skynet: { skynet: {
adaptor: 'skynet', adaptor: "skynet",
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912", uuid: "96630051-a3dc-11e3-8442-5bf31d98c912",
token: "2s67o7ek98pycik98f43reqr90t6s9k9" token: "2s67o7ek98pycik98f43reqr90t6s9k9"
} }
@ -42,7 +44,7 @@ Cylon.robot({
var robot = data.payload.robots[i], var robot = data.payload.robots[i],
bot = Cylon.robots[robot.name]; bot = Cylon.robots[robot.name];
if (robot.cmd === 'on') { if (robot.cmd === "on") {
bot.devices[robot.device].turnOn(); bot.devices[robot.device].turnOn();
} else { } else {
bot.devices[robot.device].turnOff(); bot.devices[robot.device].turnOff();
@ -51,7 +53,7 @@ Cylon.robot({
}, },
work: function(my) { work: function(my) {
my.skynet.on('message', my.handler) my.skynet.on("message", my.handler);
console.log("Skynet is listening"); console.log("Skynet is listening");
} }
}); });
@ -61,7 +63,7 @@ arduinos.forEach(function(bot) {
name: bot.name, name: bot.name,
connections: { connections: {
arduino: { adaptor: 'firmata', port: bot.port } arduino: { adaptor: "firmata", port: bot.port }
}, },
devices: bot.devices, devices: bot.devices,

View File

@ -1,22 +1,24 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
digispark: { adaptor: 'digispark' }, digispark: { adaptor: "digispark" },
leapmotion: { adaptor: 'leapmotion' } leapmotion: { adaptor: "leapmotion" }
}, },
devices: { devices: {
servo1: { driver: 'servo', pin: 0, connection: 'digispark' }, servo1: { driver: "servo", pin: 0, connection: "digispark" },
servo2: { driver: 'servo', pin: 1, connection: 'digispark' }, servo2: { driver: "servo", pin: 1, connection: "digispark" },
leapmotion: { driver: 'leapmotion', connection: 'leapmotion' } leapmotion: { driver: "leapmotion", connection: "leapmotion" }
}, },
work: function(my) { work: function(my) {
my.x = 90; my.x = 90;
my.z = 90; my.z = 90;
my.leapmotion.on('hand', function(hand) { my.leapmotion.on("hand", function(hand) {
my.x = hand.palmX.fromScale(-300, 300).toScale(30, 150); my.x = hand.palmX.fromScale(-300, 300).toScale(30, 150);
my.z = hand.palmZ.fromScale(-300, 300).toScale(30, 150); my.z = hand.palmZ.fromScale(-300, 300).toScale(30, 150);
}); });
@ -25,7 +27,12 @@ Cylon.robot({
my.servo1.angle(my.x); my.servo1.angle(my.x);
my.servo2.angle(my.z); my.servo2.angle(my.z);
console.log("Current Angle: " + my.servo1.currentAngle() + ", " + my.servo2.currentAngle()); var str = "Current Angle: ";
str += my.servo1.currentAngle();
str += ", ";
str += my.servo2.currentAngle();
console.log(str);
}); });
} }
}).start(); }).start();

View File

@ -1,13 +1,15 @@
"use strict";
var Cylon = require("../.."); var Cylon = require("../..");
var Green = 0x0000FF, var Green = 0x0000FF,
Red = 0xFF0000; Red = 0xFF0000;
var bots = { var bots = {
'Thelma': '/dev/rfcomm0', "Thelma": "/dev/rfcomm0",
'Louise': '/dev/rfcomm1', "Louise": "/dev/rfcomm1",
'Grace': '/dev/rfcomm2', "Grace": "/dev/rfcomm2",
'Ada': '/dev/rfcomm3' "Ada": "/dev/rfcomm3"
}; };
Object.keys(bots).forEach(function(name) { Object.keys(bots).forEach(function(name) {
@ -17,17 +19,17 @@ Object.keys(bots).forEach(function(name) {
name: name, name: name,
connections: { connections: {
sphero: { adaptor: 'sphero', port: port } sphero: { adaptor: "sphero", port: port }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
work: function(my) { work: function(my) {
my.born(); my.born();
my.sphero.on('collision', function() { my.sphero.on("collision", function() {
my.contacts += 1; my.contacts += 1;
}); });
@ -72,7 +74,15 @@ Object.keys(bots).forEach(function(name) {
this.age += 1; this.age += 1;
if (this.alive) { if (this.alive) {
console.log("Happy birthday, " + this.name + ". You are " + this.age + " and had " + this.contacts + " contacts."); var str = "Happy birthday, ";
str += this.name;
str += ". You are ";
str += this.age;
str += " and had ";
str += this.contacts;
str += " contacts.";
console.log(str);
} }
if (this.enoughContacts()) { if (this.enoughContacts()) {

View File

@ -1,22 +1,24 @@
"use strict";
var Cylon = require("../.."); var Cylon = require("../..");
var Green = 0x0000FF, var Green = 0x0000FF,
Red = 0xFF0000; Red = 0xFF0000;
var bots = { var bots = {
'Thelma': '/dev/rfcomm0', "Thelma": "/dev/rfcomm0",
'Louise': '/dev/rfcomm1', "Louise": "/dev/rfcomm1",
'Grace': '/dev/rfcomm2', "Grace": "/dev/rfcomm2",
'Ada': '/dev/rfcomm3' "Ada": "/dev/rfcomm3"
}; };
Object.keys(bots).forEach(function(name) { Object.keys(bots).forEach(function(name) {
var port = bots[name]; var port = bots[name];
var robot = Cylon.robot({ name: name, }); var robot = Cylon.robot({ name: name });
robot.connection('sphero', { adaptor: 'sphero', port: port }); robot.connection("sphero", { adaptor: "sphero", port: port });
robot.device('sphero', { driver: 'sphero' }); robot.device("sphero", { driver: "sphero" });
robot.move = function() { robot.move = function() {
robot.sphero.roll(60, Math.floor(Math.random() * 360)); robot.sphero.roll(60, Math.floor(Math.random() * 360));
@ -48,7 +50,15 @@ Object.keys(bots).forEach(function(name) {
robot.age += 1; robot.age += 1;
if (robot.alive) { if (robot.alive) {
console.log("Happy birthday, " + robot.name + ". You are " + robot.age + " and had " + robot.contacts + " contacts."); var str = "Happy birthday, ";
str += robot.name;
str += ". You are ";
str += robot.age;
str += " and had ";
str += robot.contacts;
str += " contacts.";
console.log(str);
} }
if (robot.enoughContacts()) { if (robot.enoughContacts()) {
@ -62,10 +72,10 @@ Object.keys(bots).forEach(function(name) {
robot.contacts = 0; robot.contacts = 0;
}; };
robot.on('ready', function() { robot.on("ready", function() {
robot.born(); robot.born();
robot.sphero.on('collision', function() { robot.sphero.on("collision", function() {
robot.contacts += 1; robot.contacts += 1;
}); });

View File

@ -1,16 +1,18 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
crazyflie: { adaptor: 'crazyflie', port: "radio://1/10/250KPS" } crazyflie: { adaptor: "crazyflie", port: "radio://1/10/250KPS" }
}, },
devices: { devices: {
drone: { driver: 'crazyflie' } drone: { driver: "crazyflie" }
} },
work: function(my) { work: function(my) {
my.drone.on('start', function() { my.drone.on("start", function() {
my.drone.takeoff(); my.drone.takeoff();
after((10).seconds(), my.drone.land); after((10).seconds(), my.drone.land);
after((15).seconds(), my.drone.stop); after((15).seconds(), my.drone.stop);

View File

@ -21,7 +21,7 @@ crazyflie adaptor. We'll be connecting to the Crazyflie using the CrazyRadio.
devices: { devices: {
drone: { driver: 'crazyflie' } drone: { driver: 'crazyflie' }
} },
With the parts in place, we can start defining our robot's work. With the parts in place, we can start defining our robot's work.

View File

@ -1,12 +1,14 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
digispark: { adaptor: 'digispark' } digispark: { adaptor: "digispark" }
}, },
devices: { devices: {
led: { driver: 'led', pin: 1 } led: { driver: "led", pin: 1 }
}, },
work: function(my) { work: function(my) {

View File

@ -1,15 +1,17 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
loopback: { adaptor: 'loopback' } loopback: { adaptor: "loopback" }
}, },
devices: { devices: {
ping: { driver: 'ping' } ping: { driver: "ping" }
}, },
work: function(my) { work: function() {
after((1).second(), function() { after((1).second(), function() {
console.log("Hello human!"); console.log("Hello human!");
console.log("I'm going to automatically stop in a few seconds."); console.log("I'm going to automatically stop in a few seconds.");

View File

@ -1,19 +1,21 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.api(); Cylon.api();
Cylon Cylon
.robot({ name: 'test' }) .robot({ name: "test" })
.connection('loopback', { adaptor: 'loopback' }) .connection("loopback", { adaptor: "loopback" })
.device('ping', { driver: 'ping' }) .device("ping", { driver: "ping" })
.on('ready', function(bot) { .on("ready", function(bot) {
setInterval(function() { setInterval(function() {
console.log("Hello, human!") console.log("Hello, human!");
console.log(bot.ping.ping()); console.log(bot.ping.ping());
}, 1000); }, 1000);
setTimeout(function() { setTimeout(function() {
console.log("I've been at your command for 5 seconds now.") console.log("I've been at your command for 5 seconds now.");
}, 5000); }, 5000);
}); });

View File

@ -1,26 +1,28 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.api(); Cylon.api();
Cylon.robot({ Cylon.robot({
name: 'test', name: "test",
connections: { connections: {
loopback: { adaptor: 'loopback' } loopback: { adaptor: "loopback" }
}, },
devices: { devices: {
ping: { driver: 'ping' } ping: { driver: "ping" }
}, },
work: function(my) { work: function(my) {
every((1).seconds(), function(){ every((1).seconds(), function(){
console.log("Hello, human!") console.log("Hello, human!");
console.log(my.ping.ping()); console.log(my.ping.ping());
}); });
after((5).seconds(), function(){ after((5).seconds(), function(){
console.log("I've been at your command for 5 seconds now.") console.log("I've been at your command for 5 seconds now.");
}); });
} }
}); });

View File

@ -1,16 +1,18 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
keyboard: { adaptor: 'keyboard' } keyboard: { adaptor: "keyboard" }
}, },
devices: { devices: {
keyboard: { driver: 'keyboard' } keyboard: { driver: "keyboard" }
}, },
work: function(my) { work: function(my) {
my.keyboard.on('a', function(key) { my.keyboard.on("a", function() {
console.log("a pressed!"); console.log("a pressed!");
}); });
} }

View File

@ -6,10 +6,11 @@
* Licensed under the Apache 2.0 license. * Licensed under the Apache 2.0 license.
*/ */
var Cylon = require('cylon'); "use strict";
var TURN_SPEED = 0.5, var Cylon = require("cylon");
TURN_TRESHOLD = 0.2,
var TURN_TRESHOLD = 0.2,
TURN_SPEED_FACTOR = 2.0; TURN_SPEED_FACTOR = 2.0;
var DIRECTION_THRESHOLD = 0.25, var DIRECTION_THRESHOLD = 0.25,
@ -26,33 +27,35 @@ var handWasClosedInLastFrame = false;
Cylon.robot({ Cylon.robot({
connections: { connections: {
leapmotion: { adaptor: 'leapmotion' }, leapmotion: { adaptor: "leapmotion" },
ardrone: { adaptor: 'ardrone', port: '192.168.1.1' }, ardrone: { adaptor: "ardrone", port: "192.168.1.1" },
keyboard: { adaptor: 'keyboard' } keyboard: { adaptor: "keyboard" }
}, },
devices: { devices: {
drone: { driver: 'ardrone', connection:'ardrone' }, drone: { driver: "ardrone", connection:"ardrone" },
leapmotion: { driver: 'leapmotion', connection:'leapmotion' }, leapmotion: { driver: "leapmotion", connection:"leapmotion" },
keyboard: { driver: 'keyboard', connection:'keyboard' } keyboard: { driver: "keyboard", connection:"keyboard" }
}, },
work: function(my) { work: function(my) {
my.keyboard.on('right', my.drone.rightFlip); my.keyboard.on("right", my.drone.rightFlip);
my.keyboard.on('left', my.drone.leftFlip); my.keyboard.on("left", my.drone.leftFlip);
my.keyboard.on('up', my.drone.frontFlip); my.keyboard.on("up", my.drone.frontFlip);
my.keyboard.on('down', my.drone.backFlip); my.keyboard.on("down", my.drone.backFlip);
my.keyboard.on('w', my.drone.wave); my.keyboard.on("w", my.drone.wave);
my.keyboard.on('s', my.drone.stop); my.keyboard.on("s", my.drone.stop);
my.keyboard.on('l', my.drone.land); my.keyboard.on("l", my.drone.land);
my.leapmotion.on('gesture', function(gesture) { my.leapmotion.on("gesture", function(gesture) {
var type = gesture.type, var type = gesture.type,
state = gesture.state, state = gesture.state,
progress = gesture.progress; progress = gesture.progress;
if (type === 'circle' && state === 'stop' && progress > CIRCLE_THRESHOLD) { var stop = (state === "stop");
if (type === "circle" && stop && progress > CIRCLE_THRESHOLD) {
if (gesture.normal[2] < 0) { if (gesture.normal[2] < 0) {
my.drone.takeoff(); my.drone.takeoff();
} }
@ -63,12 +66,14 @@ Cylon.robot({
} }
// emergency stop // emergency stop
if (type === 'keyTap' || type === 'screenTap') { if (type === "keyTap" || type === "screenTap") {
my.drone.stop(); my.drone.stop();
} }
}); });
my.leapmotion.on('hand', function(hand) { my.leapmotion.on("hand", function(hand) {
var signal, value;
var handOpen = !!hand.fingers.filter(function(f) { var handOpen = !!hand.fingers.filter(function(f) {
return f.extended; return f.extended;
}).length; }).length;
@ -79,10 +84,13 @@ Cylon.robot({
handStartDirection = hand.direction; handStartDirection = hand.direction;
} }
var horizontal = Math.abs(handStartDirection[0] - hand.direction[0]),
vertical = Math.abs(hand.palmPosition[1] - handStartPosition[1]);
// TURNS // TURNS
if (Math.abs(handStartDirection[0] - hand.direction[0]) > TURN_TRESHOLD) { if (horizontal > TURN_TRESHOLD) {
var signal = handStartDirection[0] - hand.direction[0], signal = handStartDirection[0] - hand.direction[0];
value = (Math.abs(handStartDirection[0] - hand.direction[0])- TURN_TRESHOLD) * TURN_SPEED_FACTOR; value = (horizontal - TURN_TRESHOLD) * TURN_SPEED_FACTOR;
if (signal > 0){ if (signal > 0){
my.drone.counterClockwise(value); my.drone.counterClockwise(value);
@ -94,9 +102,14 @@ Cylon.robot({
} }
// UP and DOWN // UP and DOWN
if (Math.abs(hand.palmPosition[1] - handStartPosition[1]) > UP_CONTROL_THRESHOLD) { if (vertical > UP_CONTROL_THRESHOLD) {
var signal = (hand.palmPosition[1] - handStartPosition[1]) >= 0 ? 1 : - 1; if ((hand.palmPosition[1] - handStartPosition[1]) >= 0) {
var value = Math.round(Math.abs((hand.palmPosition[1] - handStartPosition[1])) - UP_CONTROL_THRESHOLD) * UP_SPEED_FACTOR; signal = 1;
} else {
signal = -1;
}
value = Math.round(vertical - UP_CONTROL_THRESHOLD) * UP_SPEED_FACTOR;
if (signal > 0) { if (signal > 0) {
my.drone.up(value); my.drone.up(value);
@ -110,12 +123,20 @@ Cylon.robot({
// DIRECTION FRONT/BACK // DIRECTION FRONT/BACK
if ((Math.abs(hand.palmNormal[2]) > DIRECTION_THRESHOLD)) { if ((Math.abs(hand.palmNormal[2]) > DIRECTION_THRESHOLD)) {
if (hand.palmNormal[2] > 0) { if (hand.palmNormal[2] > 0) {
var value = Math.abs(Math.round(hand.palmNormal[2] * 10 + DIRECTION_THRESHOLD) * DIRECTION_SPEED_FACTOR); value = Math.abs(
Math.round(hand.palmNormal[2] * 10 + DIRECTION_THRESHOLD) *
DIRECTION_SPEED_FACTOR
);
my.drone.forward(value); my.drone.forward(value);
} }
if (hand.palmNormal[2] < 0) { if (hand.palmNormal[2] < 0) {
var value = Math.abs(Math.round(hand.palmNormal[2] * 10 - DIRECTION_THRESHOLD) * DIRECTION_SPEED_FACTOR); value = Math.abs(
Math.round(hand.palmNormal[2] * 10 - DIRECTION_THRESHOLD) *
DIRECTION_SPEED_FACTOR
);
my.drone.back(value); my.drone.back(value);
} }
} }
@ -123,23 +144,40 @@ Cylon.robot({
// DIRECTION LEFT/RIGHT // DIRECTION LEFT/RIGHT
if ((Math.abs(hand.palmNormal[0])>DIRECTION_THRESHOLD)) { if ((Math.abs(hand.palmNormal[0])>DIRECTION_THRESHOLD)) {
if (hand.palmNormal[0] > 0) { if (hand.palmNormal[0] > 0) {
var value = Math.abs(Math.round(hand.palmNormal[0] * 10 + DIRECTION_THRESHOLD ) * DIRECTION_SPEED_FACTOR); value = Math.abs(
Math.round(hand.palmNormal[0] * 10 + DIRECTION_THRESHOLD) *
DIRECTION_SPEED_FACTOR
);
my.drone.left(value); my.drone.left(value);
} }
if (hand.palmNormal[0] < 0) { if (hand.palmNormal[0] < 0) {
var value = Math.abs(Math.round(hand.palmNormal[0] * 10 - DIRECTION_THRESHOLD) * DIRECTION_SPEED_FACTOR); value = Math.abs(
Math.round(hand.palmNormal[0] * 10 - DIRECTION_THRESHOLD) *
DIRECTION_SPEED_FACTOR
);
my.drone.right(value); my.drone.right(value);
} }
} }
// AUTO FREEZE // AUTO FREEZE
if ((Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) && // within left/right threshold if (
(Math.abs(hand.palmNormal[2]) < DIRECTION_THRESHOLD) && // within forward/back threshold // within left/right threshold
Math.abs(hand.palmPosition[1] - handStartPosition[1]) < UP_CONTROL_THRESHOLD && // within up/down threshold (Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) &&
Math.abs(handStartDirection[0] - hand.direction[0]) < TURN_TRESHOLD) // within turn threshold
{ // within forward/back threshold
my.drone.stop(); (Math.abs(hand.palmNormal[2]) < DIRECTION_THRESHOLD) &&
// within up/down threshold
Math.abs(hand.palmPosition[1] - handStartPosition[1]) <
UP_CONTROL_THRESHOLD &&
// within turn threshold
Math.abs(handStartDirection[0] - hand.direction[0]) <
TURN_TRESHOLD) {
my.drone.stop();
} }
} }

View File

@ -1,17 +1,19 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
leap: { adaptor: 'leapmotion' }, leap: { adaptor: "leapmotion" },
arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' } arduino: { adaptor: "firmata", port: "/dev/ttyACM0" }
}, },
devices: { devices: {
led: { driver: 'led', pin: 13, connection: 'arduino' } led: { driver: "led", pin: 13, connection: "arduino" }
}, },
work: function(my) { work: function(my) {
my.leapmotion.on('frame', function(frame) { my.leapmotion.on("frame", function(frame) {
if (frame.hands.length > 0) { if (frame.hands.length > 0) {
my.led.turnOn(); my.led.turnOn();
} else { } else {

View File

@ -1,6 +1,8 @@
var Cylon = require('../..'); "use strict";
var bots = [ 'Huey', 'Dewey', 'Louie' ]; var Cylon = require("../..");
var bots = [ "Huey", "Dewey", "Louie" ];
bots.forEach(function(name) { bots.forEach(function(name) {
Cylon.robot({ Cylon.robot({

View File

@ -1,13 +1,15 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
arduino: { adaptor: 'firmata', port: '/dev/ttyUSB0' } arduino: { adaptor: "firmata", port: "/dev/ttyUSB0" }
}, },
devices: { devices: {
led: { driver: 'led', pin: 17 }, led: { driver: "led", pin: 17 },
servo: { driver: 'servo', pin: 2, range: { min: 30, max: 150 } } servo: { driver: "servo", pin: 2, range: { min: 30, max: 150 } }
}, },
work: function(my) { work: function(my) {
@ -16,7 +18,7 @@ Cylon.robot({
var angle = 30; var angle = 30;
var increment = 40; var increment = 40;
every(1..seconds(), function() { every((1).seconds(), function() {
angle += increment; angle += increment;
my.servo.angle(angle); my.servo.angle(angle);

View File

@ -1,9 +1,11 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.api(); Cylon.api();
Cylon.robot({ Cylon.robot({
name: 'Frankie', name: "Frankie",
sayRelax: function() { sayRelax: function() {
return this.name + " says relax"; return this.name + " says relax";

View File

@ -1,27 +1,29 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
sfcon: { sfcon: {
adaptor: 'force', adaptor: "force",
sfuser: process.env.SF_USERNAME, sfuser: process.env.SF_USERNAME,
sfpass: process.env.SF_SECURITY_TOKEN, sfpass: process.env.SF_SECURITY_TOKEN,
orgCreds: { orgCreds: {
clientId: process.env.SF_CLIENT_ID, clientId: process.env.SF_CLIENT_ID,
clientSecret: process.env.SF_CLIENT_SECRET, clientSecret: process.env.SF_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/oauth/_callback' redirectUri: "http://localhost:3000/oauth/_callback"
} }
} }
}, },
devices: { devices: {
salesforce: { driver: 'force' } salesforce: { driver: "force" }
}, },
work: function(my) { work: function(my) {
my.salesforce.on('start', function() { my.salesforce.on("start", function() {
my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) {
var msg = "Sphero: " + data.sobject.Sphero_Namy__c + ","; var msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
msg += "Bucks: " + data.sobject.Bucks__c + ","; msg += "Bucks: " + data.sobject.Bucks__c + ",";
msg += "SM_Id: " + data.sobject.Id; msg += "SM_Id: " + data.sobject.Id;
@ -33,11 +35,11 @@ Cylon.robot({
every((2).seconds(), function() { every((2).seconds(), function() {
var data = JSON.stringify({ var data = JSON.stringify({
spheroNamy: "" + my.namy, spheroName: "" + my.name,
bucks: "" + i bucks: "" + i
}); });
my.salesforce.push('SpheroController', 'POST', data); my.salesforce.push("SpheroController", "POST", data);
}); });
} }
}).start(); }).start();

View File

@ -33,7 +33,7 @@ tell it what work we want to do:
work: function(my) { work: function(my) {
my.salesforce.on('start', function() { my.salesforce.on('start', function() {
my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) {
var msg = "Sphero: " + data.sobject.Sphero_Namy__c + ","; var msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
msg += "Bucks: " + data.sobject.Bucks__c + ","; msg += "Bucks: " + data.sobject.Bucks__c + ",";
msg += "SM_Id: " + data.sobject.Id; msg += "SM_Id: " + data.sobject.Id;
@ -45,7 +45,7 @@ tell it what work we want to do:
every((2).seconds(), function() { every((2).seconds(), function() {
var data = JSON.stringify({ var data = JSON.stringify({
spheroNamy: "" + my.namy, spheroName: "" + my.name,
bucks: "" + i bucks: "" + i
}); });

View File

@ -1,28 +1,30 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
name: 'salesforce', name: "salesforce",
connections: { connections: {
sfcon: { sfcon: {
adaptor: 'force', adaptor: "force",
sfuser: process.env.SF_USERNAME, sfuser: process.env.SF_USERNAME,
sfpass: process.env.SF_SECURITY_TOKEN, sfpass: process.env.SF_SECURITY_TOKEN,
orgCreds: { orgCreds: {
clientId: process.env.SF_CLIENT_ID, clientId: process.env.SF_CLIENT_ID,
clientSecret: process.env.SF_CLIENT_SECRET, clientSecret: process.env.SF_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/oauth/_callback' redirectUri: "http://localhost:3000/oauth/_callback"
} }
} }
}, },
devices: { devices: {
salesforce: { driver: 'force' } salesforce: { driver: "force" }
}, },
work: function(my) { work: function(my) {
my.salesforce.on('start', function() { my.salesforce.on("start", function() {
my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) {
var msg = "Sphero: " + data.sobject.Sphero_Name__c + ","; var msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
msg += "Bucks: " + data.sobject.Bucks__c + ","; msg += "Bucks: " + data.sobject.Bucks__c + ",";
msg += "SM_Id: " + data.sobject.Id; msg += "SM_Id: " + data.sobject.Id;
@ -37,14 +39,14 @@ Cylon.robot({
}); });
Cylon.robot({ Cylon.robot({
name: 'ROY', name: "ROY",
connections: { connections: {
sphero: { adaptor: 'sphero' } sphero: { adaptor: "sphero" }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
react: function() { react: function() {
@ -53,7 +55,7 @@ Cylon.robot({
}, },
work: function(my) { work: function(my) {
console.log('Setting up collision detection.'); console.log("Setting up collision detection.");
my.sphero.detectCollisions(); my.sphero.detectCollisions();
my.sphero.stop(); my.sphero.stop();
@ -61,7 +63,7 @@ Cylon.robot({
my.sphero.roll(90, Math.floor(Math.random() * 360)); my.sphero.roll(90, Math.floor(Math.random() * 360));
my.sphero.on('collision', function() { my.sphero.on("collision", function() {
my.sphero.setRGB(0x0000FF, my); my.sphero.setRGB(0x0000FF, my);
my.sphero.stop(); my.sphero.stop();
@ -71,7 +73,7 @@ Cylon.robot({
}); });
var sf = Cylon.robots.salesforce; var sf = Cylon.robots.salesforce;
sf.devices.salesforce.push('SpheroController', 'POST', data); sf.devices.salesforce.push("SpheroController", "POST", data);
}); });
} }
}); });

View File

@ -1,29 +1,31 @@
var Cylon = require('../..'); "use strict";
var Cylon = require("../..");
Cylon.robot({ Cylon.robot({
connections: { connections: {
arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }, arduino: { adaptor: "firmata", port: "/dev/ttyACM0" },
skynet: { skynet: {
adaptor: 'skynet', adaptor: "skynet",
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912", uuid: "96630051-a3dc-11e3-8442-5bf31d98c912",
token: "2s67o7ek98pycik98f43reqr90t6s9k9" token: "2s67o7ek98pycik98f43reqr90t6s9k9"
} }
}, },
devices: { devices: {
led13: { driver: 'led', pin: 13, connection: 'arduino' } led13: { driver: "led", pin: 13, connection: "arduino" }
}, },
work: function(my) { work: function(my) {
console.log("Skynet is listening"); console.log("Skynet is listening");
my.skynet.on('message', function(data) { my.skynet.on("message", function(data) {
data = JSON.parse(data); data = JSON.parse(data);
console.log(data); console.log(data);
if (data.message.red === 'on') { if (data.message.red === "on") {
my.led13.turnOn(); my.led13.turnOn();
} else { } else {
my.led13.turnOff(); my.led13.turnOff();

View File

@ -1,52 +1,54 @@
"use strict";
var Cylon = require("../.."); var Cylon = require("../..");
Cylon.api({ host: '0.0.0.0', port: '8080' }); Cylon.api({ host: "0.0.0.0", port: "8080" });
Cylon.robot({ Cylon.robot({
name: 'pebble', name: "pebble",
connections: { connections: {
pebble: { adaptor: 'pebble' } pebble: { adaptor: "pebble" }
}, },
devices: { devices: {
pebble: { driver: 'pebble' } pebble: { driver: "pebble" }
}, },
message: function(msg) { message: function(msg) {
this.message_queue().push(msg); this.message_queue().push(msg);
}, },
work: function(my) { work: function() {
console.log('Pebble connected'); console.log("Pebble connected");
} }
}); });
Cylon.robot({ Cylon.robot({
name: 'salesforce', name: "salesforce",
connections: { connections: {
sfcon: { sfcon: {
adaptor: 'force', adaptor: "force",
sfuser: process.env.SF_USERNAME, sfuser: process.env.SF_USERNAME,
sfpass: process.env.SF_SECURITY_TOKEN, sfpass: process.env.SF_SECURITY_TOKEN,
orgCreds: { orgCreds: {
clientId: process.env.SF_CLIENT_ID, clientId: process.env.SF_CLIENT_ID,
clientSecret: process.env.SF_CLIENT_SECRET, clientSecret: process.env.SF_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/oauth/_callback' redirectUri: "http://localhost:3000/oauth/_callback"
} }
} }
}, },
devices: { devices: {
salesforce: { driver: 'force' } salesforce: { driver: "force" }
}, },
spheroReport: {}, spheroReport: {},
work: function(my) { work: function(my) {
my.salesforce.on('start', function() { my.salesforce.on("start", function() {
my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) {
var toPebble = "", var toPebble = "",
name = data.sobject.Sphero_Name__c, name = data.sobject.Sphero_Name__c,
bucks = data.sobject.Bucks__c; bucks = data.sobject.Bucks__c;
@ -75,9 +77,9 @@ Cylon.robot({
}); });
var bots = [ var bots = [
{ port: '/dev/tty.Sphero-ROY-AMP-SPP', name: 'ROY' }, { port: "/dev/tty.Sphero-ROY-AMP-SPP", name: "ROY" },
{ port: '/dev/tty.Sphero-GBO-AMP-SPP', name: 'GBO' }, { port: "/dev/tty.Sphero-GBO-AMP-SPP", name: "GBO" },
{ port: '/dev/tty.Sphero-RRY-AMP-SPP', name: 'RRY' } { port: "/dev/tty.Sphero-RRY-AMP-SPP", name: "RRY" }
]; ];
bots.forEach(function(bot) { bots.forEach(function(bot) {
@ -85,11 +87,11 @@ bots.forEach(function(bot) {
name: bot.name, name: bot.name,
connections: { connections: {
sphero: { adaptor: 'sphero', port: bot.port } sphero: { adaptor: "sphero", port: bot.port }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
totalBucks: 1, totalBucks: 1,
@ -141,7 +143,7 @@ bots.forEach(function(bot) {
my.bankrupt(); my.bankrupt();
my.changeDirection(); my.changeDirection();
my.sphero.on('collision', function() { my.sphero.on("collision", function() {
my.sphero.setRGB(0x0000FF); my.sphero.setRGB(0x0000FF);
my.sphero.stop(); my.sphero.stop();
my.payingPower = false; my.payingPower = false;
@ -151,7 +153,7 @@ bots.forEach(function(bot) {
bucks: "" + (my.totalBucks++) bucks: "" + (my.totalBucks++)
}); });
var sf = Cylon.robots['salesforce']; var sf = Cylon.robots["salesforce"];
sf.devices.salesforce.push("SpheroController", "POST", data); sf.devices.salesforce.push("SpheroController", "POST", data);
}); });
} }

View File

@ -1,26 +1,33 @@
var Cylon = require('cylon'); "use strict";
var Cylon = require("cylon");
Cylon.robot({ Cylon.robot({
connections: { connections: {
sphero: { adaptor: 'sphero', port: '/dev/tty.Sphero-YBW-RN-SPP' } sphero: { adaptor: "sphero", port: "/dev/tty.Sphero-YBW-RN-SPP" }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
work: function(my) { work: function(my) {
var max = 0; var max = 0;
var changingColor = false; var changingColor = false;
my.sphero.setDataStreaming(['velocity'], { n: 40, m: 1, pcnt: 0 }); my.sphero.setDataStreaming(["velocity"], { n: 40, m: 1, pcnt: 0 });
my.sphero.on('data', function(data) { my.sphero.on("data", function(data) {
if(!changingColor) { if(!changingColor) {
x = Math.abs(data[0]); var x = Math.abs(data[0]),
y = Math.abs(data[1]); y = Math.abs(data[1]);
if (x > max) max = x; if (x > max) {
if (y > max) max = y; max = x;
}
if (y > max) {
max = y;
}
} }
}); });
@ -28,19 +35,19 @@ Cylon.robot({
changingColor = true; changingColor = true;
if (max < 10) { if (max < 10) {
my.sphero.setColor('white'); my.sphero.setColor("white");
} else if (max < 100) { } else if (max < 100) {
my.sphero.setColor('lightyellow'); my.sphero.setColor("lightyellow");
} else if (max < 150) { } else if (max < 150) {
my.sphero.setColor('yellow'); my.sphero.setColor("yellow");
} else if (max < 250) { } else if (max < 250) {
my.sphero.setColor('orange'); my.sphero.setColor("orange");
} else if (max < 350) { } else if (max < 350) {
my.sphero.setColor('orangered'); my.sphero.setColor("orangered");
} else if (max < 450) { } else if (max < 450) {
my.sphero.setColor('red'); my.sphero.setColor("red");
} else { } else {
my.sphero.setColor('darkred'); my.sphero.setColor("darkred");
} }
max = 0; max = 0;

View File

@ -1,15 +1,17 @@
var Cylon = require('../..'), "use strict";
Travis = require('travis-ci');
var travis = new Travis({version: '2.0.0'}); var Cylon = require("../.."),
Travis = require("travis-ci");
var travis = new Travis({version: "2.0.0"});
Cylon.robot({ Cylon.robot({
connections: { connections: {
sphero: { adaptor: 'sphero', port: '/dev/rfcomm0' } sphero: { adaptor: "sphero", port: "/dev/rfcomm0" }
}, },
devices: { devices: {
sphero: { driver: 'sphero' } sphero: { driver: "sphero" }
}, },
work: function(my) { work: function(my) {
@ -18,23 +20,23 @@ Cylon.robot({
var checkTravis = function() { var checkTravis = function() {
console.log("Checking repo " + user + "/" + name); console.log("Checking repo " + user + "/" + name);
my.sphero.setColor('blue', true); my.sphero.setColor("blue", true);
travis.repos({ owner_name: user, name: name }, function(err, res) { travis.repos({ owner_name: user, name: name }, function(err, res) {
if (res.repo === undefined) { my.sphero.setColor('blue', true); } if (res.repo === undefined) { my.sphero.setColor("blue", true); }
switch (res.repo.last_build_state) { switch (res.repo.last_build_state) {
case 'passed': case "passed":
my.sphero.setColor('green', true); my.sphero.setColor("green", true);
break; break;
case 'failed': case "failed":
my.sphero.setColor('red', true); my.sphero.setColor("red", true);
break; break;
default: default:
my.sphero.setColor('blue', true); my.sphero.setColor("blue", true);
} }
}); });
} };
checkTravis(); checkTravis();