WIP on organizing examples and making sure there are JS and CS versions of both
This commit is contained in:
parent
f619b5694d
commit
47bc59fe3d
|
@ -1,23 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
devices:
|
|
||||||
[
|
|
||||||
{name: 'sensor', driver: 'analogSensor', pin: 0, upperLimit: 900, lowerLimit: 100},
|
|
||||||
]
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
#my.sensor.on('analogRead', (val) ->
|
|
||||||
# console.log("AnalogValue ===> #{ val }")
|
|
||||||
#)
|
|
||||||
my.sensor.on('upperLimit', (val) ->
|
|
||||||
console.log("Upper limit reached ===> #{ val }")
|
|
||||||
)
|
|
||||||
my.sensor.on('lowerLimit', (val) ->
|
|
||||||
console.log("Lower limit reached ===> #{ val }")
|
|
||||||
)
|
|
||||||
.start()
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection:
|
||||||
|
name: 'arduino'
|
||||||
|
adaptor: 'firmata'
|
||||||
|
port: '/dev/ttyACM0'
|
||||||
|
|
||||||
|
device:
|
||||||
|
name: 'sensor'
|
||||||
|
driver: 'analogSensor'
|
||||||
|
pin: 0
|
||||||
|
upperLimit: 900
|
||||||
|
lowerLimit: 100
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
my.sensor.on 'upperLimit', (val) ->
|
||||||
|
Logger.info "Upper limit reached ===> #{val}"
|
||||||
|
|
||||||
|
my.sensor.on 'lowerLimit', (val) ->
|
||||||
|
Logger.info "Lower limit reached ===> #{val}"
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,28 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: {
|
||||||
|
name: 'arduino',
|
||||||
|
adaptor: 'firmata',
|
||||||
|
port: '/dev/ttyACM0'
|
||||||
|
},
|
||||||
|
|
||||||
|
device: {
|
||||||
|
name: 'sensor',
|
||||||
|
driver: 'analogSensor',
|
||||||
|
pin: 0,
|
||||||
|
upperLimit: 900,
|
||||||
|
lowerLimit: 100
|
||||||
|
},
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.sensor.on('upperLimit', function(val) {
|
||||||
|
Logger.info("Upper limit reached ===> " + val);
|
||||||
|
});
|
||||||
|
|
||||||
|
my.sensor.on('lowerLimit', function(val) {
|
||||||
|
Logger.info("Lower limit reached ===> " + val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}).start();
|
|
@ -1,4 +1,4 @@
|
||||||
Cylon = require '..'
|
Cylon = require '../..'
|
||||||
|
|
||||||
Cylon.api host: '0.0.0.0', port: '8080'
|
Cylon.api host: '0.0.0.0', port: '8080'
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@ bots = [
|
||||||
]
|
]
|
||||||
|
|
||||||
SpheroRobot =
|
SpheroRobot =
|
||||||
connection:
|
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||||
name: 'Sphero', adaptor: 'sphero'
|
|
||||||
|
|
||||||
device:
|
device: { name: 'sphero', driver: 'sphero' }
|
||||||
name: 'sphero', driver: 'sphero'
|
|
||||||
|
|
||||||
work: (me) ->
|
work: (me) ->
|
||||||
every 1.seconds(), ->
|
every 1.seconds(), ->
|
||||||
|
@ -21,9 +19,10 @@ SpheroRobot =
|
||||||
me.sphero.roll 60, Math.floor(Math.random() * 360)
|
me.sphero.roll 60, Math.floor(Math.random() * 360)
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = Object.create(SpheroRobot)
|
robot = Object.create SpheroRobot
|
||||||
robot.connection.port = bot.port
|
robot.connection.port = bot.port
|
||||||
robot.name = bot.name
|
robot.name = bot.name
|
||||||
|
|
||||||
Cylon.robot robot
|
Cylon.robot robot
|
||||||
|
|
||||||
Cylon.start()
|
Cylon.start()
|
|
@ -0,0 +1,34 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.api({ host: '0.0.0.0', port: '8080' });
|
||||||
|
|
||||||
|
var bots = [
|
||||||
|
{ port: '/dev/rfcomm0', name: 'Thelma' },
|
||||||
|
{ port: '/dev/rfcomm1', name: 'Louise' }
|
||||||
|
];
|
||||||
|
|
||||||
|
var SpheroRobot = {
|
||||||
|
connection: { name: 'Sphero', adaptor: 'sphero' },
|
||||||
|
|
||||||
|
device: { name: 'sphero', driver: 'sphero' },
|
||||||
|
|
||||||
|
work: function(me) {
|
||||||
|
every((1).seconds(), function() {
|
||||||
|
Logger.info(me.name);
|
||||||
|
me.sphero.setRGB(Math.floor(Math.random() * 100000));
|
||||||
|
return me.sphero.roll(60, Math.floor(Math.random() * 360));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < bots.length; i++) {
|
||||||
|
var bot = bots[i];
|
||||||
|
var robot = Object.create(SpheroRobot);
|
||||||
|
|
||||||
|
robot.connection.port = bot.port;
|
||||||
|
robot.name = bot.name;
|
||||||
|
|
||||||
|
Cylon.robot(robot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cylon.start();
|
|
@ -1,15 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'led', driver: 'led', pin: 13
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
# we do our thing here
|
|
||||||
every 1.second(), -> my.led.toggle()
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
# Initialize the robot
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
||||||
|
|
||||||
|
device: { name: 'led', driver: 'led', pin: 13 }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
every 1.second(), -> my.led.toggle()
|
||||||
|
|
||||||
|
.start()
|
|
@ -1,6 +1,5 @@
|
||||||
var Cylon = require('..');
|
var Cylon = require('../..');
|
||||||
|
|
||||||
// Initialize the robot
|
|
||||||
Cylon.robot({
|
Cylon.robot({
|
||||||
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
device: {name: 'led', driver: 'led', pin: 13},
|
device: {name: 'led', driver: 'led', pin: 13},
|
|
@ -1,21 +1,18 @@
|
||||||
Cylon = require('..')
|
Cylon = require '../..'
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
Cylon.robot
|
||||||
connection:
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
device:
|
device: { name: 'blinkm', driver: 'blinkm' }
|
||||||
name: 'blinkm', driver: 'blinkm'
|
|
||||||
|
|
||||||
work: (my) ->
|
work: (my) ->
|
||||||
# we do our thing here
|
|
||||||
my.blinkm.on 'start', ->
|
my.blinkm.on 'start', ->
|
||||||
my.blinkm.version (version) ->
|
my.blinkm.version (version) ->
|
||||||
Logger.info "Started BlinkM version #{version}"
|
Logger.info "Started BlinkM version #{version}"
|
||||||
|
|
||||||
my.blinkm.off()
|
my.blinkm.off()
|
||||||
lit = false
|
lit = false
|
||||||
|
|
||||||
every 1.second(), ->
|
every 1.second(), ->
|
||||||
if lit
|
if lit
|
||||||
lit = false
|
lit = false
|
||||||
|
@ -24,6 +21,6 @@ Cylon.robot
|
||||||
else
|
else
|
||||||
lit = true
|
lit = true
|
||||||
Logger.info 'off'
|
Logger.info 'off'
|
||||||
my.blinkm.rgb 0, 0, 0
|
my.blinkm.rgb 0, 0, 0
|
||||||
|
|
||||||
.start()
|
.start()
|
|
@ -0,0 +1,31 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
|
|
||||||
|
device: { name: 'blinkm', driver: 'blinkm' },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.blinkm.on('start', function() {
|
||||||
|
my.blinkm.version(function(version) {
|
||||||
|
Logger.info("Started BlinkM version " + version);
|
||||||
|
});
|
||||||
|
|
||||||
|
my.blinkm.off();
|
||||||
|
|
||||||
|
var lit = false;
|
||||||
|
|
||||||
|
every((1).second(), function() {
|
||||||
|
if (lit) {
|
||||||
|
lit = false;
|
||||||
|
Logger.info('on');
|
||||||
|
my.blinkm.rgb(0xaa, 0, 0);
|
||||||
|
} else {
|
||||||
|
lit = true;
|
||||||
|
Logger.info('off');
|
||||||
|
my.blinkm.rgb(0, 0, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,17 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
devices:
|
|
||||||
[
|
|
||||||
{name: 'led', driver: 'led', pin: 13},
|
|
||||||
{name: 'button', driver: 'button', pin: 2}
|
|
||||||
]
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
my.button.on 'push', -> my.led.toggle()
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -1,12 +0,0 @@
|
||||||
var Cylon = require('..');
|
|
||||||
|
|
||||||
// Initialize the robot
|
|
||||||
Cylon.robot({
|
|
||||||
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
|
||||||
devices: [{name: 'led', driver: 'led', pin: 13},
|
|
||||||
{name: 'button', driver: 'button', pin: 2}],
|
|
||||||
|
|
||||||
work: function(my) {
|
|
||||||
my.button.on('push', function() {my.led.toggle()});
|
|
||||||
}
|
|
||||||
}).start();
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
Cylon = require('../..')
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection:
|
||||||
|
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
||||||
|
|
||||||
|
devices: [
|
||||||
|
{ name: 'led', driver: 'led', pin: 13 },
|
||||||
|
{ name: 'button', driver: 'button', pin: 2 }
|
||||||
|
]
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
my.button.on 'push', -> my.led.toggle()
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,16 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
|
|
||||||
|
devices: [
|
||||||
|
{ name: 'led', driver: 'led', pin: 13 },
|
||||||
|
{ name: 'button', driver: 'button', pin: 2 }
|
||||||
|
],
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.button.on('push', function() {
|
||||||
|
my.led.toggle();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,53 +1,49 @@
|
||||||
Cylon = require '..'
|
Cylon = require '../..'
|
||||||
|
|
||||||
bots = [
|
bots = [
|
||||||
{ port: '/dev/rfcomm0', name: 'Thelma' }
|
{ port: '/dev/rfcomm0', name: 'Thelma' }
|
||||||
# { port: '/dev/rfcomm1', name: 'Louise' },
|
{ port: '/dev/rfcomm1', name: 'Louise' },
|
||||||
# { port: '/dev/rfcomm2', name: 'Grace' },
|
{ port: '/dev/rfcomm2', name: 'Grace' },
|
||||||
# { port: '/dev/rfcomm3', name: 'Ada' }
|
{ port: '/dev/rfcomm3', name: 'Ada' }
|
||||||
]
|
]
|
||||||
|
|
||||||
Green = 0x0000FF
|
Green = 0x0000FF
|
||||||
Red = 0xFF0000
|
Red = 0xFF0000
|
||||||
|
|
||||||
class ConwayRobot
|
class ConwayRobot
|
||||||
connection:
|
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||||
name: 'Sphero', adaptor: 'sphero'
|
device: { name: 'sphero', driver: 'sphero' }
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'sphero', driver: 'sphero'
|
|
||||||
|
|
||||||
born: ->
|
born: ->
|
||||||
@contacts = 0
|
@contacts = 0
|
||||||
@age = 0
|
@age = 0
|
||||||
this.life()
|
@life()
|
||||||
this.move()
|
@move()
|
||||||
|
|
||||||
move: ->
|
move: ->
|
||||||
this.sphero.roll 60, Math.floor(Math.random() * 360)
|
@sphero.roll 60, Math.floor(Math.random() * 360)
|
||||||
|
|
||||||
life: ->
|
life: ->
|
||||||
@alive = true
|
@alive = true
|
||||||
this.sphero.setRGB Green
|
@sphero.setRGB Green
|
||||||
|
|
||||||
death: ->
|
death: ->
|
||||||
@alive = false
|
@alive = false
|
||||||
this.sphero.setRGB Green
|
@sphero.setRGB Green
|
||||||
this.sphero.stop()
|
@sphero.stop()
|
||||||
|
|
||||||
enoughContacts: ->
|
enoughContacts: ->
|
||||||
if @contacts >= 2 and @contacts < 7
|
if @contacts >= 2 and @contacts < 7 then true else false
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
|
|
||||||
birthday: ->
|
birthday: ->
|
||||||
@age += 1
|
@age += 1
|
||||||
|
|
||||||
Logger.info "Happy birthday, #{@name}. You are #{@age} and had #{@contacts} contacts."
|
Logger.info "Happy birthday, #{@name}. You are #{@age} and had #{@contacts} contacts."
|
||||||
if this.enoughContacts()
|
|
||||||
this.rebirth() if not @alive?
|
if @enoughContacts()
|
||||||
|
@rebirth() if not @alive?
|
||||||
else
|
else
|
||||||
this.death()
|
@death()
|
||||||
|
|
||||||
@contacts = 0
|
@contacts = 0
|
||||||
|
|
||||||
|
@ -63,7 +59,6 @@ class ConwayRobot
|
||||||
every 10.seconds(), ->
|
every 10.seconds(), ->
|
||||||
me.birthday() if me.alive?
|
me.birthday() if me.alive?
|
||||||
|
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = new ConwayRobot
|
robot = new ConwayRobot
|
||||||
robot.connection.port = bot.port
|
robot.connection.port = bot.port
|
|
@ -0,0 +1,94 @@
|
||||||
|
var ConwayRobot, Cylon, Green, Red, bot, bots, robot, _i, _len;
|
||||||
|
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
var bots = [
|
||||||
|
{ port: '/dev/rfcomm0', name: 'Thelma' },
|
||||||
|
{ port: '/dev/rfcomm1', name: 'Louise' },
|
||||||
|
{ port: '/dev/rfcomm2', name: 'Grace' },
|
||||||
|
{ port: '/dev/rfcomm3', name: 'Ada' }
|
||||||
|
];
|
||||||
|
|
||||||
|
var Green = 0x0000FF;
|
||||||
|
var Red = 0xFF0000;
|
||||||
|
|
||||||
|
var ConwayRobot = (function() {
|
||||||
|
function ConwayRobot() {}
|
||||||
|
|
||||||
|
ConwayRobot.prototype.connection = { name: 'Sphero', adaptor: 'sphero' };
|
||||||
|
ConwayRobot.prototype.device = { name: 'sphero', driver: 'sphero' };
|
||||||
|
|
||||||
|
ConwayRobot.prototype.born = function() {
|
||||||
|
this.contacts = 0;
|
||||||
|
this.age = 0;
|
||||||
|
this.life();
|
||||||
|
return this.move();
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.move = function() {
|
||||||
|
return this.sphero.roll(60, Math.floor(Math.random() * 360));
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.life = function() {
|
||||||
|
this.alive = true;
|
||||||
|
return this.sphero.setRGB(Green);
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.death = function() {
|
||||||
|
this.alive = false;
|
||||||
|
this.sphero.setRGB(Green);
|
||||||
|
return this.sphero.stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.enoughContacts = function() {
|
||||||
|
if (this.contacts >= 2 && this.contacts < 7) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.birthday = function() {
|
||||||
|
this.age += 1;
|
||||||
|
|
||||||
|
Logger.info("Happy birthday, " + this.name + ". You are " + this.age + " and had " + this.contacts + " contacts.");
|
||||||
|
|
||||||
|
if (this.enoughContacts()) {
|
||||||
|
if (this.alive == null) { this.rebirth(); }
|
||||||
|
} else {
|
||||||
|
this.death();
|
||||||
|
}
|
||||||
|
return this.contacts = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
ConwayRobot.prototype.work = function(me) {
|
||||||
|
me.born();
|
||||||
|
|
||||||
|
me.sphero.on('collision', function() {
|
||||||
|
return this.contacts += 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
every((3).seconds(), function() {
|
||||||
|
if (me.alive != null) { return me.move(); }
|
||||||
|
});
|
||||||
|
|
||||||
|
return every((10).seconds(), function() {
|
||||||
|
if (me.alive != null) { return me.birthday(); }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return ConwayRobot;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
for (var i = 0; i < bots.length; i++) {
|
||||||
|
var bot = bots[i];
|
||||||
|
var robot = new ConwayRobot;
|
||||||
|
|
||||||
|
robot.connection.port = bot.port;
|
||||||
|
robot.name = bot.name;
|
||||||
|
|
||||||
|
Cylon.robot(robot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cylon.start();
|
|
@ -1,19 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1'
|
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'drone', driver: 'ardrone'
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
my.drone.takeoff()
|
|
||||||
|
|
||||||
after 10.seconds(), ->
|
|
||||||
my.drone.land()
|
|
||||||
|
|
||||||
after 15.seconds(), ->
|
|
||||||
my.drone.stop()
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -1,17 +0,0 @@
|
||||||
var Cylon = require('..');
|
|
||||||
|
|
||||||
Cylon.robot({
|
|
||||||
connection: {name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1'},
|
|
||||||
device: {name: 'drone', driver: 'ardrone'},
|
|
||||||
work: function(my) {
|
|
||||||
my.drone.takeoff();
|
|
||||||
|
|
||||||
after((10).seconds(), function() {
|
|
||||||
my.drone.land();
|
|
||||||
}
|
|
||||||
|
|
||||||
after((15).seconds(), function() {
|
|
||||||
my.drone.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' }
|
||||||
|
device: { name: 'drone', driver: 'ardrone' }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
my.drone.takeoff()
|
||||||
|
after 10.seconds(), -> my.drone.land()
|
||||||
|
after 15.seconds(), -> my.drone.stop()
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,12 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' },
|
||||||
|
device: { name: 'drone', driver: 'ardrone' },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.drone.takeoff();
|
||||||
|
after(10..seconds(), function() { my.drone.land(); });
|
||||||
|
after(15..seconds(), function() { my.drone.stop(); });
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,19 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1'
|
|
||||||
|
|
||||||
devices:
|
|
||||||
[
|
|
||||||
{name: 'drone', driver: 'ardrone'},
|
|
||||||
{name: 'nav', driver: 'ardroneNav'}
|
|
||||||
]
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
my.drone.config('general:navdata_demo', 'TRUE')
|
|
||||||
|
|
||||||
my.nav.on 'update', (data) ->
|
|
||||||
Logger.info data
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection:
|
||||||
|
name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1'
|
||||||
|
|
||||||
|
devices: [
|
||||||
|
{name: 'drone', driver: 'ardrone'},
|
||||||
|
{name: 'nav', driver: 'ardroneNav'}
|
||||||
|
]
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
my.drone.config 'general:navdata_demo', 'TRUE'
|
||||||
|
my.nav.on 'update', (data) -> Logger.info data
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,14 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' },
|
||||||
|
devices: [
|
||||||
|
{ name: 'drone', driver: 'ardrone' },
|
||||||
|
{ name: 'nav', driver: 'ardroneNav' }
|
||||||
|
],
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.drone.config('general:navdata_demo', 'TRUE');
|
||||||
|
my.nav.on('update', function(data) { Logger.info(data); });
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,10 +0,0 @@
|
||||||
var Cylon = require('..');
|
|
||||||
|
|
||||||
Cylon.robot({
|
|
||||||
connection: { name: 'looped', adaptor: 'loopback'},
|
|
||||||
|
|
||||||
work: function() {
|
|
||||||
every((1).second(), function() { Logger.info("Hello, human!"); });
|
|
||||||
after((10).seconds(), function() { Logger.info("Impressive."); });
|
|
||||||
}
|
|
||||||
}).start();
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
work: function() {
|
||||||
|
every(1..second(), function() { Logger.info("Hello, human!"); });
|
||||||
|
after(10..seconds(), function() { Logger.info("Impressive."); });
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,17 +1,13 @@
|
||||||
Cylon = require('..')
|
Cylon = require '../..'
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
Cylon.robot
|
||||||
connection:
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
device: { name: 'led', driver: 'led', pin: 3 }
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'led', driver: 'led', pin: 3
|
|
||||||
|
|
||||||
work: (my) ->
|
work: (my) ->
|
||||||
# we do our thing here
|
|
||||||
brightness = 0
|
brightness = 0
|
||||||
fade = 5
|
fade = 5
|
||||||
|
|
||||||
every 0.05.seconds(), ->
|
every 0.05.seconds(), ->
|
||||||
brightness += fade
|
brightness += fade
|
||||||
my.led.brightness(brightness)
|
my.led.brightness(brightness)
|
|
@ -0,0 +1,19 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
|
device: { name: 'led', driver: 'led', pin: 3 },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
var brightness = 0;
|
||||||
|
var fade = 5;
|
||||||
|
|
||||||
|
every(0.05.seconds(), function() {
|
||||||
|
brightness += fade;
|
||||||
|
my.led.brightness(brightness);
|
||||||
|
if ((brightness === 0) || (brightness === 255)) {
|
||||||
|
fade = -fade;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,4 +1,4 @@
|
||||||
Cylon = require '..'
|
Cylon = require '../..'
|
||||||
|
|
||||||
bots = [
|
bots = [
|
||||||
{ port: '/dev/cu.Sphero-RGB', name: 'Huey' },
|
{ port: '/dev/cu.Sphero-RGB', name: 'Huey' },
|
||||||
|
@ -10,8 +10,8 @@ SpheroRobot =
|
||||||
connection:
|
connection:
|
||||||
name: 'Sphero', adaptor: 'sphero'
|
name: 'Sphero', adaptor: 'sphero'
|
||||||
|
|
||||||
work: (self) ->
|
work: (my) ->
|
||||||
console.log "Robot #{self.name} is now working!"
|
Logger.info "Robot #{my.name} is now working!"
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = Object.create(SpheroRobot)
|
robot = Object.create(SpheroRobot)
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Generated by CoffeeScript 1.6.3
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
var bots = [
|
||||||
|
{ port: '/dev/cu.Sphero-RGB', name: 'Huey' },
|
||||||
|
{ port: '/dev/cu.Sphero-GRB', name: 'Dewey' },
|
||||||
|
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||||
|
];
|
||||||
|
|
||||||
|
var SpheroRobot = {
|
||||||
|
connection: { name: 'Sphero', adaptor: 'sphero' },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
Logger.info("Robot " + my.name + " is now working!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < bots.length; i++) {
|
||||||
|
var bot = bots[i];
|
||||||
|
var robot = Object.create(SpheroRobot);
|
||||||
|
|
||||||
|
robot.connection.port = bot.port;
|
||||||
|
robot.name = bot.name;
|
||||||
|
|
||||||
|
Cylon.robot(robot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cylon.start();
|
|
@ -1,20 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'motor', driver: 'motor', pin: 3
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
speed = 0
|
|
||||||
increment = 5
|
|
||||||
every 0.05.seconds(), ->
|
|
||||||
speed += increment
|
|
||||||
my.motor.speed(speed)
|
|
||||||
console.log("current speed => #{ my.motor.currentSpeed() }")
|
|
||||||
increment = -increment if (speed is 0) or (speed is 255)
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
||||||
|
device: { name: 'motor', driver: 'motor', pin: 3 }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
speed = 0
|
||||||
|
increment = 5
|
||||||
|
|
||||||
|
every 0.05.seconds(), ->
|
||||||
|
speed += increment
|
||||||
|
my.motor.speed(speed)
|
||||||
|
Logger.info "Current Speed: #{my.motor.currentSpeed() }"
|
||||||
|
increment = -increment if (speed is 0) or (speed is 255)
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,20 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
|
device: { name: 'motor', driver: 'motor', pin: 3 },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
var speed = 0;
|
||||||
|
var increment = 5;
|
||||||
|
|
||||||
|
every(0.05.seconds(), function() {
|
||||||
|
speed += increment;
|
||||||
|
my.motor.speed(speed);
|
||||||
|
|
||||||
|
Logger.info("Current Speed: " + (my.motor.currentSpeed()));
|
||||||
|
|
||||||
|
if ((speed === 0) || (speed === 255)) { increment = -increment; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,4 +1,4 @@
|
||||||
Cylon = require '..'
|
Cylon = require '../..'
|
||||||
|
|
||||||
bots = [
|
bots = [
|
||||||
{ name: 'Huey' },
|
{ name: 'Huey' },
|
||||||
|
@ -7,18 +7,15 @@ bots = [
|
||||||
]
|
]
|
||||||
|
|
||||||
class ChattyRobot
|
class ChattyRobot
|
||||||
connection:
|
connection: { name: 'loopback', adaptor: 'loopback' }
|
||||||
name: 'loopback', adaptor: 'loopback'
|
device: { name: 'ping', driver: 'ping' }
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'ping', driver: 'ping'
|
|
||||||
|
|
||||||
hello: (my) ->
|
hello: (my) ->
|
||||||
Logger.info "#{my.name}: #{my.ping.ping()}"
|
Logger.info "#{my.name}: #{my.ping.ping()}"
|
||||||
|
|
||||||
work: (my) ->
|
work: (my) ->
|
||||||
every 1.seconds(), ->
|
every 1.seconds(), ->
|
||||||
my.hello(my)
|
my.hello(my)
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = new ChattyRobot
|
robot = new ChattyRobot
|
|
@ -0,0 +1,40 @@
|
||||||
|
var bot, bots, robot, _i, _len;
|
||||||
|
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
bots = [
|
||||||
|
{ name: 'Huey' },
|
||||||
|
{ name: 'Dewey' },
|
||||||
|
{ name: 'Louie' }
|
||||||
|
];
|
||||||
|
|
||||||
|
var ChattyRobot = (function() {
|
||||||
|
function ChattyRobot() {}
|
||||||
|
|
||||||
|
ChattyRobot.prototype.connection = { name: 'loopback', adaptor: 'loopback' };
|
||||||
|
ChattyRobot.prototype.device = { name: 'ping', driver: 'ping' };
|
||||||
|
|
||||||
|
ChattyRobot.prototype.hello = function(my) {
|
||||||
|
Logger.info("" + my.name + ": " + (my.ping.ping()));
|
||||||
|
};
|
||||||
|
|
||||||
|
ChattyRobot.prototype.work = function(my) {
|
||||||
|
every((1).seconds(), function() {
|
||||||
|
my.hello(my);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return ChattyRobot;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
for (var i = 0; i < bots.length; i++) {
|
||||||
|
var bot = bots[i];
|
||||||
|
var robot = new ChattyRobot;
|
||||||
|
|
||||||
|
robot.name = bot.name;
|
||||||
|
|
||||||
|
Cylon.robot(robot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cylon.start();
|
|
@ -1,21 +0,0 @@
|
||||||
class Person
|
|
||||||
constructor: (args = {}) ->
|
|
||||||
@name = args.name
|
|
||||||
@age = args.age
|
|
||||||
|
|
||||||
noSuchMethod: (args) ->
|
|
||||||
console.log("You called method #{ args[0] } with params #{ args }, no such method exist")
|
|
||||||
|
|
||||||
sayHi: (var1, var2, var3) ->
|
|
||||||
console.log("Saying Hi! #{var1}, #{var2}, #{var3}")
|
|
||||||
|
|
||||||
execute: () ->
|
|
||||||
if typeof(this[arguments[0]]) is 'function'
|
|
||||||
this[arguments[0]].apply(this, Array.prototype.slice.call(arguments, 1))
|
|
||||||
else
|
|
||||||
this.noSuchMethod(arguments)
|
|
||||||
|
|
||||||
person = new Person({name: 'Leonidas', age:123})
|
|
||||||
|
|
||||||
person.execute('sayHi', 1, 2, 3)
|
|
||||||
person.execute('sayHello', 1, 2, 3)
|
|
|
@ -1,18 +0,0 @@
|
||||||
require('../dist/digital-pin')
|
|
||||||
|
|
||||||
pin4 = new Cylon.IO.DigitalPin(pin: 4, mode: 'w')
|
|
||||||
|
|
||||||
pin4.on('open', (data) ->
|
|
||||||
console.log("Pin files have been created")
|
|
||||||
)
|
|
||||||
|
|
||||||
pin4.on('digitalWrite', (value) ->
|
|
||||||
console.log("Value writen to pin -> #{ value }")
|
|
||||||
)
|
|
||||||
|
|
||||||
pin4.on('connect', (data) ->
|
|
||||||
console.log("Pin mode has been setup!")
|
|
||||||
pin4.setHigh()
|
|
||||||
)
|
|
||||||
|
|
||||||
pin4.connect()
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
require '../../dist/digital-pin'
|
||||||
|
|
||||||
|
pin4 = new Cylon.IO.DigitalPin(pin: 4, mode: 'w')
|
||||||
|
|
||||||
|
pin4.on 'open', (data) -> console.log "Pin files have been created"
|
||||||
|
|
||||||
|
pin4.on 'digitalWrite', (value) ->
|
||||||
|
console.log "Value written to pin: #{value}"
|
||||||
|
|
||||||
|
pin4.on 'connect', (data) ->
|
||||||
|
console.log "Pin mode has been setup!"
|
||||||
|
pin4.setHigh()
|
||||||
|
|
||||||
|
pin4.connect()
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Generated by CoffeeScript 1.6.3
|
||||||
|
require('../../dist/digital-pin');
|
||||||
|
|
||||||
|
var pin4 = new Cylon.IO.DigitalPin({ pin: 4, mode: 'w' });
|
||||||
|
|
||||||
|
pin4.on('open', function(data) {
|
||||||
|
console.log("Pin files have been created");
|
||||||
|
});
|
||||||
|
|
||||||
|
pin4.on('digitalWrite', function(value) {
|
||||||
|
console.log("Value written to pin: " + value);
|
||||||
|
});
|
||||||
|
|
||||||
|
pin4.on('connect', function(data) {
|
||||||
|
console.log("Pin mode has been setup!");
|
||||||
|
pin4.setHigh();
|
||||||
|
});
|
||||||
|
|
||||||
|
pin4.connect();
|
|
@ -1,34 +0,0 @@
|
||||||
spheron = require('spheron')
|
|
||||||
sphero = spheron.sphero()
|
|
||||||
spheroPort = '/dev/rfcomm0'
|
|
||||||
COLORS = spheron.toolbelt.COLORS
|
|
||||||
|
|
||||||
sphero.on('open', ->
|
|
||||||
console.log('EVENT OPEN!')
|
|
||||||
sphero.configureCollisionDetection(0x01, 0x20, 0x20, 0x20, 0x20, 0x50)
|
|
||||||
sphero.setRGB(COLORS.GREEN, false)
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.on('close', ->
|
|
||||||
console.log('EVENT CLOSE!')
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.on('end', ->
|
|
||||||
console.log('EVENT END!')
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.on('error', ->
|
|
||||||
console.log('EVENT ERROR!')
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.on('notification', (packet) ->
|
|
||||||
console.log('Packet contents:')
|
|
||||||
console.log(packet)
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.on('message', (packet) ->
|
|
||||||
console.log('Packet contents:')
|
|
||||||
console.log(packet)
|
|
||||||
)
|
|
||||||
|
|
||||||
sphero.open(spheroPort)
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
spheron = require('spheron')
|
||||||
|
|
||||||
|
sphero = spheron.sphero()
|
||||||
|
spheroPort = '/dev/rfcomm0'
|
||||||
|
|
||||||
|
COLORS = spheron.toolbelt.COLORS
|
||||||
|
|
||||||
|
sphero.on 'open', ->
|
||||||
|
console.log 'EVENT OPEN!'
|
||||||
|
sphero.configureCollisionDetection 0x01, 0x20, 0x20, 0x20, 0x20, 0x50
|
||||||
|
sphero.setRGB COLORS.GREEN, false
|
||||||
|
|
||||||
|
sphero.on 'close', -> console.log 'EVENT CLOSE!'
|
||||||
|
sphero.on 'end', -> console.log 'EVENT END!'
|
||||||
|
sphero.on 'error', -> console.log 'EVENT ERROR!'
|
||||||
|
sphero.on 'notification', (packet) -> console.log "Packet contents: #{packet}"
|
||||||
|
sphero.on 'message', (packet) -> console.log "Packet contents: #{packet}"
|
||||||
|
|
||||||
|
sphero.open spheroPort
|
|
@ -0,0 +1,34 @@
|
||||||
|
var spheron = require('spheron');
|
||||||
|
|
||||||
|
var sphero = spheron.sphero();
|
||||||
|
var spheroPort = '/dev/rfcomm0';
|
||||||
|
|
||||||
|
var COLORS = spheron.toolbelt.COLORS;
|
||||||
|
|
||||||
|
sphero.on('open', function() {
|
||||||
|
console.log('EVENT OPEN!');
|
||||||
|
sphero.configureCollisionDetection(0x01, 0x20, 0x20, 0x20, 0x20, 0x50);
|
||||||
|
sphero.setRGB(COLORS.GREEN, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.on('close', function() {
|
||||||
|
console.log('EVENT CLOSE!');
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.on('end', function() {
|
||||||
|
console.log('EVENT END!');
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.on('error', function() {
|
||||||
|
console.log('EVENT ERROR!');
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.on('notification', function(packet) {
|
||||||
|
console.log("Packet contents: " + packet);
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.on('message', function(packet) {
|
||||||
|
console.log("Packet contents: " + packet);
|
||||||
|
});
|
||||||
|
|
||||||
|
sphero.open(spheroPort);
|
|
@ -1,15 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'raspi', adaptor: 'raspi'
|
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'led', driver: 'led', pin: 11
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
# we do our thing here
|
|
||||||
every 1.second(), -> my.led.toggle()
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'raspi', adaptor: 'raspi' }
|
||||||
|
device: { name: 'led', driver: 'led', pin: 11 }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
every 1.second(), -> my.led.toggle()
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,10 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'raspi', adaptor: 'raspi' },
|
||||||
|
device: { name: 'led', driver: 'led', pin: 11 },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
every((1).second(), function() { my.led.toggle(); });
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,17 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'raspi', adaptor: 'raspi'
|
|
||||||
|
|
||||||
devices:
|
|
||||||
[
|
|
||||||
{name: 'led', driver: 'led', pin: 11},
|
|
||||||
{name: 'button', driver: 'button', pin: 7}
|
|
||||||
]
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
my.button.on 'push', () -> my.led.toggle()
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'raspi', adaptor: 'raspi' }
|
||||||
|
|
||||||
|
devices: [
|
||||||
|
{name: 'led', driver: 'led', pin: 11},
|
||||||
|
{name: 'button', driver: 'button', pin: 7}
|
||||||
|
]
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
my.button.on 'push', -> my.led.toggle()
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,14 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'raspi', adaptor: 'raspi' },
|
||||||
|
|
||||||
|
devices: [
|
||||||
|
{ name: 'led', driver: 'led', pin: 11 },
|
||||||
|
{ name: 'button', driver: 'button', pin: 7 }
|
||||||
|
],
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
my.button.on('push', function() { my.led.toggle(); });
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,32 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
Cylon.robot
|
|
||||||
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'
|
|
||||||
|
|
||||||
work: (me) ->
|
|
||||||
|
|
||||||
me.salesforce.on('start', () ->
|
|
||||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
|
||||||
Logger.info "Sphero: #{ data.sobject.Sphero_Name__c }, Bucks: #{ data.sobject.Bucks__c }, SM_Id: #{ data.sobject.Id }"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
every 2.seconds(), () ->
|
|
||||||
# push(apexPath, method, body)
|
|
||||||
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ i }\" }"
|
|
||||||
me.salesforce.push('SpheroController', 'POST', toSend)
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
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' }
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
Logger.info msg
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
every 2.seconds(), () ->
|
||||||
|
data = JSON.stringify { spheroName: "#{me.name}", bucks: "#{i}" }
|
||||||
|
me.salesforce.push 'SpheroController', 'POST', data
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,40 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
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' },
|
||||||
|
|
||||||
|
work: function(me) {
|
||||||
|
me.salesforce.on('start', function() {
|
||||||
|
me.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;
|
||||||
|
|
||||||
|
Logger.info(msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
every((2).seconds(), function() {
|
||||||
|
var data = JSON.stringify({
|
||||||
|
spheroName: "" + me.name,
|
||||||
|
bucks: "" + i
|
||||||
|
});
|
||||||
|
|
||||||
|
me.salesforce.push('SpheroController', 'POST', data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,20 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
# Initialize the robot
|
|
||||||
Cylon.robot
|
|
||||||
connection:
|
|
||||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'servo', driver: 'servo', pin: 3
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
angle = 0
|
|
||||||
increment = 90
|
|
||||||
every 1.seconds(), ->
|
|
||||||
angle += increment
|
|
||||||
my.servo.angle(angle)
|
|
||||||
console.log("Current Angle => #{ my.servo.currentAngle() }")
|
|
||||||
increment = -increment if (angle is 0) or (angle is 180)
|
|
||||||
|
|
||||||
.start()
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
||||||
|
device: { name: 'servo', driver: 'servo', pin: 3 }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
angle = 0
|
||||||
|
increment = 90
|
||||||
|
|
||||||
|
every 1.seconds(), ->
|
||||||
|
angle += increment
|
||||||
|
my.servo.angle angle
|
||||||
|
|
||||||
|
Logger.info "Current Angle: #{my.servo.currentAngle()}"
|
||||||
|
|
||||||
|
increment = -increment if (angle is 0) or (angle is 180)
|
||||||
|
|
||||||
|
.start()
|
|
@ -0,0 +1,20 @@
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
Cylon.robot({
|
||||||
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
|
||||||
|
device: { name: 'servo', driver: 'servo', pin: 3 },
|
||||||
|
|
||||||
|
work: function(my) {
|
||||||
|
var angle = 0;
|
||||||
|
var increment = 90;
|
||||||
|
|
||||||
|
every(1..seconds(), function() {
|
||||||
|
angle += increment;
|
||||||
|
my.servo.angle(angle);
|
||||||
|
|
||||||
|
Logger.info("Current Angle: " + (my.servo.currentAngle()));
|
||||||
|
|
||||||
|
if ((angle === 0) || (angle === 180)) { increment = -increment; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
|
@ -1,52 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
nforce = require('nforce')
|
|
||||||
faye = require('faye')
|
|
||||||
|
|
||||||
namespace = require('node-namespace')
|
|
||||||
|
|
||||||
namespace 'SF', ->
|
|
||||||
class @SFClient
|
|
||||||
constructor: (opts) ->
|
|
||||||
@client = null
|
|
||||||
@outboundMessages = []
|
|
||||||
@sfuser = opts.sfuser
|
|
||||||
@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.error('unable to authenticate to sfdc')
|
|
||||||
console.log(err)
|
|
||||||
process.exit(code=0)
|
|
||||||
else
|
|
||||||
console.log("authenticated")
|
|
||||||
@oauth = _oauth
|
|
||||||
@_handleStreamingAPI(outboundCB)
|
|
||||||
@_processOutboundMessages()
|
|
||||||
)
|
|
||||||
|
|
||||||
push: (msg) ->
|
|
||||||
#jsonBody = JSON.parse(msg)
|
|
||||||
#jsonString = JSON.stringify(msg)
|
|
||||||
jsonString = msg
|
|
||||||
console.log("SpheroController post msg:")
|
|
||||||
console.log(msg)
|
|
||||||
@org.apexRest({uri:'SpheroController', method: 'POST', body: jsonString}, @oauth, (err,resp) =>
|
|
||||||
if(err)
|
|
||||||
console.log(err)
|
|
||||||
else
|
|
||||||
console.log(resp)
|
|
||||||
)
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
namespace = require 'node-namespace'
|
||||||
|
nforce = require 'nforce'
|
||||||
|
Faye = require 'faye'
|
||||||
|
|
||||||
|
namespace 'SF', ->
|
||||||
|
class @SFClient
|
||||||
|
constructor: (opts) ->
|
||||||
|
@client = null
|
||||||
|
@outboundMessages = []
|
||||||
|
@sfuser = opts.sfuser
|
||||||
|
@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
|
|
@ -0,0 +1,67 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var namespace = require('node-namespace');
|
||||||
|
var nforce = require('nforce');
|
||||||
|
var Faye = require('faye');
|
||||||
|
|
||||||
|
namespace('SF', function() {
|
||||||
|
this.SFClient = (function() {
|
||||||
|
|
||||||
|
function SFClient(opts) {
|
||||||
|
this.client = null;
|
||||||
|
this.outboundMessages = [];
|
||||||
|
this.sfuser = opts.sfuser;
|
||||||
|
this.sfpass = opts.sfpass;
|
||||||
|
this.orgCreds = opts.orgCredentials;
|
||||||
|
this.org = nforce.createConnection(this.orgCreds);
|
||||||
|
}
|
||||||
|
|
||||||
|
SFClient.prototype._processOutboundMessages = function() {};
|
||||||
|
|
||||||
|
SFClient.prototype._handleStreamingAPI = function(outboundCB) {
|
||||||
|
var client, subscription;
|
||||||
|
client = new Faye.Client("" + this.oauth.instance_url + "/cometd/28.0");
|
||||||
|
client.setHeader("Authorization", "OAuth " + this.oauth.access_token);
|
||||||
|
subscription = client.subscribe('/topic/SpheroMsgOutbound', outboundCB);
|
||||||
|
console.log("Streaming API Connected...");
|
||||||
|
};
|
||||||
|
|
||||||
|
SFClient.prototype.authenticate = function(outboundCB) {
|
||||||
|
var _this = this;
|
||||||
|
this.org.authenticate({
|
||||||
|
username: this.sfuser,
|
||||||
|
password: this.sfpass
|
||||||
|
}, function(err, _oauth) {
|
||||||
|
if (err) {
|
||||||
|
console.log('unable to authenticate to sfdc');
|
||||||
|
console.log(err);
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.log("authenticated");
|
||||||
|
_this.oauth = _oauth;
|
||||||
|
_this._handleStreamingAPI(outboundCB);
|
||||||
|
_this._processOutboundMessages();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SFClient.prototype.push = function(msg) {
|
||||||
|
var jsonString, methodData,
|
||||||
|
_this = this;
|
||||||
|
jsonString = msg;
|
||||||
|
console.log("SpheroController post msg:");
|
||||||
|
console.log(msg);
|
||||||
|
methodData = {
|
||||||
|
uri: 'SpheroController',
|
||||||
|
method: 'POST',
|
||||||
|
body: jsonString
|
||||||
|
};
|
||||||
|
this.org.apexRest(methodData, this.oauth, function(err, resp) {
|
||||||
|
console.log(err ? err : resp);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return SFClient;
|
||||||
|
|
||||||
|
})();
|
||||||
|
});
|
|
@ -1,68 +0,0 @@
|
||||||
Cylon = require('..')
|
|
||||||
|
|
||||||
class SalesforceRobot
|
|
||||||
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'
|
|
||||||
|
|
||||||
work: (me) ->
|
|
||||||
me.salesforce.on('start', () ->
|
|
||||||
me.salesforce.subscribe('/topic/SpheroMsgOutbound', (data) ->
|
|
||||||
spheroName = data.sobject.Sphero_Name__c
|
|
||||||
bucks = data.sobject.Bucks__c
|
|
||||||
Logger.info "Sphero: #{ spheroName }, data Bucks: #{ bucks }, SM_Id: #{ data.sobject.Id }"
|
|
||||||
me.master.findRobot(spheroName, (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', ->
|
|
||||||
Logger.info('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()
|
|
||||||
toSend = "{ \"spheroName\" :\"#{ me.name }\", \"bucks\": \"#{ me.totalBucks++ }\" }"
|
|
||||||
me.master.findRobot('salesforce', (err, sf) ->
|
|
||||||
sf.devices.salesforce.push('SpheroController', 'POST', toSend)
|
|
||||||
)
|
|
||||||
|
|
||||||
sfRobot = new SalesforceRobot()
|
|
||||||
sfRobot.name = "salesforce"
|
|
||||||
Cylon.robot sfRobot
|
|
||||||
|
|
||||||
spheroRobot = new SpheroRobot()
|
|
||||||
spheroRobot.name = 'ROY'
|
|
||||||
spheroRobot.connection.port = '/dev/rfcomm0'
|
|
||||||
Cylon.robot spheroRobot
|
|
||||||
|
|
||||||
Cylon.start()
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
Cylon = require '../..'
|
||||||
|
|
||||||
|
class SalesforceRobot
|
||||||
|
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' }
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
Logger.info 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', ->
|
||||||
|
Logger.info '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
|
||||||
|
|
||||||
|
Cylon.start()
|
|
@ -0,0 +1,92 @@
|
||||||
|
var __bind = function(fn, me) {
|
||||||
|
return function() { return fn.apply(me, arguments); };
|
||||||
|
};
|
||||||
|
|
||||||
|
var Cylon = require('../..');
|
||||||
|
|
||||||
|
var SalesforceRobot = (function() {
|
||||||
|
function SalesforceRobot() {}
|
||||||
|
|
||||||
|
SalesforceRobot.prototype.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'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SalesforceRobot.prototype.device = { name: 'salesforce', driver: 'force' };
|
||||||
|
|
||||||
|
SalesforceRobot.prototype.work = function(me) {
|
||||||
|
me.salesforce.on('start', function() {
|
||||||
|
me.salesforce.subscribe('/topic/SpheroMsgOutbound', function(data) {
|
||||||
|
var msg;
|
||||||
|
msg = "Sphero: " + data.sobject.Sphero_Name__c + ",";
|
||||||
|
msg += "Bucks: " + data.sobject.Bucks__c + ",";
|
||||||
|
msg += "SM_Id: " + data.sobject.Id;
|
||||||
|
Logger.info(msg);
|
||||||
|
me.master.findRobot(data.sobject.Sphero_Name__c, function(err, spheroBot) {
|
||||||
|
spheroBot.react(spheroBot.devices.sphero);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return SalesforceRobot;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
var SpheroRobot = (function() {
|
||||||
|
function SpheroRobot() {
|
||||||
|
this.react = __bind(this.react, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpheroRobot.prototype.totalBucks = 0;
|
||||||
|
|
||||||
|
SpheroRobot.prototype.connection = { name: 'sphero', adaptor: 'sphero' };
|
||||||
|
SpheroRobot.prototype.device = { name: 'sphero', driver: 'sphero' };
|
||||||
|
|
||||||
|
SpheroRobot.prototype.react = function(robot) {
|
||||||
|
robot.setRGB(0x00FF00);
|
||||||
|
robot.roll(90, Math.floor(Math.random() * 360));
|
||||||
|
};
|
||||||
|
|
||||||
|
SpheroRobot.prototype.work = function(me) {
|
||||||
|
me.sphero.on('connect', function() {
|
||||||
|
Logger.info('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', function(data) {
|
||||||
|
me.sphero.setRGB(0x0000FF, me);
|
||||||
|
me.sphero.stop();
|
||||||
|
data = JSON.stringify({
|
||||||
|
spheroName: "" + me.name,
|
||||||
|
bucks: "" + (me.totalBucks++)
|
||||||
|
});
|
||||||
|
me.master.findRobot('salesforce', function(err, sf) {
|
||||||
|
sf.devices.salesforce.push('SpheroController', 'POST', data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return SpheroRobot;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
var sfRobot = new SalesforceRobot();
|
||||||
|
sfRobot.name = "salesforce";
|
||||||
|
Cylon.robot(sfRobot);
|
||||||
|
|
||||||
|
var spheroRobot = new SpheroRobot();
|
||||||
|
spheroRobot.name = 'ROY';
|
||||||
|
spheroRobot.connection.port = '/dev/rfcomm0';
|
||||||
|
Cylon.robot(spheroRobot);
|
||||||
|
|
||||||
|
Cylon.start();
|
|
@ -1,29 +0,0 @@
|
||||||
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) ->
|
|
||||||
simpleMessageString = "^ Sphero Name: #{msg.sobject.Sphero_Name__c}, Msg Content:#{ msg.sobject.Content__c }, SM Id:#{ msg.sobject.Id }"
|
|
||||||
console.log("Printed from callback in client program.program")
|
|
||||||
console.log(simpleMessageString + "\n")
|
|
||||||
)
|
|
||||||
|
|
||||||
myId = null
|
|
||||||
message = "hello"
|
|
||||||
detail = "Some Stuff for details"
|
|
||||||
|
|
||||||
setInterval(() =>
|
|
||||||
cc++
|
|
||||||
myId = cc
|
|
||||||
toSend = "{ \"identifier\" :\"run3#{ myId }\", \"msg\": \"#{ message }\" }"
|
|
||||||
sf.push(toSend)
|
|
||||||
, 1000)
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
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
|
|
@ -0,0 +1,38 @@
|
||||||
|
require('../examples/sf-client');
|
||||||
|
|
||||||
|
var sfuser = process.env.SF_USERNAME;
|
||||||
|
var sfpass = process.env.SF_SECURITY_TOKEN;
|
||||||
|
|
||||||
|
var orgCreds = {
|
||||||
|
clientId: process.env.SF_CLIENT_ID,
|
||||||
|
clientSecret: process.env.SF_CLIENT_SECRET,
|
||||||
|
redirectUri: 'http://localhost:3000/oauth/_callback'
|
||||||
|
};
|
||||||
|
|
||||||
|
var sf = new Cylon.SF.SFClient({
|
||||||
|
sfuser: sfuser,
|
||||||
|
sfpass: sfpass,
|
||||||
|
orgCredentials: orgCreds
|
||||||
|
});
|
||||||
|
|
||||||
|
var cc = 0;
|
||||||
|
|
||||||
|
sf.authenticate(function(msg) {
|
||||||
|
var string;
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
var myId = null;
|
||||||
|
var message = "hello";
|
||||||
|
var detail = "Some Stuff for details";
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
cc++;
|
||||||
|
myId = cc;
|
||||||
|
var data = JSON.stringify({ identifier: "run3" + myId, msg: message });
|
||||||
|
sf.push(data);
|
||||||
|
}, 1000);
|
Loading…
Reference in New Issue