Disconnect board issue fixed

Esse commit está contido em:
Alex Castillo
2016-04-08 16:03:15 -04:00
commit f994e098d3
2 arquivos alterados com 18 adições e 5 exclusões
+1
Ver Arquivo
@@ -1,2 +1,3 @@
.idea
node_modules
data
+17 -5
Ver Arquivo
@@ -42,7 +42,7 @@ function onBoardReady () {
console.log(experiment.name + ' experiment started');
board.streamStart();
board.on('sample', addPattern);
setTimeout(endExperiment, experiment.duration);
setTimeout(disconnectBoard, experiment.duration);
}
// Add pattern
@@ -60,10 +60,8 @@ function addPattern (sample) {
console.log('pattern', pattern);
}
// End Experiment
function endExperiment () {
board.streamStop()
.then(board.disconnect());
// Save experiment
function saveExperiment () {
jsonfile.writeFile(experiment.filePath, experiment, { spaces: 2 }, function (error) {
if (!error) {
console.log(experiment.name + ' experiment finished with ' + experiment.patternsTotal + ' patterns');
@@ -74,4 +72,18 @@ function endExperiment () {
});
}
/**
* Disconnect board
*/
function disconnectBoard () {
board.streamStop()
.then(function () {
setTimeout(function () {
board.disconnect();
saveExperiment();
console.log('board disconnected');
}, 50);
});
}