cylon/examples/api/api.js

42 lines
710 B
JavaScript
Raw Permalink Normal View History

2014-12-14 08:19:25 +08:00
"use strict";
var Cylon = require("../..");
// ensure you install the API plugin first:
// $ npm install cylon-api-http
2014-11-26 01:45:20 +08:00
Cylon.api({
2014-12-14 08:19:25 +08:00
host: "0.0.0.0",
port: "8080"
});
2014-09-30 06:15:42 +08:00
var bots = {
2015-04-15 12:49:12 +08:00
Thelma: "/dev/rfcomm0",
Louise: "/dev/rfcomm1"
};
2014-09-30 06:15:42 +08:00
Object.keys(bots).forEach(function(name) {
var port = bots[name];
2014-09-30 06:15:42 +08:00
Cylon.robot({
name: name,
2014-11-26 08:01:31 +08:00
connections: {
2014-12-14 08:19:25 +08:00
sphero: { adaptor: "sphero", port: port }
2014-11-26 08:01:31 +08:00
},
devices: {
2014-12-14 08:19:25 +08:00
sphero: { driver: "sphero" }
2014-11-26 08:01:31 +08:00
},
2014-09-30 06:15:42 +08:00
work: function(my) {
every((1).seconds(), function() {
console.log(my.name);
my.sphero.setRandomColor();
my.sphero.roll(60, Math.floor(Math.random() * 360));
});
}
});
});
Cylon.start();