From 288718228273bdcf550693c051024dab567966e4 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 18 Apr 2016 21:52:38 -0400 Subject: [PATCH] Sequencer and firmware work together --- app/js/app.js | 6 ++++++ app/lib/mcopy-arduino.js | 10 +++++----- app/main.js | 15 ++++++++++++++- app/src/index.js | 6 ++++++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/js/app.js b/app/js/app.js index a86ccb8..0f60d0a 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -2771,6 +2771,7 @@ cmd.cam_forward = function (rgb, callback) { var res = function (ms) { gui.updateState(); setTimeout(function () { + light.display([0,0,0]); light.set([0, 0, 0], function () { if (callback) { callback(ms); } }); @@ -2779,6 +2780,7 @@ cmd.cam_forward = function (rgb, callback) { if (!mcopy.state.camera.direction) { cam.set(true, function () { setTimeout( function () { + light.display(rgb); light.set(rgb, function () { setTimeout( function () { cam.move(res); @@ -2787,6 +2789,7 @@ cmd.cam_forward = function (rgb, callback) { }, mcopy.cfg.arduino.serialDelay); }); } else { + light.display(rgb); light.set(rgb, function () { setTimeout(function () { cam.move(res); @@ -2803,6 +2806,7 @@ cmd.cam_backward = function (rgb, callback) { 'use strict'; var res = function (ms) { gui.updateState(); + light.display([0,0,0]); light.set([0, 0, 0], function () { if (callback) { callback(ms); } }); @@ -2810,6 +2814,7 @@ cmd.cam_backward = function (rgb, callback) { if (mcopy.state.camera.direction) { cam.set(false, function () { setTimeout(function () { + light.display(rgb); light.set(rgb, function () { cam.move(res); }); @@ -2817,6 +2822,7 @@ cmd.cam_backward = function (rgb, callback) { }); } else { setTimeout(function () { + light.display(rgb); light.set(rgb, function () { cam.move(res); }); diff --git a/app/lib/mcopy-arduino.js b/app/lib/mcopy-arduino.js index 56f7a5a..be6f481 100644 --- a/app/lib/mcopy-arduino.js +++ b/app/lib/mcopy-arduino.js @@ -28,7 +28,7 @@ mcopy.arduino = { }; mcopy.arduino.enumerate = function (callback) { 'use strict'; - console.log('Searching for devices...'); + //console.log('Searching for devices...'); var cmd = 'ls /dev/tty.*'; exec(cmd, function (e, std) { var devices = std.split('\n'), @@ -85,7 +85,7 @@ mcopy.arduino.end = function (data) { ms = end - mcopy.arduino.timer; if (mcopy.arduino.queue[data] !== undefined) { mcopy.arduino.lock = false; - console.log('Command ' + data + ' took ' + ms + 'ms'); + //console.log('Command ' + data + ' took ' + ms + 'ms'); mcopy.arduino.queue[data](ms); //execute callback delete mcopy.arduino.queue[data]; } else { @@ -104,7 +104,7 @@ mcopy.arduino.connect = function (serial, device, confirm, callback) { if (callback) { callback(error); } return console.log('failed to open: '+ error); } else { - console.log('Opened connection with ' + mcopy.arduino.path[serial]); + //console.log('Opened connection with ' + mcopy.arduino.path[serial]); if (!confirm) { mcopy.arduino.serial[serial].on('data', function (data) { data = data.replace('\r', ''); @@ -176,7 +176,7 @@ mcopy.arduino.close = function (callback) { }; mcopy.arduino.fakeConnect = function (serial, callback) { - console.log('Connecting to fake arduino...'); + //console.log('Connecting to fake arduino...'); mcopy.arduino.serial[serial] = { write : function (cmd, res) { var t = { @@ -196,7 +196,7 @@ mcopy.arduino.fakeConnect = function (serial, callback) { }, fake : true }; - console.log('Connected to fake arduino! Not real! Doesn\'t exist!'); + //console.log('Connected to fake arduino! Not real! Doesn\'t exist!'); if (callback) callback(); }; diff --git a/app/main.js b/app/main.js index 815ca5a..4ed65b0 100644 --- a/app/main.js +++ b/app/main.js @@ -118,10 +118,23 @@ var distinguishDevices = function (devices) { }); } } + if (devices.length > 1) { + distinguishDevice(devices[1], distinguishTwo); + } }); }, distinguishTwo = function (err, type) { - + arduino.close(function () { + if (type === 'projector') { + arduino.connect('projector', devices[1], false, function () { + log.info('Connected to ' + devices[1] + ' as PROJECTOR', 'SERIAL', true, true); + }); + } else if (type === 'camera') { + arduino.connect('camera', devices[1], false, function () { + log.info('Connected to ' + devices[1] + ' as CAMERA', 'SERIAL', true, true); + }); + } + }); }; distinguishDevice(devices[0], distinguishOne); }; diff --git a/app/src/index.js b/app/src/index.js index 05d1c80..02b4a2e 100644 --- a/app/src/index.js +++ b/app/src/index.js @@ -315,6 +315,7 @@ cmd.cam_forward = function (rgb, callback) { var res = function (ms) { gui.updateState(); setTimeout(function () { + light.display([0,0,0]); light.set([0, 0, 0], function () { if (callback) { callback(ms); } }); @@ -323,6 +324,7 @@ cmd.cam_forward = function (rgb, callback) { if (!mcopy.state.camera.direction) { cam.set(true, function () { setTimeout( function () { + light.display(rgb); light.set(rgb, function () { setTimeout( function () { cam.move(res); @@ -331,6 +333,7 @@ cmd.cam_forward = function (rgb, callback) { }, mcopy.cfg.arduino.serialDelay); }); } else { + light.display(rgb); light.set(rgb, function () { setTimeout(function () { cam.move(res); @@ -347,6 +350,7 @@ cmd.cam_backward = function (rgb, callback) { 'use strict'; var res = function (ms) { gui.updateState(); + light.display([0,0,0]); light.set([0, 0, 0], function () { if (callback) { callback(ms); } }); @@ -354,6 +358,7 @@ cmd.cam_backward = function (rgb, callback) { if (mcopy.state.camera.direction) { cam.set(false, function () { setTimeout(function () { + light.display(rgb); light.set(rgb, function () { cam.move(res); }); @@ -361,6 +366,7 @@ cmd.cam_backward = function (rgb, callback) { }); } else { setTimeout(function () { + light.display(rgb); light.set(rgb, function () { cam.move(res); });