diff --git a/examples/api/api.js b/examples/api/api.js index e7b49dd..b25f5c1 100644 --- a/examples/api/api.js +++ b/examples/api/api.js @@ -1,13 +1,15 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.api({ - host: '0.0.0.0', - port: '8080' + host: "0.0.0.0", + port: "8080" }); var bots = { - 'Thelma': '/dev/rfcomm0', - 'Louise': '/dev/rfcomm1' + "Thelma": "/dev/rfcomm0", + "Louise": "/dev/rfcomm1" }; Object.keys(bots).forEach(function(name) { @@ -17,11 +19,11 @@ Object.keys(bots).forEach(function(name) { name: name, connections: { - sphero: { adaptor: 'sphero', port: port } + sphero: { adaptor: "sphero", port: port } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, work: function(my) { diff --git a/examples/arduinos_and_skynet/multiple_arduinos_multiple_skynet_connections.js b/examples/arduinos_and_skynet/multiple_arduinos_multiple_skynet_connections.js index 86c39a8..b019997 100644 --- a/examples/arduinos_and_skynet/multiple_arduinos_multiple_skynet_connections.js +++ b/examples/arduinos_and_skynet/multiple_arduinos_multiple_skynet_connections.js @@ -1,3 +1,5 @@ +"use strict"; + var Cylon = require("../.."); var bots = [ @@ -26,10 +28,10 @@ bots.forEach(function(bot) { }, work: function(my) { - my.skynet.on('message', function(data) { - if (data.led13 === 'on') { + my.skynet.on("message", function(data) { + if (data.led13 === "on") { my.led13.turnOn(); - } else if (data.led13 === 'off') { + } else if (data.led13 === "off") { my.led13.turnOff(); } diff --git a/examples/arduinos_and_skynet/multiple_arduinos_one_skynet_connection.js b/examples/arduinos_and_skynet/multiple_arduinos_one_skynet_connection.js index dbfba90..1342162 100644 --- a/examples/arduinos_and_skynet/multiple_arduinos_one_skynet_connection.js +++ b/examples/arduinos_and_skynet/multiple_arduinos_one_skynet_connection.js @@ -1,11 +1,13 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); var arduinos = [ { name: "arduino0", port: "/dev/ttyACM0", devices: { - led00: { driver: 'led', pin: 13 } + led00: { driver: "led", pin: 13 } } }, @@ -13,9 +15,9 @@ var arduinos = [ name: "arduin01", port: "/dev/ttyACM1", devices: { - led10: { driver: 'led', pin: 11 } - led11: { driver: 'led', pin: 12 } - led12: { driver: 'led', pin: 13 } + led10: { driver: "led", pin: 11 }, + led11: { driver: "led", pin: 12 }, + led12: { driver: "led", pin: 13 } } } ]; @@ -25,7 +27,7 @@ Cylon.robot({ connections: { skynet: { - adaptor: 'skynet', + adaptor: "skynet", uuid: "96630051-a3dc-11e3-8442-5bf31d98c912", token: "2s67o7ek98pycik98f43reqr90t6s9k9" } @@ -42,7 +44,7 @@ Cylon.robot({ var robot = data.payload.robots[i], bot = Cylon.robots[robot.name]; - if (robot.cmd === 'on') { + if (robot.cmd === "on") { bot.devices[robot.device].turnOn(); } else { bot.devices[robot.device].turnOff(); @@ -51,7 +53,7 @@ Cylon.robot({ }, work: function(my) { - my.skynet.on('message', my.handler) + my.skynet.on("message", my.handler); console.log("Skynet is listening"); } }); @@ -61,7 +63,7 @@ arduinos.forEach(function(bot) { name: bot.name, connections: { - arduino: { adaptor: 'firmata', port: bot.port } + arduino: { adaptor: "firmata", port: bot.port } }, devices: bot.devices, diff --git a/examples/cattoy/cattoy.js b/examples/cattoy/cattoy.js index 2ccc1d9..2995c12 100644 --- a/examples/cattoy/cattoy.js +++ b/examples/cattoy/cattoy.js @@ -1,22 +1,24 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - digispark: { adaptor: 'digispark' }, - leapmotion: { adaptor: 'leapmotion' } + digispark: { adaptor: "digispark" }, + leapmotion: { adaptor: "leapmotion" } }, devices: { - servo1: { driver: 'servo', pin: 0, connection: 'digispark' }, - servo2: { driver: 'servo', pin: 1, connection: 'digispark' }, - leapmotion: { driver: 'leapmotion', connection: 'leapmotion' } + servo1: { driver: "servo", pin: 0, connection: "digispark" }, + servo2: { driver: "servo", pin: 1, connection: "digispark" }, + leapmotion: { driver: "leapmotion", connection: "leapmotion" } }, work: function(my) { my.x = 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.z = hand.palmZ.fromScale(-300, 300).toScale(30, 150); }); @@ -25,7 +27,12 @@ Cylon.robot({ my.servo1.angle(my.x); 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(); diff --git a/examples/conway_sphero/conway_sphero.js b/examples/conway_sphero/conway_sphero.js index 693a6b5..b0913cc 100644 --- a/examples/conway_sphero/conway_sphero.js +++ b/examples/conway_sphero/conway_sphero.js @@ -1,13 +1,15 @@ +"use strict"; + var Cylon = require("../.."); var Green = 0x0000FF, Red = 0xFF0000; var bots = { - 'Thelma': '/dev/rfcomm0', - 'Louise': '/dev/rfcomm1', - 'Grace': '/dev/rfcomm2', - 'Ada': '/dev/rfcomm3' + "Thelma": "/dev/rfcomm0", + "Louise": "/dev/rfcomm1", + "Grace": "/dev/rfcomm2", + "Ada": "/dev/rfcomm3" }; Object.keys(bots).forEach(function(name) { @@ -17,17 +19,17 @@ Object.keys(bots).forEach(function(name) { name: name, connections: { - sphero: { adaptor: 'sphero', port: port } + sphero: { adaptor: "sphero", port: port } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, work: function(my) { my.born(); - my.sphero.on('collision', function() { + my.sphero.on("collision", function() { my.contacts += 1; }); @@ -72,7 +74,15 @@ Object.keys(bots).forEach(function(name) { this.age += 1; 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()) { diff --git a/examples/conway_sphero/fluent-conway_sphero.js b/examples/conway_sphero/fluent-conway_sphero.js index 78bff33..51134e7 100644 --- a/examples/conway_sphero/fluent-conway_sphero.js +++ b/examples/conway_sphero/fluent-conway_sphero.js @@ -1,22 +1,24 @@ +"use strict"; + var Cylon = require("../.."); var Green = 0x0000FF, Red = 0xFF0000; var bots = { - 'Thelma': '/dev/rfcomm0', - 'Louise': '/dev/rfcomm1', - 'Grace': '/dev/rfcomm2', - 'Ada': '/dev/rfcomm3' + "Thelma": "/dev/rfcomm0", + "Louise": "/dev/rfcomm1", + "Grace": "/dev/rfcomm2", + "Ada": "/dev/rfcomm3" }; Object.keys(bots).forEach(function(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.device('sphero', { driver: 'sphero' }); + robot.connection("sphero", { adaptor: "sphero", port: port }); + robot.device("sphero", { driver: "sphero" }); robot.move = function() { robot.sphero.roll(60, Math.floor(Math.random() * 360)); @@ -48,7 +50,15 @@ Object.keys(bots).forEach(function(name) { robot.age += 1; 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()) { @@ -62,10 +72,10 @@ Object.keys(bots).forEach(function(name) { robot.contacts = 0; }; - robot.on('ready', function() { + robot.on("ready", function() { robot.born(); - robot.sphero.on('collision', function() { + robot.sphero.on("collision", function() { robot.contacts += 1; }); diff --git a/examples/crazyflie/crazyflie.js b/examples/crazyflie/crazyflie.js index 335f0ce..84964b9 100644 --- a/examples/crazyflie/crazyflie.js +++ b/examples/crazyflie/crazyflie.js @@ -1,16 +1,18 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - crazyflie: { adaptor: 'crazyflie', port: "radio://1/10/250KPS" } + crazyflie: { adaptor: "crazyflie", port: "radio://1/10/250KPS" } }, devices: { - drone: { driver: 'crazyflie' } - } + drone: { driver: "crazyflie" } + }, work: function(my) { - my.drone.on('start', function() { + my.drone.on("start", function() { my.drone.takeoff(); after((10).seconds(), my.drone.land); after((15).seconds(), my.drone.stop); diff --git a/examples/crazyflie/crazyflie.markdown b/examples/crazyflie/crazyflie.markdown index 67071cc..2b4f055 100644 --- a/examples/crazyflie/crazyflie.markdown +++ b/examples/crazyflie/crazyflie.markdown @@ -21,7 +21,7 @@ crazyflie adaptor. We'll be connecting to the Crazyflie using the CrazyRadio. devices: { drone: { driver: 'crazyflie' } - } + }, With the parts in place, we can start defining our robot's work. diff --git a/examples/digispark_blink/blink.js b/examples/digispark_blink/blink.js index 2e86ff0..7a89f5f 100644 --- a/examples/digispark_blink/blink.js +++ b/examples/digispark_blink/blink.js @@ -1,12 +1,14 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - digispark: { adaptor: 'digispark' } + digispark: { adaptor: "digispark" } }, devices: { - led: { driver: 'led', pin: 1 } + led: { driver: "led", pin: 1 } }, work: function(my) { diff --git a/examples/halt/halt.js b/examples/halt/halt.js index 886740c..5c7a3e1 100644 --- a/examples/halt/halt.js +++ b/examples/halt/halt.js @@ -1,15 +1,17 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - loopback: { adaptor: 'loopback' } + loopback: { adaptor: "loopback" } }, devices: { - ping: { driver: 'ping' } + ping: { driver: "ping" } }, - work: function(my) { + work: function() { after((1).second(), function() { console.log("Hello human!"); console.log("I'm going to automatically stop in a few seconds."); diff --git a/examples/hello/fluent-hello.js b/examples/hello/fluent-hello.js index ef0337f..4883bd0 100644 --- a/examples/hello/fluent-hello.js +++ b/examples/hello/fluent-hello.js @@ -1,19 +1,21 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.api(); Cylon - .robot({ name: 'test' }) - .connection('loopback', { adaptor: 'loopback' }) - .device('ping', { driver: 'ping' }) - .on('ready', function(bot) { + .robot({ name: "test" }) + .connection("loopback", { adaptor: "loopback" }) + .device("ping", { driver: "ping" }) + .on("ready", function(bot) { setInterval(function() { - console.log("Hello, human!") + console.log("Hello, human!"); console.log(bot.ping.ping()); }, 1000); 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); }); diff --git a/examples/hello/hello.js b/examples/hello/hello.js index 9eed61c..f06c362 100644 --- a/examples/hello/hello.js +++ b/examples/hello/hello.js @@ -1,26 +1,28 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.api(); Cylon.robot({ - name: 'test', + name: "test", connections: { - loopback: { adaptor: 'loopback' } + loopback: { adaptor: "loopback" } }, devices: { - ping: { driver: 'ping' } + ping: { driver: "ping" } }, work: function(my) { every((1).seconds(), function(){ - console.log("Hello, human!") + console.log("Hello, human!"); console.log(my.ping.ping()); }); 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."); }); } }); diff --git a/examples/keyboard/keyboard.js b/examples/keyboard/keyboard.js index 74fe0eb..d65407c 100644 --- a/examples/keyboard/keyboard.js +++ b/examples/keyboard/keyboard.js @@ -1,16 +1,18 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - keyboard: { adaptor: 'keyboard' } + keyboard: { adaptor: "keyboard" } }, devices: { - keyboard: { driver: 'keyboard' } + keyboard: { driver: "keyboard" } }, work: function(my) { - my.keyboard.on('a', function(key) { + my.keyboard.on("a", function() { console.log("a pressed!"); }); } diff --git a/examples/leap_ardrone/leap_ardrone.js b/examples/leap_ardrone/leap_ardrone.js index fa08b91..a878cda 100644 --- a/examples/leap_ardrone/leap_ardrone.js +++ b/examples/leap_ardrone/leap_ardrone.js @@ -6,10 +6,11 @@ * Licensed under the Apache 2.0 license. */ -var Cylon = require('cylon'); +"use strict"; -var TURN_SPEED = 0.5, - TURN_TRESHOLD = 0.2, +var Cylon = require("cylon"); + +var TURN_TRESHOLD = 0.2, TURN_SPEED_FACTOR = 2.0; var DIRECTION_THRESHOLD = 0.25, @@ -26,33 +27,35 @@ var handWasClosedInLastFrame = false; Cylon.robot({ connections: { - leapmotion: { adaptor: 'leapmotion' }, - ardrone: { adaptor: 'ardrone', port: '192.168.1.1' }, - keyboard: { adaptor: 'keyboard' } + leapmotion: { adaptor: "leapmotion" }, + ardrone: { adaptor: "ardrone", port: "192.168.1.1" }, + keyboard: { adaptor: "keyboard" } }, devices: { - drone: { driver: 'ardrone', connection:'ardrone' }, - leapmotion: { driver: 'leapmotion', connection:'leapmotion' }, - keyboard: { driver: 'keyboard', connection:'keyboard' } + drone: { driver: "ardrone", connection:"ardrone" }, + leapmotion: { driver: "leapmotion", connection:"leapmotion" }, + keyboard: { driver: "keyboard", connection:"keyboard" } }, work: function(my) { - my.keyboard.on('right', my.drone.rightFlip); - my.keyboard.on('left', my.drone.leftFlip); - my.keyboard.on('up', my.drone.frontFlip); - my.keyboard.on('down', my.drone.backFlip); + my.keyboard.on("right", my.drone.rightFlip); + my.keyboard.on("left", my.drone.leftFlip); + my.keyboard.on("up", my.drone.frontFlip); + my.keyboard.on("down", my.drone.backFlip); - my.keyboard.on('w', my.drone.wave); - my.keyboard.on('s', my.drone.stop); - my.keyboard.on('l', my.drone.land); + my.keyboard.on("w", my.drone.wave); + my.keyboard.on("s", my.drone.stop); + my.keyboard.on("l", my.drone.land); - my.leapmotion.on('gesture', function(gesture) { + my.leapmotion.on("gesture", function(gesture) { var type = gesture.type, state = gesture.state, 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) { my.drone.takeoff(); } @@ -63,12 +66,14 @@ Cylon.robot({ } // emergency stop - if (type === 'keyTap' || type === 'screenTap') { + if (type === "keyTap" || type === "screenTap") { 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) { return f.extended; }).length; @@ -79,10 +84,13 @@ Cylon.robot({ handStartDirection = hand.direction; } + var horizontal = Math.abs(handStartDirection[0] - hand.direction[0]), + vertical = Math.abs(hand.palmPosition[1] - handStartPosition[1]); + // TURNS - if (Math.abs(handStartDirection[0] - hand.direction[0]) > TURN_TRESHOLD) { - var signal = handStartDirection[0] - hand.direction[0], - value = (Math.abs(handStartDirection[0] - hand.direction[0])- TURN_TRESHOLD) * TURN_SPEED_FACTOR; + if (horizontal > TURN_TRESHOLD) { + signal = handStartDirection[0] - hand.direction[0]; + value = (horizontal - TURN_TRESHOLD) * TURN_SPEED_FACTOR; if (signal > 0){ my.drone.counterClockwise(value); @@ -94,9 +102,14 @@ Cylon.robot({ } // UP and DOWN - if (Math.abs(hand.palmPosition[1] - handStartPosition[1]) > UP_CONTROL_THRESHOLD) { - var signal = (hand.palmPosition[1] - handStartPosition[1]) >= 0 ? 1 : - 1; - var value = Math.round(Math.abs((hand.palmPosition[1] - handStartPosition[1])) - UP_CONTROL_THRESHOLD) * UP_SPEED_FACTOR; + if (vertical > UP_CONTROL_THRESHOLD) { + if ((hand.palmPosition[1] - handStartPosition[1]) >= 0) { + signal = 1; + } else { + signal = -1; + } + + value = Math.round(vertical - UP_CONTROL_THRESHOLD) * UP_SPEED_FACTOR; if (signal > 0) { my.drone.up(value); @@ -110,12 +123,20 @@ Cylon.robot({ // DIRECTION FRONT/BACK if ((Math.abs(hand.palmNormal[2]) > DIRECTION_THRESHOLD)) { 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); } 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); } } @@ -123,23 +144,40 @@ Cylon.robot({ // DIRECTION LEFT/RIGHT if ((Math.abs(hand.palmNormal[0])>DIRECTION_THRESHOLD)) { 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); } 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); } } // AUTO FREEZE - if ((Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) && // within left/right threshold - (Math.abs(hand.palmNormal[2]) < DIRECTION_THRESHOLD) && // within forward/back threshold - Math.abs(hand.palmPosition[1] - handStartPosition[1]) < UP_CONTROL_THRESHOLD && // within up/down threshold - Math.abs(handStartDirection[0] - hand.direction[0]) < TURN_TRESHOLD) // within turn threshold - { - my.drone.stop(); + if ( + // within left/right threshold + (Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) && + + // within forward/back threshold + (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(); } } diff --git a/examples/leap_arduino/leap_arduino.js b/examples/leap_arduino/leap_arduino.js index 01f8a80..70e727c 100644 --- a/examples/leap_arduino/leap_arduino.js +++ b/examples/leap_arduino/leap_arduino.js @@ -1,17 +1,19 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - leap: { adaptor: 'leapmotion' }, - arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' } + leap: { adaptor: "leapmotion" }, + arduino: { adaptor: "firmata", port: "/dev/ttyACM0" } }, devices: { - led: { driver: 'led', pin: 13, connection: 'arduino' } + led: { driver: "led", pin: 13, connection: "arduino" } }, work: function(my) { - my.leapmotion.on('frame', function(frame) { + my.leapmotion.on("frame", function(frame) { if (frame.hands.length > 0) { my.led.turnOn(); } else { diff --git a/examples/master/master.js b/examples/master/master.js index 89dab9a..dbcf4d1 100644 --- a/examples/master/master.js +++ b/examples/master/master.js @@ -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) { Cylon.robot({ diff --git a/examples/rapiro/rapiro_servo.js b/examples/rapiro/rapiro_servo.js index d5c2449..3376f70 100644 --- a/examples/rapiro/rapiro_servo.js +++ b/examples/rapiro/rapiro_servo.js @@ -1,13 +1,15 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - arduino: { adaptor: 'firmata', port: '/dev/ttyUSB0' } + arduino: { adaptor: "firmata", port: "/dev/ttyUSB0" } }, devices: { - led: { driver: 'led', pin: 17 }, - servo: { driver: 'servo', pin: 2, range: { min: 30, max: 150 } } + led: { driver: "led", pin: 17 }, + servo: { driver: "servo", pin: 2, range: { min: 30, max: 150 } } }, work: function(my) { @@ -16,7 +18,7 @@ Cylon.robot({ var angle = 30; var increment = 40; - every(1..seconds(), function() { + every((1).seconds(), function() { angle += increment; my.servo.angle(angle); diff --git a/examples/robot_commands/robot_commands.js b/examples/robot_commands/robot_commands.js index 65c7c5c..99b6a57 100644 --- a/examples/robot_commands/robot_commands.js +++ b/examples/robot_commands/robot_commands.js @@ -1,9 +1,11 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.api(); Cylon.robot({ - name: 'Frankie', + name: "Frankie", sayRelax: function() { return this.name + " says relax"; diff --git a/examples/salesforce/salesforce.js b/examples/salesforce/salesforce.js index 82e4fc2..fb4ec8a 100644 --- a/examples/salesforce/salesforce.js +++ b/examples/salesforce/salesforce.js @@ -1,27 +1,29 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { sfcon: { - adaptor: 'force', + 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' + redirectUri: "http://localhost:3000/oauth/_callback" } } }, devices: { - salesforce: { driver: 'force' } + salesforce: { driver: "force" } }, work: function(my) { - my.salesforce.on('start', function() { - my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { - var msg = "Sphero: " + data.sobject.Sphero_Namy__c + ","; + my.salesforce.on("start", function() { + my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) { + var msg = "Sphero: " + data.sobject.Sphero_Name__c + ","; msg += "Bucks: " + data.sobject.Bucks__c + ","; msg += "SM_Id: " + data.sobject.Id; @@ -33,11 +35,11 @@ Cylon.robot({ every((2).seconds(), function() { var data = JSON.stringify({ - spheroNamy: "" + my.namy, + spheroName: "" + my.name, bucks: "" + i }); - my.salesforce.push('SpheroController', 'POST', data); + my.salesforce.push("SpheroController", "POST", data); }); } }).start(); diff --git a/examples/salesforce/salesforce.markdown b/examples/salesforce/salesforce.markdown index e03b90c..20b24b1 100644 --- a/examples/salesforce/salesforce.markdown +++ b/examples/salesforce/salesforce.markdown @@ -33,7 +33,7 @@ tell it what work we want to do: work: function(my) { my.salesforce.on('start', function() { 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 += "SM_Id: " + data.sobject.Id; @@ -45,7 +45,7 @@ tell it what work we want to do: every((2).seconds(), function() { var data = JSON.stringify({ - spheroNamy: "" + my.namy, + spheroName: "" + my.name, bucks: "" + i }); diff --git a/examples/sf-sphero/sf-sphero.js b/examples/sf-sphero/sf-sphero.js index a7dc7c1..c46904b 100644 --- a/examples/sf-sphero/sf-sphero.js +++ b/examples/sf-sphero/sf-sphero.js @@ -1,28 +1,30 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ - name: 'salesforce', + name: "salesforce", connections: { sfcon: { - adaptor: 'force', + 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' + redirectUri: "http://localhost:3000/oauth/_callback" } } }, devices: { - salesforce: { driver: 'force' } + salesforce: { driver: "force" } }, work: function(my) { - my.salesforce.on('start', function() { - my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { + my.salesforce.on("start", function() { + my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) { var msg = "Sphero: " + data.sobject.Sphero_Name__c + ","; msg += "Bucks: " + data.sobject.Bucks__c + ","; msg += "SM_Id: " + data.sobject.Id; @@ -37,14 +39,14 @@ Cylon.robot({ }); Cylon.robot({ - name: 'ROY', + name: "ROY", connections: { - sphero: { adaptor: 'sphero' } + sphero: { adaptor: "sphero" } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, react: function() { @@ -53,7 +55,7 @@ Cylon.robot({ }, work: function(my) { - console.log('Setting up collision detection.'); + console.log("Setting up collision detection."); my.sphero.detectCollisions(); my.sphero.stop(); @@ -61,7 +63,7 @@ Cylon.robot({ 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.stop(); @@ -71,7 +73,7 @@ Cylon.robot({ }); var sf = Cylon.robots.salesforce; - sf.devices.salesforce.push('SpheroController', 'POST', data); + sf.devices.salesforce.push("SpheroController", "POST", data); }); } }); diff --git a/examples/skynet/skynet-blink.js b/examples/skynet/skynet-blink.js index 5079607..de428f6 100644 --- a/examples/skynet/skynet-blink.js +++ b/examples/skynet/skynet-blink.js @@ -1,29 +1,31 @@ -var Cylon = require('../..'); +"use strict"; + +var Cylon = require("../.."); Cylon.robot({ connections: { - arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }, + arduino: { adaptor: "firmata", port: "/dev/ttyACM0" }, skynet: { - adaptor: 'skynet', + adaptor: "skynet", uuid: "96630051-a3dc-11e3-8442-5bf31d98c912", token: "2s67o7ek98pycik98f43reqr90t6s9k9" } }, devices: { - led13: { driver: 'led', pin: 13, connection: 'arduino' } + led13: { driver: "led", pin: 13, connection: "arduino" } }, work: function(my) { console.log("Skynet is listening"); - my.skynet.on('message', function(data) { + my.skynet.on("message", function(data) { data = JSON.parse(data); console.log(data); - if (data.message.red === 'on') { + if (data.message.red === "on") { my.led13.turnOn(); } else { my.led13.turnOff(); diff --git a/examples/sphero-pebble-sf/sphero-pebble-sf.js b/examples/sphero-pebble-sf/sphero-pebble-sf.js index c05e118..243e453 100644 --- a/examples/sphero-pebble-sf/sphero-pebble-sf.js +++ b/examples/sphero-pebble-sf/sphero-pebble-sf.js @@ -1,52 +1,54 @@ +"use strict"; + var Cylon = require("../.."); -Cylon.api({ host: '0.0.0.0', port: '8080' }); +Cylon.api({ host: "0.0.0.0", port: "8080" }); Cylon.robot({ - name: 'pebble', + name: "pebble", connections: { - pebble: { adaptor: 'pebble' } + pebble: { adaptor: "pebble" } }, devices: { - pebble: { driver: 'pebble' } + pebble: { driver: "pebble" } }, message: function(msg) { this.message_queue().push(msg); }, - work: function(my) { - console.log('Pebble connected'); + work: function() { + console.log("Pebble connected"); } }); Cylon.robot({ - name: 'salesforce', + name: "salesforce", connections: { sfcon: { - adaptor: 'force', + 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' + redirectUri: "http://localhost:3000/oauth/_callback" } } }, devices: { - salesforce: { driver: 'force' } + salesforce: { driver: "force" } }, spheroReport: {}, work: function(my) { - my.salesforce.on('start', function() { - my.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) { + my.salesforce.on("start", function() { + my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) { var toPebble = "", name = data.sobject.Sphero_Name__c, bucks = data.sobject.Bucks__c; @@ -75,9 +77,9 @@ Cylon.robot({ }); var 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' } + { 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" } ]; bots.forEach(function(bot) { @@ -85,11 +87,11 @@ bots.forEach(function(bot) { name: bot.name, connections: { - sphero: { adaptor: 'sphero', port: bot.port } + sphero: { adaptor: "sphero", port: bot.port } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, totalBucks: 1, @@ -141,7 +143,7 @@ bots.forEach(function(bot) { my.bankrupt(); my.changeDirection(); - my.sphero.on('collision', function() { + my.sphero.on("collision", function() { my.sphero.setRGB(0x0000FF); my.sphero.stop(); my.payingPower = false; @@ -151,7 +153,7 @@ bots.forEach(function(bot) { bucks: "" + (my.totalBucks++) }); - var sf = Cylon.robots['salesforce']; + var sf = Cylon.robots["salesforce"]; sf.devices.salesforce.push("SpheroController", "POST", data); }); } diff --git a/examples/sphero_shakeometer/sphero_shakeometer.js b/examples/sphero_shakeometer/sphero_shakeometer.js index fc28316..fdadcad 100644 --- a/examples/sphero_shakeometer/sphero_shakeometer.js +++ b/examples/sphero_shakeometer/sphero_shakeometer.js @@ -1,26 +1,33 @@ -var Cylon = require('cylon'); +"use strict"; + +var Cylon = require("cylon"); Cylon.robot({ connections: { - sphero: { adaptor: 'sphero', port: '/dev/tty.Sphero-YBW-RN-SPP' } + sphero: { adaptor: "sphero", port: "/dev/tty.Sphero-YBW-RN-SPP" } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, work: function(my) { var max = 0; var changingColor = false; - my.sphero.setDataStreaming(['velocity'], { n: 40, m: 1, pcnt: 0 }); - my.sphero.on('data', function(data) { + my.sphero.setDataStreaming(["velocity"], { n: 40, m: 1, pcnt: 0 }); + my.sphero.on("data", function(data) { if(!changingColor) { - x = Math.abs(data[0]); - y = Math.abs(data[1]); + var x = Math.abs(data[0]), + y = Math.abs(data[1]); - if (x > max) max = x; - if (y > max) max = y; + if (x > max) { + max = x; + } + + if (y > max) { + max = y; + } } }); @@ -28,19 +35,19 @@ Cylon.robot({ changingColor = true; if (max < 10) { - my.sphero.setColor('white'); + my.sphero.setColor("white"); } else if (max < 100) { - my.sphero.setColor('lightyellow'); + my.sphero.setColor("lightyellow"); } else if (max < 150) { - my.sphero.setColor('yellow'); + my.sphero.setColor("yellow"); } else if (max < 250) { - my.sphero.setColor('orange'); + my.sphero.setColor("orange"); } else if (max < 350) { - my.sphero.setColor('orangered'); + my.sphero.setColor("orangered"); } else if (max < 450) { - my.sphero.setColor('red'); + my.sphero.setColor("red"); } else { - my.sphero.setColor('darkred'); + my.sphero.setColor("darkred"); } max = 0; diff --git a/examples/travis/travis.js b/examples/travis/travis.js index cad9e96..9f815e6 100644 --- a/examples/travis/travis.js +++ b/examples/travis/travis.js @@ -1,15 +1,17 @@ -var Cylon = require('../..'), - Travis = require('travis-ci'); +"use strict"; -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({ connections: { - sphero: { adaptor: 'sphero', port: '/dev/rfcomm0' } + sphero: { adaptor: "sphero", port: "/dev/rfcomm0" } }, devices: { - sphero: { driver: 'sphero' } + sphero: { driver: "sphero" } }, work: function(my) { @@ -18,23 +20,23 @@ Cylon.robot({ var checkTravis = function() { 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) { - if (res.repo === undefined) { my.sphero.setColor('blue', true); } + if (res.repo === undefined) { my.sphero.setColor("blue", true); } switch (res.repo.last_build_state) { - case 'passed': - my.sphero.setColor('green', true); + case "passed": + my.sphero.setColor("green", true); break; - case 'failed': - my.sphero.setColor('red', true); + case "failed": + my.sphero.setColor("red", true); break; default: - my.sphero.setColor('blue', true); + my.sphero.setColor("blue", true); } }); - } + }; checkTravis();