Merge master and multiple examples
This commit is contained in:
parent
95aa7f8962
commit
8ccf93ce40
|
@ -6,15 +6,14 @@ bots = [
|
|||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||
]
|
||||
|
||||
SpheroRobot =
|
||||
connection:
|
||||
name: 'Sphero', adaptor: 'sphero'
|
||||
class SpheroRobot
|
||||
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||
|
||||
work: (my) ->
|
||||
Logger.info "Robot #{my.name} is now working!"
|
||||
|
||||
for bot in bots
|
||||
robot = Object.create(SpheroRobot)
|
||||
robot = new SpheroRobot
|
||||
robot.connection.port = bot.port
|
||||
robot.name = bot.name
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Cylon = require('../..');
|
||||
|
||||
var bots = [
|
||||
|
@ -7,17 +6,22 @@ var bots = [
|
|||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||
];
|
||||
|
||||
var SpheroRobot = {
|
||||
connection: { name: 'Sphero', adaptor: 'sphero' },
|
||||
var SpheroRobot = (function() {
|
||||
function SpheroRobot() {}
|
||||
|
||||
work: function(my) {
|
||||
SpheroRobot.prototype.connection = { name: 'Sphero', adaptor: 'sphero' };
|
||||
|
||||
SpheroRobot.prototype.work = function(my) {
|
||||
Logger.info("Robot " + my.name + " is now working!");
|
||||
}
|
||||
};
|
||||
|
||||
return SpheroRobot;
|
||||
|
||||
})();
|
||||
|
||||
for (var i = 0; i < bots.length; i++) {
|
||||
var bot = bots[i];
|
||||
var robot = Object.create(SpheroRobot);
|
||||
var robot = new SpheroRobot;
|
||||
|
||||
robot.connection.port = bot.port;
|
||||
robot.name = bot.name;
|
||||
|
|
|
@ -24,16 +24,15 @@ a base robot and change it's attributes as needed.
|
|||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||
]
|
||||
|
||||
Now we can define our cleverly-named `SpheroRobot` object. This will be the base
|
||||
object for all three of the robots.
|
||||
Now we can define our cleverly-named `SpheroRobot` class. This will be the base
|
||||
class for all three of the robots.
|
||||
|
||||
SpheroRobot =
|
||||
class SpheroRobot
|
||||
|
||||
Every robot needs to connect to a Sphero. We're doing this using the
|
||||
`cylon-sphero` adaptor.
|
||||
|
||||
connection:
|
||||
name: 'Sphero', adaptor: 'sphero'
|
||||
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||
|
||||
We'll just give our robots some basic work so we can tell they're actually
|
||||
working:
|
||||
|
@ -43,12 +42,12 @@ working:
|
|||
|
||||
And that's all we need for that.
|
||||
|
||||
Next up, we'll create Cylon robots by making a duplicate of the `SpheroRobot`
|
||||
object, and modifying the attributes that are unique to each robot. After the
|
||||
Next up, we'll create Cylon robots by making an instance of the `SpheroRobot`
|
||||
class, and modifying the attributes that are unique to each robot. After the
|
||||
customized robot is ready, we'll feed it into Cylon.
|
||||
|
||||
for bot in bots
|
||||
robot = Object.create(SpheroRobot)
|
||||
robot = new SpheroRobot
|
||||
robot.connection.port = bot.port
|
||||
robot.name = bot.name
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
Cylon = require '../..'
|
||||
|
||||
bots = [
|
||||
{ name: 'Huey' },
|
||||
{ name: 'Dewey' },
|
||||
{ name: 'Louie' }
|
||||
]
|
||||
|
||||
class ChattyRobot
|
||||
connection: { name: 'loopback', adaptor: 'loopback' }
|
||||
device: { name: 'ping', driver: 'ping' }
|
||||
|
||||
hello: (my) ->
|
||||
Logger.info "#{my.name}: #{my.ping.ping()}"
|
||||
|
||||
work: (my) ->
|
||||
every 1.seconds(), ->
|
||||
my.hello(my)
|
||||
|
||||
for bot in bots
|
||||
robot = new ChattyRobot
|
||||
robot.name = bot.name
|
||||
Cylon.robot robot
|
||||
|
||||
Cylon.start()
|
|
@ -1,40 +0,0 @@
|
|||
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();
|
Loading…
Reference in New Issue