2014-11-26 01:45:20 +08:00
|
|
|
var Cylon = require('../..');
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
var arduinos = [
|
|
|
|
{
|
|
|
|
name: "arduino0",
|
|
|
|
port: "/dev/ttyACM0",
|
|
|
|
devices: {
|
|
|
|
led00: { driver: 'led', pin: 13 }
|
|
|
|
}
|
|
|
|
},
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
{
|
|
|
|
name: "arduin01",
|
|
|
|
port: "/dev/ttyACM1",
|
|
|
|
devices: {
|
|
|
|
led10: { driver: 'led', pin: 11 }
|
|
|
|
led11: { driver: 'led', pin: 12 }
|
|
|
|
led12: { driver: 'led', pin: 13 }
|
|
|
|
}
|
2014-03-06 04:50:39 +08:00
|
|
|
}
|
2014-11-26 01:45:20 +08:00
|
|
|
];
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
Cylon.robot({
|
|
|
|
name: "SkynetBot",
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-11 04:37:33 +08:00
|
|
|
connection: {
|
|
|
|
name: 'skynet',
|
|
|
|
adaptor: 'skynet',
|
|
|
|
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912",
|
|
|
|
token: "2s67o7ek98pycik98f43reqr90t6s9k9"
|
|
|
|
},
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
handler: function(data) {
|
|
|
|
if (data.payload == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Data: ", data);
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
for (var i in data.payload.robots) {
|
|
|
|
var robot = data.payload.robots[i],
|
2014-06-07 02:53:54 +08:00
|
|
|
bot = Cylon.robots[robot.name];
|
2014-11-26 01:45:20 +08:00
|
|
|
|
|
|
|
if (robot.cmd === 'on') {
|
|
|
|
bot.devices[robot.device].turnOn();
|
|
|
|
} else {
|
|
|
|
bot.devices[robot.device].turnOff();
|
2014-03-06 04:50:39 +08:00
|
|
|
}
|
2014-11-26 01:45:20 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
work: function(my) {
|
|
|
|
my.skynet.on('message', my.handler)
|
|
|
|
console.log("Skynet is listening");
|
2014-03-06 04:50:39 +08:00
|
|
|
}
|
2014-11-26 01:45:20 +08:00
|
|
|
});
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
arduinos.forEach(function(bot) {
|
|
|
|
Cylon.robot({
|
|
|
|
name: bot.name,
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
connection: { name: 'arduino', adaptor: 'firmata', port: bot.port },
|
|
|
|
devices: bot.devices,
|
|
|
|
|
|
|
|
work: function(my) {
|
|
|
|
console.log(my.name + " is online");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-06 04:50:39 +08:00
|
|
|
|
|
|
|
Cylon.start();
|