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 .idea
node_modules node_modules
data
+17 -5
Ver Arquivo
@@ -42,7 +42,7 @@ function onBoardReady () {
console.log(experiment.name + ' experiment started'); console.log(experiment.name + ' experiment started');
board.streamStart(); board.streamStart();
board.on('sample', addPattern); board.on('sample', addPattern);
setTimeout(endExperiment, experiment.duration); setTimeout(disconnectBoard, experiment.duration);
} }
// Add pattern // Add pattern
@@ -60,10 +60,8 @@ function addPattern (sample) {
console.log('pattern', pattern); console.log('pattern', pattern);
} }
// End Experiment // Save experiment
function endExperiment () { function saveExperiment () {
board.streamStop()
.then(board.disconnect());
jsonfile.writeFile(experiment.filePath, experiment, { spaces: 2 }, function (error) { jsonfile.writeFile(experiment.filePath, experiment, { spaces: 2 }, function (error) {
if (!error) { if (!error) {
console.log(experiment.name + ' experiment finished with ' + experiment.patternsTotal + ' patterns'); 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);
});
}