Sequencer and firmware work together

This commit is contained in:
Matt 2016-04-18 21:52:38 -04:00
parent f4b75d7398
commit 2887182282
4 changed files with 31 additions and 6 deletions

View File

@ -2771,6 +2771,7 @@ cmd.cam_forward = function (rgb, callback) {
var res = function (ms) { var res = function (ms) {
gui.updateState(); gui.updateState();
setTimeout(function () { setTimeout(function () {
light.display([0,0,0]);
light.set([0, 0, 0], function () { light.set([0, 0, 0], function () {
if (callback) { callback(ms); } if (callback) { callback(ms); }
}); });
@ -2779,6 +2780,7 @@ cmd.cam_forward = function (rgb, callback) {
if (!mcopy.state.camera.direction) { if (!mcopy.state.camera.direction) {
cam.set(true, function () { cam.set(true, function () {
setTimeout( function () { setTimeout( function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
setTimeout( function () { setTimeout( function () {
cam.move(res); cam.move(res);
@ -2787,6 +2789,7 @@ cmd.cam_forward = function (rgb, callback) {
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
}); });
} else { } else {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
setTimeout(function () { setTimeout(function () {
cam.move(res); cam.move(res);
@ -2803,6 +2806,7 @@ cmd.cam_backward = function (rgb, callback) {
'use strict'; 'use strict';
var res = function (ms) { var res = function (ms) {
gui.updateState(); gui.updateState();
light.display([0,0,0]);
light.set([0, 0, 0], function () { light.set([0, 0, 0], function () {
if (callback) { callback(ms); } if (callback) { callback(ms); }
}); });
@ -2810,6 +2814,7 @@ cmd.cam_backward = function (rgb, callback) {
if (mcopy.state.camera.direction) { if (mcopy.state.camera.direction) {
cam.set(false, function () { cam.set(false, function () {
setTimeout(function () { setTimeout(function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
cam.move(res); cam.move(res);
}); });
@ -2817,6 +2822,7 @@ cmd.cam_backward = function (rgb, callback) {
}); });
} else { } else {
setTimeout(function () { setTimeout(function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
cam.move(res); cam.move(res);
}); });

View File

@ -28,7 +28,7 @@ mcopy.arduino = {
}; };
mcopy.arduino.enumerate = function (callback) { mcopy.arduino.enumerate = function (callback) {
'use strict'; 'use strict';
console.log('Searching for devices...'); //console.log('Searching for devices...');
var cmd = 'ls /dev/tty.*'; var cmd = 'ls /dev/tty.*';
exec(cmd, function (e, std) { exec(cmd, function (e, std) {
var devices = std.split('\n'), var devices = std.split('\n'),
@ -85,7 +85,7 @@ mcopy.arduino.end = function (data) {
ms = end - mcopy.arduino.timer; ms = end - mcopy.arduino.timer;
if (mcopy.arduino.queue[data] !== undefined) { if (mcopy.arduino.queue[data] !== undefined) {
mcopy.arduino.lock = false; 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 mcopy.arduino.queue[data](ms); //execute callback
delete mcopy.arduino.queue[data]; delete mcopy.arduino.queue[data];
} else { } else {
@ -104,7 +104,7 @@ mcopy.arduino.connect = function (serial, device, confirm, callback) {
if (callback) { callback(error); } if (callback) { callback(error); }
return console.log('failed to open: '+ error); return console.log('failed to open: '+ error);
} else { } else {
console.log('Opened connection with ' + mcopy.arduino.path[serial]); //console.log('Opened connection with ' + mcopy.arduino.path[serial]);
if (!confirm) { if (!confirm) {
mcopy.arduino.serial[serial].on('data', function (data) { mcopy.arduino.serial[serial].on('data', function (data) {
data = data.replace('\r', ''); data = data.replace('\r', '');
@ -176,7 +176,7 @@ mcopy.arduino.close = function (callback) {
}; };
mcopy.arduino.fakeConnect = function (serial, callback) { mcopy.arduino.fakeConnect = function (serial, callback) {
console.log('Connecting to fake arduino...'); //console.log('Connecting to fake arduino...');
mcopy.arduino.serial[serial] = { mcopy.arduino.serial[serial] = {
write : function (cmd, res) { write : function (cmd, res) {
var t = { var t = {
@ -196,7 +196,7 @@ mcopy.arduino.fakeConnect = function (serial, callback) {
}, },
fake : true 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(); if (callback) callback();
}; };

View File

@ -118,10 +118,23 @@ var distinguishDevices = function (devices) {
}); });
} }
} }
if (devices.length > 1) {
distinguishDevice(devices[1], distinguishTwo);
}
}); });
}, },
distinguishTwo = function (err, type) { 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); distinguishDevice(devices[0], distinguishOne);
}; };

View File

@ -315,6 +315,7 @@ cmd.cam_forward = function (rgb, callback) {
var res = function (ms) { var res = function (ms) {
gui.updateState(); gui.updateState();
setTimeout(function () { setTimeout(function () {
light.display([0,0,0]);
light.set([0, 0, 0], function () { light.set([0, 0, 0], function () {
if (callback) { callback(ms); } if (callback) { callback(ms); }
}); });
@ -323,6 +324,7 @@ cmd.cam_forward = function (rgb, callback) {
if (!mcopy.state.camera.direction) { if (!mcopy.state.camera.direction) {
cam.set(true, function () { cam.set(true, function () {
setTimeout( function () { setTimeout( function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
setTimeout( function () { setTimeout( function () {
cam.move(res); cam.move(res);
@ -331,6 +333,7 @@ cmd.cam_forward = function (rgb, callback) {
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
}); });
} else { } else {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
setTimeout(function () { setTimeout(function () {
cam.move(res); cam.move(res);
@ -347,6 +350,7 @@ cmd.cam_backward = function (rgb, callback) {
'use strict'; 'use strict';
var res = function (ms) { var res = function (ms) {
gui.updateState(); gui.updateState();
light.display([0,0,0]);
light.set([0, 0, 0], function () { light.set([0, 0, 0], function () {
if (callback) { callback(ms); } if (callback) { callback(ms); }
}); });
@ -354,6 +358,7 @@ cmd.cam_backward = function (rgb, callback) {
if (mcopy.state.camera.direction) { if (mcopy.state.camera.direction) {
cam.set(false, function () { cam.set(false, function () {
setTimeout(function () { setTimeout(function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
cam.move(res); cam.move(res);
}); });
@ -361,6 +366,7 @@ cmd.cam_backward = function (rgb, callback) {
}); });
} else { } else {
setTimeout(function () { setTimeout(function () {
light.display(rgb);
light.set(rgb, function () { light.set(rgb, function () {
cam.move(res); cam.move(res);
}); });