2014-12-14 08:19:25 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
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: {
|
2014-12-14 08:19:25 +08:00
|
|
|
led00: { driver: "led", pin: 13 }
|
2014-11-26 01:45:20 +08:00
|
|
|
}
|
|
|
|
},
|
2014-03-06 04:50:39 +08:00
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
{
|
|
|
|
name: "arduin01",
|
|
|
|
port: "/dev/ttyACM1",
|
|
|
|
devices: {
|
2014-12-14 08:19:25 +08:00
|
|
|
led10: { driver: "led", pin: 11 },
|
|
|
|
led11: { driver: "led", pin: 12 },
|
|
|
|
led12: { driver: "led", pin: 13 }
|
2014-11-26 01:45:20 +08:00
|
|
|
}
|
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-26 08:01:31 +08:00
|
|
|
connections: {
|
|
|
|
skynet: {
|
2014-12-14 08:19:25 +08:00
|
|
|
adaptor: "skynet",
|
2014-11-26 08:01:31 +08:00
|
|
|
uuid: "96630051-a3dc-11e3-8442-5bf31d98c912",
|
|
|
|
token: "2s67o7ek98pycik98f43reqr90t6s9k9"
|
|
|
|
}
|
2014-11-11 04:37:33 +08:00
|
|
|
},
|
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
|
|
|
|
2014-12-14 08:19:25 +08:00
|
|
|
if (robot.cmd === "on") {
|
2014-11-26 01:45:20 +08:00
|
|
|
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) {
|
2014-12-14 08:19:25 +08:00
|
|
|
my.skynet.on("message", my.handler);
|
2014-11-26 01:45:20 +08:00
|
|
|
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 08:01:31 +08:00
|
|
|
connections: {
|
2014-12-14 08:19:25 +08:00
|
|
|
arduino: { adaptor: "firmata", port: bot.port }
|
2014-11-26 08:01:31 +08:00
|
|
|
},
|
|
|
|
|
2014-11-26 01:45:20 +08:00
|
|
|
devices: bot.devices,
|
|
|
|
|
|
|
|
work: function(my) {
|
|
|
|
console.log(my.name + " is online");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-06 04:50:39 +08:00
|
|
|
|
|
|
|
Cylon.start();
|