node-poweredup/multipletest.js
2018-06-12 17:17:26 +01:00

46 lines
1.2 KiB
JavaScript

const LPF2 = require("./lpf2.js");
const lpf2 = new LPF2();
let wedoUUID = "0ae95acf801e47f9bda4752392756eed",
wedoHub = null,
boostUUID = "782a5fbbcef64c5cb31ab4791c191f5d",
boostHub = null;
lpf2.scan();
lpf2.on("discover", (hub) => {
if (hub.uuid === wedoUUID) {
wedoHub = hub;
wedoHub.connect();
wedoHub.on("distance", (port, distance) => {
console.log(`Distance ${distance} received on WeDo port ${port}`);
if (boostHub) {
if (distance < 30) {
boostHub.setMotorSpeed("C", 40);
} else {
boostHub.setMotorSpeed("C", 0);
}
}
});
return;
}
if (hub.uuid === boostUUID) {
boostHub = hub;
boostHub.connect();
boostHub.on("distance", (port, distance) => {
console.log(`Distance ${distance} received on Boost port ${port}`);
if (wedoHub) {
if (distance < 30) {
wedoHub.setMotorSpeed("B", 40);
} else {
wedoHub.setMotorSpeed("B", 0);
}
}
});
return;
}
});