Restore sequencer functionality

This commit is contained in:
Matt 2016-04-18 00:19:09 -04:00
parent 4d11f1f985
commit f17c00dea7
3 changed files with 244 additions and 231 deletions

View File

@ -2574,59 +2574,59 @@ log.info = function (action, service, status, time) {
seq.i = 0; seq.i = 0;
mcopy.loop = 1; mcopy.loop = 1;
mcopy.loopCount = 0; mcopy.loopCount = 0;
mcopy.seq_time = 0; seq.time = 0;
seq.stopState = false; seq.stopState = false;
seq.run = function () { seq.run = function () {
var cmd = mcopy.state.sequence.arr[seq.i], var c = mcopy.state.sequence.arr[seq.i],
action = function () { timeEnd = 0,
setTimeout(function () { rgb,
seq.i++; action = function () {
seq.run(); setTimeout(function () {
}, mcopy.cfg.arduino.sequenceDelay); seq.i++;
}, seq.run();
timeEnd = 0; }, mcopy.cfg.arduino.sequenceDelay);
}
if (seq.stop()) { if (seq.stop()) {
$('.row input').removeClass('h'); $('.row input').removeClass('h');
console.log('Sequence stepped'); console.log('Sequence stepped');
return false; return false;
} }
if (seq.i <= mcopy.state.sequence.arr.length && cmd !== undefined) { if (seq.i <= mcopy.state.sequence.arr.length && c !== undefined) {
console.log('Sequence step ' + seq.i + ' command ' + cmd + '...'); log.info('Step ' + seq.i + ' command ' + c, 'SEQUENCE', true);
//gui action //gui action
$('.row input').removeClass('h'); $('.row input').removeClass('h');
$('.row input[x=' + seq.i + ']').addClass('h'); $('.row input[x=' + seq.i + ']').addClass('h');
$('#numbers div[x=' + seq.i + ']').addClass('h'); $('#numbers div[x=' + seq.i + ']').addClass('h');
/*if (cmd === 'CF'){ if (c === 'CF'){
mcopy.cmd.cam_forward(action); rgb = mcopy.state.sequence.light[seq.i].split(',');
} else if (cmd === 'CB') { cmd.cam_forward(rgb, action);
mcopy.cmd.cam_backward(action); } else if (c === 'CB') {
} else if (cmd === 'PF') { rgb = mcopy.state.sequence.light[seq.i].split(',');
mcopy.cmd.proj_forward(action); cmd.cam_backward(rgb, action);
} else if (cmd === 'PB') { } else if (c === 'PF') {
mcopy.cmd.proj_backward(action); cmd.proj_forward(action);
} else if (cmd === 'BF') { } else if (c === 'PB') {
mcopy.cmd.black_forward(action); cmd.proj_backward(action);
} else if (cmd === 'BB') { } else if (c === 'BF') {
mcopy.cmd.black_backward(action); cmd.black_forward(action);
}*/ } else if (c === 'BB') {
cmd.black_backward(action);
}
} else { } else {
mcopy.loopCount++; mcopy.loopCount++;
if (mcopy.loopCount < mcopy.loop) { if (mcopy.loopCount < mcopy.loop) {
console.log('Loop ' + mcopy.loopCount + ' completed!'); log.info('Loop ' + mcopy.loopCount + ' completed', 'SEQUENCE', true);
$('.row input').removeClass('h'); $('.row input').removeClass('h');
seq.i = 0; seq.i = 0;
seq.run(); seq.run();
} else { } else {
console.log('Sequence completed!');
timeEnd = +new Date(); timeEnd = +new Date();
timeEnd = timeEnd - mcopy.seq_time; timeEnd = timeEnd - seq.time;
setTimeout(function () { if (timeEnd < 2000) {
if (timeEnd < 2000) { log.info('Sequence completed in ' + timeEnd + 'ms', 'SEQUENCE', true);
console.log('Sequence took ' + timeEnd + 'ms'); } else {
} else { log.info('Sequence completed in ' + humanizeDuration(timeEnd), 'SEQUENCE', true);
console.log('Sequence took ' + humanizeDuration(timeEnd)); }
}
}, 500);
//clear gui //clear gui
$('.row input').removeClass('h'); $('.row input').removeClass('h');
$('#numbers div').removeClass('h'); $('#numbers div').removeClass('h');
@ -2645,7 +2645,7 @@ seq.init = function (start) {
if (typeof start === 'undefined') { if (typeof start === 'undefined') {
start = 0; start = 0;
mcopy.loopCount = 0; mcopy.loopCount = 0;
mcopy.seq_time = +new Date(); seq.time = +new Date();
} }
seq.stop(false); seq.stop(false);
seq.i = start; seq.i = start;
@ -2653,7 +2653,7 @@ seq.init = function (start) {
}; };
seq.stats = function () { seq.stats = function () {
var ms = 0, var ms = 0,
cmd = '', c = '',
cam_total = 0, cam_total = 0,
proj_total = 0, proj_total = 0,
real_total = mcopy.state.sequence.arr.filter(function (elem) { real_total = mcopy.state.sequence.arr.filter(function (elem) {
@ -2665,18 +2665,18 @@ seq.stats = function () {
//timing //timing
for (var i = 0; i < mcopy.state.sequence.arr.length; i++) { for (var i = 0; i < mcopy.state.sequence.arr.length; i++) {
cmd = mcopy.state.sequence.arr[i]; c = mcopy.state.sequence.arr[i];
if (cmd === 'CF' || cmd === 'CB'){ if (c === 'CF' || c === 'CB'){
ms += mcopy.cfg.arduino.cam.time; ms += mcopy.cfg.arduino.cam.time;
ms += mcopy.cfg.arduino.cam.delay; ms += mcopy.cfg.arduino.cam.delay;
ms += mcopy.cfg.arduino.serialDelay; ms += mcopy.cfg.arduino.serialDelay;
} }
if (cmd === 'PF' || cmd === 'PB'){ if (c === 'PF' || c === 'PB'){
ms += mcopy.cfg.arduino.proj.time; ms += mcopy.cfg.arduino.proj.time;
ms += mcopy.cfg.arduino.proj.delay; ms += mcopy.cfg.arduino.proj.delay;
ms += mcopy.cfg.arduino.serialDelay; ms += mcopy.cfg.arduino.serialDelay;
} }
if (cmd === 'BF' || cmd === 'BB'){ if (c === 'BF' || c === 'BB'){
ms += mcopy.cfg.arduino.black.before; ms += mcopy.cfg.arduino.black.before;
ms += mcopy.cfg.arduino.black.after; ms += mcopy.cfg.arduino.black.after;
ms += mcopy.cfg.arduino.cam.time; ms += mcopy.cfg.arduino.cam.time;
@ -2685,16 +2685,16 @@ seq.stats = function () {
} }
ms += mcopy.cfg.arduino.sequenceDelay; ms += mcopy.cfg.arduino.sequenceDelay;
if (cmd === 'CF' || cmd === 'BF') { if (c === 'CF' || c === 'BF') {
cam_total++; cam_total++;
} }
if (cmd === 'CB' || cmd === 'BB') { if (c === 'CB' || c === 'BB') {
cam_total--; cam_total--;
} }
if (cmd === 'PF') { if (c === 'PF') {
proj_total++; proj_total++;
} }
if (cmd === 'PB') { if (c === 'PB') {
proj_total--; proj_total--;
} }
} }
@ -2727,9 +2727,10 @@ seq.clear = function () {
//mcopy.gui.updateState(); //mcopy.gui.updateState();
cmd.proj_forward = function (callback) { cmd.proj_forward = function (callback) {
'use strict';
var res = function (ms) { var res = function (ms) {
//mcopy.gui.updateState(); gui.updateState();
if (callback) { callback(); } if (callback) { callback(ms); }
}; };
if (!mcopy.state.projector.direction) { if (!mcopy.state.projector.direction) {
proj.set(true, function (ms) { proj.set(true, function (ms) {
@ -2743,75 +2744,82 @@ cmd.proj_forward = function (callback) {
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
} }
}; };
/*
cmd.cam_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved +1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
mcopy.gui.trad.updateDir({value:'cam_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
cmd.cam_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
//gui action
mcopy.gui.updateState();
mcopy.log('Camera moved -1 frame to ' + mcopy.state.camera.pos);
if (callback) { callback(); }
};
if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
mcopy.gui.trad.updateDir({value:'cam_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}
};
cmd.proj_backward = function (callback) { cmd.proj_backward = function (callback) {
'use strict';
var res = function (ms) { var res = function (ms) {
mcopy.state.projector.pos--; gui.updateState();
mcopy.gui.updateState(); if (callback) { callback(ms); }
//gui action
mcopy.log('Projector moved -1 frame to ' + mcopy.state.projector.pos);
if (callback) { callback(); }
}; };
if (mcopy.state.projector.direction) { if (mcopy.state.projector.direction) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_backward, function (ms) { proj.set(false, function (ms) {
mcopy.state.projector.direction = false;
mcopy.gui.trad.updateDir({value:'proj_backward'});
setTimeout(function () { setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res); proj.move(res);
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
}); });
} else { } else {
setTimeout(function () { setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res); proj.move(res);
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
} }
}; };
*/ cmd.cam_forward = function (rgb, callback) {
'use strict';
var res = function (ms) {
gui.updateState();
light.set([0, 0, 0], function () {
if (callback) { callback(ms); }
});
};
if (!mcopy.state.camera.direction) {
cam.set(true, function () {
setTimeout(function () {
light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay);
}
};
cmd.black_forward = function (callback) {
'use strict';
var off = [0, 0, 0];
cmd.cam_forward(off, callback);
};
cmd.cam_backward = function (rgb, callback) {
'use strict';
var res = function (ms) {
gui.updateState();
light.set([0, 0, 0], function () {
if (callback) { callback(ms); }
});
};
if (mcopy.state.camera.direction) {
cam.set(false, function () {
setTimeout(function () {
light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay);
}
};
cmd.black_backward = function (callback) {
'use strict';
var off = [0, 0, 0];
cmd.cam_backward(off, callback);
};
proj.queue = {}; proj.queue = {};
proj.lock = false; proj.lock = false;
@ -2855,13 +2863,13 @@ proj.move = function (callback) {
proj.queue[obj.id] = obj; proj.queue[obj.id] = obj;
proj.lock = true; proj.lock = true;
}; };
proj.end = function (cmd, id) { proj.end = function (c, id, ms) {
'use strict'; 'use strict';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) { if (c === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true; mcopy.state.projector.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) { } else if (c === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false; mcopy.state.projector.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.projector) { } else if (c === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) { if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1; mcopy.state.projector.pos += 1;
} else { } else {
@ -2870,7 +2878,7 @@ proj.end = function (cmd, id) {
} }
if (typeof proj.queue[id] !== 'undefined') { if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') { if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback(); proj.queue[id].callback(ms);
} }
delete proj.queue[id]; delete proj.queue[id];
proj.lock = false; proj.lock = false;
@ -2879,7 +2887,7 @@ proj.end = function (cmd, id) {
proj.listen = function () { proj.listen = function () {
'use strict'; 'use strict';
ipcRenderer.on('proj', function (event, arg) { ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id); proj.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true; return event.returnValue = true;
}); });
}; };
@ -2926,13 +2934,13 @@ cam.move = function (callback) {
cam.queue[obj.id] = obj; cam.queue[obj.id] = obj;
cam.lock = true; cam.lock = true;
}; };
cam.end = function (cmd, id) { cam.end = function (c, id, ms) {
'use strict'; 'use strict';
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) { if (c === mcopy.cfg.arduino.cmd.cam_forward) {
mcopy.state.camera.direction = true; mcopy.state.camera.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) { } else if (c === mcopy.cfg.arduino.cmd.cam_backward) {
mcopy.state.camera.direction = false; mcopy.state.camera.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.camera) { } else if (c === mcopy.cfg.arduino.cmd.camera) {
if (mcopy.state.camera.direction) { if (mcopy.state.camera.direction) {
mcopy.state.camera.pos += 1; mcopy.state.camera.pos += 1;
} else { } else {
@ -2941,7 +2949,7 @@ cam.end = function (cmd, id) {
} }
if (typeof cam.queue[id] !== 'undefined') { if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') { if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback(); cam.queue[id].callback(ms);
} }
delete cam.queue[id]; delete cam.queue[id];
cam.lock = false; cam.lock = false;
@ -2950,7 +2958,7 @@ cam.end = function (cmd, id) {
cam.listen = function () { cam.listen = function () {
'use strict'; 'use strict';
ipcRenderer.on('cam', function (event, arg) { ipcRenderer.on('cam', function (event, arg) {
cam.end(arg.cmd, arg.id); cam.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true; return event.returnValue = true;
}); });
}; };
@ -3390,14 +3398,9 @@ gui.updateProj = function (t) {
gui.updateState = function () { gui.updateState = function () {
var cpos = mcopy.state.camera.pos, var cpos = mcopy.state.camera.pos,
ppos = mcopy.state.projector.pos; ppos = mcopy.state.projector.pos;
$('#trad_cam_count').val(cpos).change();
$('#trad_proj_count').val(ppos).change();
$('#seq_cam_count').val(cpos).change(); $('#seq_cam_count').val(cpos).change();
$('#seq_proj_count').val(ppos).change(); $('#seq_proj_count').val(ppos).change();
$('#goto_cam').val(cpos).change();
$('#goto_proj').val(ppos).change();
}; };
gui.info = function (title, message) { gui.info = function (title, message) {
'use strict'; 'use strict';
@ -3497,12 +3500,12 @@ gui.grid.refresh = function () {
gui.grid.click = function (t) { gui.grid.click = function (t) {
'use strict'; 'use strict';
var i = parseInt($(t).attr('x')), var i = parseInt($(t).attr('x')),
cmd; c;
if ($(t).prop('checked')) { if ($(t).prop('checked')) {
cmd = $(t).attr('class').replace('.', ''); c = $(t).attr('class').replace('.', '');
mcopy.state.sequence.arr[i] = cmd; mcopy.state.sequence.arr[i] = c;
if (cmd === 'CF' if (c === 'CF'
|| cmd === 'CB') { || c === 'CB') {
mcopy.state.sequence.light[i] = light.color.join(','); mcopy.state.sequence.light[i] = light.color.join(',');
} else { } else {
mcopy.state.sequence.light[i] = ''; mcopy.state.sequence.light[i] = '';
@ -3528,7 +3531,6 @@ gui.grid.loopChange = function (t) {
'use strict'; 'use strict';
var count = parseInt(t.value); var count = parseInt(t.value);
mcopy.loop = count; mcopy.loop = count;
console.log('Loop count set to ' + mcopy.loop);
seq.stats(); seq.stats();
}; };
gui.grid.plus_24 = function () { gui.grid.plus_24 = function () {

View File

@ -11,11 +11,14 @@ var electron = require('electron'),
moment = require('moment'), moment = require('moment'),
Q = require('q'), Q = require('q'),
mcopy = {}, mcopy = {},
mainWindow,
mscript,
arduino; arduino;
mcopy.cfg = {}; mcopy.cfg = {};
mcopy.cfgFile = './data/cfg.json'; mcopy.cfgFile = './data/cfg.json';
mcopy.cfgInit = function () { mcopy.cfgInit = function () {
'use strict';
if (!fs.existsSync(mcopy.cfgFile)) { if (!fs.existsSync(mcopy.cfgFile)) {
console.log('Using default configuration...'); console.log('Using default configuration...');
fs.writeFileSync(mcopy.cfgFile, fs.readFileSync('./data/cfg.json.default')); fs.writeFileSync(mcopy.cfgFile, fs.readFileSync('./data/cfg.json.default'));
@ -23,12 +26,11 @@ mcopy.cfgInit = function () {
mcopy.cfg = JSON.parse(fs.readFileSync(mcopy.cfgFile, 'utf8')); mcopy.cfg = JSON.parse(fs.readFileSync(mcopy.cfgFile, 'utf8'));
}; };
mcopy.cfgStore = function () { mcopy.cfgStore = function () {
'use strict';
var data = JSON.stringify(mcopy.cfg); var data = JSON.stringify(mcopy.cfg);
fs.writeFileSync(mcopy.cfgFile, data, 'utf8'); fs.writeFileSync(mcopy.cfgFile, data, 'utf8');
}; };
var mainWindow;
var init = function () { var init = function () {
'use strict'; 'use strict';
mcopy.cfgInit(); mcopy.cfgInit();
@ -40,6 +42,7 @@ var init = function () {
cam.init(); cam.init();
arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg); arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg);
mscript = require('./lib/mscript.js');
setTimeout(function () { setTimeout(function () {
arduino.init(function (err, device) { arduino.init(function (err, device) {
if (err) { if (err) {
@ -230,15 +233,15 @@ light.listen = function () {
light.set = function (rgb, id) { light.set = function (rgb, id) {
'use strict'; 'use strict';
var str = rgb.join(','); var str = rgb.join(',');
arduino.send(mcopy.cfg.arduino.cmd.light, function () { arduino.send(mcopy.cfg.arduino.cmd.light, function (ms) {
light.end(rgb, id); light.end(rgb, id, ms);
}); });
arduino.string(str); arduino.string(str);
}; };
light.end = function (rgb, id) { light.end = function (rgb, id, ms) {
'use strict'; 'use strict';
log.info('Light set to ' + rgb.join(','), 'LIGHT', true, true); log.info('Light set to ' + rgb.join(','), 'LIGHT', true, true);
mainWindow.webContents.send('light', {rgb: rgb, id : id}); mainWindow.webContents.send('light', {rgb: rgb, id : id, ms: ms});
}; };
var proj = {}; var proj = {};
@ -295,7 +298,7 @@ proj.end = function (cmd, id, ms) {
} }
message += ' 1 frame'; message += ' 1 frame';
} }
log.info(message, 'PROJ', true, true); log.info(message, 'PROJECTOR', true, true);
mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms}); mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms});
}; };
@ -353,7 +356,7 @@ cam.end = function (cmd, id, ms) {
} }
message += ' 1 frame'; message += ' 1 frame';
} }
log.info(message, 'CAM', true, true); log.info(message, 'CAMERA', true, true);
mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms}); mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms});
}; };

View File

@ -118,59 +118,59 @@ log.info = function (action, service, status, time) {
seq.i = 0; seq.i = 0;
mcopy.loop = 1; mcopy.loop = 1;
mcopy.loopCount = 0; mcopy.loopCount = 0;
mcopy.seq_time = 0; seq.time = 0;
seq.stopState = false; seq.stopState = false;
seq.run = function () { seq.run = function () {
var cmd = mcopy.state.sequence.arr[seq.i], var c = mcopy.state.sequence.arr[seq.i],
action = function () { timeEnd = 0,
setTimeout(function () { rgb,
seq.i++; action = function () {
seq.run(); setTimeout(function () {
}, mcopy.cfg.arduino.sequenceDelay); seq.i++;
}, seq.run();
timeEnd = 0; }, mcopy.cfg.arduino.sequenceDelay);
}
if (seq.stop()) { if (seq.stop()) {
$('.row input').removeClass('h'); $('.row input').removeClass('h');
console.log('Sequence stepped'); console.log('Sequence stepped');
return false; return false;
} }
if (seq.i <= mcopy.state.sequence.arr.length && cmd !== undefined) { if (seq.i <= mcopy.state.sequence.arr.length && c !== undefined) {
console.log('Sequence step ' + seq.i + ' command ' + cmd + '...'); log.info('Step ' + seq.i + ' command ' + c, 'SEQUENCE', true);
//gui action //gui action
$('.row input').removeClass('h'); $('.row input').removeClass('h');
$('.row input[x=' + seq.i + ']').addClass('h'); $('.row input[x=' + seq.i + ']').addClass('h');
$('#numbers div[x=' + seq.i + ']').addClass('h'); $('#numbers div[x=' + seq.i + ']').addClass('h');
/*if (cmd === 'CF'){ if (c === 'CF'){
mcopy.cmd.cam_forward(action); rgb = mcopy.state.sequence.light[seq.i].split(',');
} else if (cmd === 'CB') { cmd.cam_forward(rgb, action);
mcopy.cmd.cam_backward(action); } else if (c === 'CB') {
} else if (cmd === 'PF') { rgb = mcopy.state.sequence.light[seq.i].split(',');
mcopy.cmd.proj_forward(action); cmd.cam_backward(rgb, action);
} else if (cmd === 'PB') { } else if (c === 'PF') {
mcopy.cmd.proj_backward(action); cmd.proj_forward(action);
} else if (cmd === 'BF') { } else if (c === 'PB') {
mcopy.cmd.black_forward(action); cmd.proj_backward(action);
} else if (cmd === 'BB') { } else if (c === 'BF') {
mcopy.cmd.black_backward(action); cmd.black_forward(action);
}*/ } else if (c === 'BB') {
cmd.black_backward(action);
}
} else { } else {
mcopy.loopCount++; mcopy.loopCount++;
if (mcopy.loopCount < mcopy.loop) { if (mcopy.loopCount < mcopy.loop) {
console.log('Loop ' + mcopy.loopCount + ' completed!'); log.info('Loop ' + mcopy.loopCount + ' completed', 'SEQUENCE', true);
$('.row input').removeClass('h'); $('.row input').removeClass('h');
seq.i = 0; seq.i = 0;
seq.run(); seq.run();
} else { } else {
console.log('Sequence completed!');
timeEnd = +new Date(); timeEnd = +new Date();
timeEnd = timeEnd - mcopy.seq_time; timeEnd = timeEnd - seq.time;
setTimeout(function () { if (timeEnd < 2000) {
if (timeEnd < 2000) { log.info('Sequence completed in ' + timeEnd + 'ms', 'SEQUENCE', true);
console.log('Sequence took ' + timeEnd + 'ms'); } else {
} else { log.info('Sequence completed in ' + humanizeDuration(timeEnd), 'SEQUENCE', true);
console.log('Sequence took ' + humanizeDuration(timeEnd)); }
}
}, 500);
//clear gui //clear gui
$('.row input').removeClass('h'); $('.row input').removeClass('h');
$('#numbers div').removeClass('h'); $('#numbers div').removeClass('h');
@ -189,7 +189,7 @@ seq.init = function (start) {
if (typeof start === 'undefined') { if (typeof start === 'undefined') {
start = 0; start = 0;
mcopy.loopCount = 0; mcopy.loopCount = 0;
mcopy.seq_time = +new Date(); seq.time = +new Date();
} }
seq.stop(false); seq.stop(false);
seq.i = start; seq.i = start;
@ -197,7 +197,7 @@ seq.init = function (start) {
}; };
seq.stats = function () { seq.stats = function () {
var ms = 0, var ms = 0,
cmd = '', c = '',
cam_total = 0, cam_total = 0,
proj_total = 0, proj_total = 0,
real_total = mcopy.state.sequence.arr.filter(function (elem) { real_total = mcopy.state.sequence.arr.filter(function (elem) {
@ -209,18 +209,18 @@ seq.stats = function () {
//timing //timing
for (var i = 0; i < mcopy.state.sequence.arr.length; i++) { for (var i = 0; i < mcopy.state.sequence.arr.length; i++) {
cmd = mcopy.state.sequence.arr[i]; c = mcopy.state.sequence.arr[i];
if (cmd === 'CF' || cmd === 'CB'){ if (c === 'CF' || c === 'CB'){
ms += mcopy.cfg.arduino.cam.time; ms += mcopy.cfg.arduino.cam.time;
ms += mcopy.cfg.arduino.cam.delay; ms += mcopy.cfg.arduino.cam.delay;
ms += mcopy.cfg.arduino.serialDelay; ms += mcopy.cfg.arduino.serialDelay;
} }
if (cmd === 'PF' || cmd === 'PB'){ if (c === 'PF' || c === 'PB'){
ms += mcopy.cfg.arduino.proj.time; ms += mcopy.cfg.arduino.proj.time;
ms += mcopy.cfg.arduino.proj.delay; ms += mcopy.cfg.arduino.proj.delay;
ms += mcopy.cfg.arduino.serialDelay; ms += mcopy.cfg.arduino.serialDelay;
} }
if (cmd === 'BF' || cmd === 'BB'){ if (c === 'BF' || c === 'BB'){
ms += mcopy.cfg.arduino.black.before; ms += mcopy.cfg.arduino.black.before;
ms += mcopy.cfg.arduino.black.after; ms += mcopy.cfg.arduino.black.after;
ms += mcopy.cfg.arduino.cam.time; ms += mcopy.cfg.arduino.cam.time;
@ -229,16 +229,16 @@ seq.stats = function () {
} }
ms += mcopy.cfg.arduino.sequenceDelay; ms += mcopy.cfg.arduino.sequenceDelay;
if (cmd === 'CF' || cmd === 'BF') { if (c === 'CF' || c === 'BF') {
cam_total++; cam_total++;
} }
if (cmd === 'CB' || cmd === 'BB') { if (c === 'CB' || c === 'BB') {
cam_total--; cam_total--;
} }
if (cmd === 'PF') { if (c === 'PF') {
proj_total++; proj_total++;
} }
if (cmd === 'PB') { if (c === 'PB') {
proj_total--; proj_total--;
} }
} }
@ -271,9 +271,10 @@ seq.clear = function () {
//mcopy.gui.updateState(); //mcopy.gui.updateState();
cmd.proj_forward = function (callback) { cmd.proj_forward = function (callback) {
'use strict';
var res = function (ms) { var res = function (ms) {
//mcopy.gui.updateState(); gui.updateState();
if (callback) { callback(); } if (callback) { callback(ms); }
}; };
if (!mcopy.state.projector.direction) { if (!mcopy.state.projector.direction) {
proj.set(true, function (ms) { proj.set(true, function (ms) {
@ -288,9 +289,10 @@ cmd.proj_forward = function (callback) {
} }
}; };
cmd.proj_backward = function (callback) { cmd.proj_backward = function (callback) {
'use strict';
var res = function (ms) { var res = function (ms) {
//mcopy.gui.updateState(); gui.updateState();
if (callback) { callback(); } if (callback) { callback(ms); }
}; };
if (mcopy.state.projector.direction) { if (mcopy.state.projector.direction) {
proj.set(false, function (ms) { proj.set(false, function (ms) {
@ -304,52 +306,64 @@ cmd.proj_backward = function (callback) {
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
} }
}; };
/* cmd.cam_forward = function (rgb, callback) {
cmd.cam_forward = function (callback) { 'use strict';
var res = function (ms) { var res = function (ms) {
mcopy.state.camera.pos++; gui.updateState();
//gui action light.set([0, 0, 0], function () {
mcopy.gui.updateState(); if (callback) { callback(ms); }
mcopy.log('Camera moved +1 frame to ' + mcopy.state.camera.pos); });
if (callback) { callback(); }
}; };
if (!mcopy.state.camera.direction) { if (!mcopy.state.camera.direction) {
mcopy.log('Advancing camera...'); cam.set(true, function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_forward, function (ms) {
mcopy.state.camera.direction = true;
mcopy.gui.trad.updateDir({value:'cam_forward'});
setTimeout(function () { setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res); light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
}); });
} else { } else {
setTimeout(function () { setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res); light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
} }
}; };
cmd.cam_backward = function (callback) { cmd.black_forward = function (callback) {
'use strict';
var off = [0, 0, 0];
cmd.cam_forward(off, callback);
};
cmd.cam_backward = function (rgb, callback) {
'use strict';
var res = function (ms) { var res = function (ms) {
mcopy.state.camera.pos--; gui.updateState();
//gui action light.set([0, 0, 0], function () {
mcopy.gui.updateState(); if (callback) { callback(ms); }
mcopy.log('Camera moved -1 frame to ' + mcopy.state.camera.pos); });
if (callback) { callback(); }
}; };
if (mcopy.state.camera.direction) { if (mcopy.state.camera.direction) {
mcopy.log('Rewinding camera...'); cam.set(false, function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.cam_backward, function (ms) {
mcopy.state.camera.direction = false;
mcopy.gui.trad.updateDir({value:'cam_backward'});
setTimeout(function () { setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res); light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay); }, mcopy.cfg.arduino.serialDelay);
}); });
} else { } else {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res); setTimeout(function () {
light.set(rgb, function () {
cam.move(res);
});
}, mcopy.cfg.arduino.serialDelay);
} }
}; };
*/ cmd.black_backward = function (callback) {
'use strict';
var off = [0, 0, 0];
cmd.cam_backward(off, callback);
};
proj.queue = {}; proj.queue = {};
proj.lock = false; proj.lock = false;
@ -393,13 +407,13 @@ proj.move = function (callback) {
proj.queue[obj.id] = obj; proj.queue[obj.id] = obj;
proj.lock = true; proj.lock = true;
}; };
proj.end = function (cmd, id) { proj.end = function (c, id, ms) {
'use strict'; 'use strict';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) { if (c === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true; mcopy.state.projector.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) { } else if (c === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false; mcopy.state.projector.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.projector) { } else if (c === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) { if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1; mcopy.state.projector.pos += 1;
} else { } else {
@ -408,7 +422,7 @@ proj.end = function (cmd, id) {
} }
if (typeof proj.queue[id] !== 'undefined') { if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') { if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback(); proj.queue[id].callback(ms);
} }
delete proj.queue[id]; delete proj.queue[id];
proj.lock = false; proj.lock = false;
@ -417,7 +431,7 @@ proj.end = function (cmd, id) {
proj.listen = function () { proj.listen = function () {
'use strict'; 'use strict';
ipcRenderer.on('proj', function (event, arg) { ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id); proj.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true; return event.returnValue = true;
}); });
}; };
@ -464,13 +478,13 @@ cam.move = function (callback) {
cam.queue[obj.id] = obj; cam.queue[obj.id] = obj;
cam.lock = true; cam.lock = true;
}; };
cam.end = function (cmd, id) { cam.end = function (c, id, ms) {
'use strict'; 'use strict';
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) { if (c === mcopy.cfg.arduino.cmd.cam_forward) {
mcopy.state.camera.direction = true; mcopy.state.camera.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) { } else if (c === mcopy.cfg.arduino.cmd.cam_backward) {
mcopy.state.camera.direction = false; mcopy.state.camera.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.camera) { } else if (c === mcopy.cfg.arduino.cmd.camera) {
if (mcopy.state.camera.direction) { if (mcopy.state.camera.direction) {
mcopy.state.camera.pos += 1; mcopy.state.camera.pos += 1;
} else { } else {
@ -479,7 +493,7 @@ cam.end = function (cmd, id) {
} }
if (typeof cam.queue[id] !== 'undefined') { if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') { if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback(); cam.queue[id].callback(ms);
} }
delete cam.queue[id]; delete cam.queue[id];
cam.lock = false; cam.lock = false;
@ -488,7 +502,7 @@ cam.end = function (cmd, id) {
cam.listen = function () { cam.listen = function () {
'use strict'; 'use strict';
ipcRenderer.on('cam', function (event, arg) { ipcRenderer.on('cam', function (event, arg) {
cam.end(arg.cmd, arg.id); cam.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true; return event.returnValue = true;
}); });
}; };
@ -928,14 +942,9 @@ gui.updateProj = function (t) {
gui.updateState = function () { gui.updateState = function () {
var cpos = mcopy.state.camera.pos, var cpos = mcopy.state.camera.pos,
ppos = mcopy.state.projector.pos; ppos = mcopy.state.projector.pos;
$('#trad_cam_count').val(cpos).change();
$('#trad_proj_count').val(ppos).change();
$('#seq_cam_count').val(cpos).change(); $('#seq_cam_count').val(cpos).change();
$('#seq_proj_count').val(ppos).change(); $('#seq_proj_count').val(ppos).change();
$('#goto_cam').val(cpos).change();
$('#goto_proj').val(ppos).change();
}; };
gui.info = function (title, message) { gui.info = function (title, message) {
'use strict'; 'use strict';
@ -1035,12 +1044,12 @@ gui.grid.refresh = function () {
gui.grid.click = function (t) { gui.grid.click = function (t) {
'use strict'; 'use strict';
var i = parseInt($(t).attr('x')), var i = parseInt($(t).attr('x')),
cmd; c;
if ($(t).prop('checked')) { if ($(t).prop('checked')) {
cmd = $(t).attr('class').replace('.', ''); c = $(t).attr('class').replace('.', '');
mcopy.state.sequence.arr[i] = cmd; mcopy.state.sequence.arr[i] = c;
if (cmd === 'CF' if (c === 'CF'
|| cmd === 'CB') { || c === 'CB') {
mcopy.state.sequence.light[i] = light.color.join(','); mcopy.state.sequence.light[i] = light.color.join(',');
} else { } else {
mcopy.state.sequence.light[i] = ''; mcopy.state.sequence.light[i] = '';
@ -1066,7 +1075,6 @@ gui.grid.loopChange = function (t) {
'use strict'; 'use strict';
var count = parseInt(t.value); var count = parseInt(t.value);
mcopy.loop = count; mcopy.loop = count;
console.log('Loop count set to ' + mcopy.loop);
seq.stats(); seq.stats();
}; };
gui.grid.plus_24 = function () { gui.grid.plus_24 = function () {