2019-03-20 19:44:07 +00:00
|
|
|
const seq = {};
|
2019-03-22 08:33:53 +00:00
|
|
|
seq.id = 'sequence';
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.grid = [];
|
|
|
|
seq.gridLoops = 1;
|
2019-03-22 08:33:53 +00:00
|
|
|
seq.arr = [];
|
|
|
|
seq.loops = 1;
|
|
|
|
seq.size = 24;
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.time = 0;
|
|
|
|
seq.running = false;
|
2016-05-16 14:41:11 +00:00
|
|
|
|
|
|
|
/******
|
|
|
|
Sequence Object
|
|
|
|
*******/
|
2019-03-18 22:42:31 +00:00
|
|
|
|
2019-03-24 01:58:22 +00:00
|
|
|
seq.init = function () {
|
|
|
|
seq.listen();
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.listen = function () {
|
|
|
|
ipcRenderer.on(seq.id, seq.listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.listener = function (event, arg) {
|
2019-03-30 00:44:12 +00:00
|
|
|
//console.log(JSON.stringify(arg))
|
2019-03-31 00:29:01 +00:00
|
|
|
if (arg.start) {
|
|
|
|
if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') {
|
|
|
|
seq.activeStep(arg.step);
|
2019-04-04 22:49:07 +00:00
|
|
|
log.info(`Step ${arg.step + 1}/${seq.arr.length}, Loop ${arg.loop + 1}/${seq.loops}`, 'SERIAL', true);
|
2019-03-31 00:29:01 +00:00
|
|
|
} else if (typeof arg.loop !== 'undefined') {
|
|
|
|
$('#loop_current').text(gui.fmtZero(arg.loop + 1, 6));
|
|
|
|
} else {
|
2019-04-04 22:49:07 +00:00
|
|
|
seq.progress(0, 0);
|
2019-03-31 00:29:01 +00:00
|
|
|
}
|
2019-03-24 01:58:22 +00:00
|
|
|
} else if (arg.stop) {
|
2019-03-31 00:29:01 +00:00
|
|
|
if (typeof arg.loop !== 'undefined' && typeof arg.step !== 'undefined') {
|
|
|
|
//console.log(JSON.stringify(arg))
|
2019-04-04 22:49:07 +00:00
|
|
|
seq.progress(arg.step + 1, arg.loop);
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.inactiveAll();
|
|
|
|
} else if (typeof arg.loop !== 'undefined') {
|
|
|
|
$('#loop_current').text('');
|
|
|
|
} else {
|
|
|
|
gui.overlay(false);
|
|
|
|
gui.spinner(false);
|
|
|
|
log.info('Sequence stopped', 'SERIAL', true);
|
|
|
|
}
|
2019-03-24 01:58:22 +00:00
|
|
|
}
|
|
|
|
return event.returnValue = true;
|
|
|
|
}
|
|
|
|
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.progress = function (step, loop) {
|
2019-04-02 14:21:01 +00:00
|
|
|
const elem = $('.progress-bar');
|
2019-03-31 00:29:01 +00:00
|
|
|
const len = seq.arr.length;
|
|
|
|
const total = len * seq.loops;
|
2019-04-02 14:21:01 +00:00
|
|
|
let pos = (loop * len) + step;
|
2019-04-04 22:49:07 +00:00
|
|
|
let progress = 0;
|
2019-03-31 00:29:01 +00:00
|
|
|
|
2019-04-04 22:49:07 +00:00
|
|
|
if (pos > 0 && total > 0) {
|
2019-03-31 00:29:01 +00:00
|
|
|
progress = (pos / total) * 100;
|
|
|
|
}
|
2019-04-04 22:49:07 +00:00
|
|
|
|
|
|
|
//console.log(`${progress}%`)
|
|
|
|
|
2019-03-31 00:29:01 +00:00
|
|
|
elem.attr('aria-valuenow', progress);
|
|
|
|
elem.css('width', `${progress}%`);
|
|
|
|
}
|
|
|
|
|
2019-03-24 01:58:22 +00:00
|
|
|
seq.activeStep = function (x) {
|
|
|
|
seq.inactiveAll();
|
2019-03-30 00:44:12 +00:00
|
|
|
//console.log(`.row input[x=${x + ''}]`)
|
2019-03-24 01:58:22 +00:00
|
|
|
$(`.row input[x=${x + ''}]`).addClass('h');
|
|
|
|
$(`#numbers div[x=${x + ''}]`).addClass('h');
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.inactiveAll = function () {
|
|
|
|
$('.row input').removeClass('h');
|
|
|
|
$('#numbers div').removeClass('h');
|
|
|
|
}
|
|
|
|
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.stop = function (s) {
|
2016-06-21 19:25:29 +00:00
|
|
|
'use strict';
|
2019-03-22 21:06:57 +00:00
|
|
|
ipcRenderer.send(seq.id, { stop : true });
|
|
|
|
$('#loop_current').text('');
|
2016-05-16 14:41:11 +00:00
|
|
|
};
|
2019-03-31 00:29:01 +00:00
|
|
|
//start the sequencer from the grid
|
2019-03-30 00:44:12 +00:00
|
|
|
seq.start = function () {
|
2016-06-21 19:25:29 +00:00
|
|
|
'use strict';
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.time = +new Date();
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.arr = seq.grid;
|
|
|
|
seq.loops = seq.gridLoops;
|
2019-03-22 21:06:57 +00:00
|
|
|
ipcRenderer.send(seq.id, { start : true });
|
2016-05-16 14:41:11 +00:00
|
|
|
};
|
2019-03-22 08:33:53 +00:00
|
|
|
|
2019-03-30 00:44:12 +00:00
|
|
|
//start a pre-set sequence, not using the gui
|
|
|
|
seq.exec = function (arr, loops) {
|
|
|
|
'use strict';
|
|
|
|
seq.time = +new Date();
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.arr = arr;
|
|
|
|
seq.loops = loops;
|
2019-03-30 00:44:12 +00:00
|
|
|
ipcRenderer.send(seq.id, { start : true, arr, loops });
|
|
|
|
};
|
|
|
|
|
2019-03-22 08:33:53 +00:00
|
|
|
seq.set = function (x, cmd) {
|
2019-03-22 21:06:57 +00:00
|
|
|
'use strict';
|
2019-03-22 08:33:53 +00:00
|
|
|
let increase = 0;
|
2019-03-31 00:29:01 +00:00
|
|
|
if (x >= seq.grid.length + 1) {
|
|
|
|
increase = x - seq.grid.length;
|
2019-03-22 08:33:53 +00:00
|
|
|
for (let i = 0; i < increase; i++) {
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.grid.push({});
|
2019-03-22 08:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-31 00:29:01 +00:00
|
|
|
if (!seq.grid[x]) seq.grid[x] = {};
|
|
|
|
seq.grid[x].x = x;
|
|
|
|
seq.grid[x].cmd = cmd;
|
2019-03-22 08:33:53 +00:00
|
|
|
if (cmd.indexOf('C') !== -1) {
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.grid[x].light = light.color;
|
2019-03-22 08:33:53 +00:00
|
|
|
} else {
|
2019-03-31 00:29:01 +00:00
|
|
|
if (seq.grid[x].light) {
|
|
|
|
delete seq.grid[x].light;
|
2019-03-22 08:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//set
|
2019-03-31 00:29:01 +00:00
|
|
|
ipcRenderer.send(seq.id, { set : [ seq.grid[x] ] });
|
2019-03-22 08:33:53 +00:00
|
|
|
//update grid?
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:49:07 +00:00
|
|
|
seq.unsetAll = function () {
|
|
|
|
const len = seq.grid.length;
|
|
|
|
const steps = [];
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
if (typeof seq.grid[i] !== 'undefined') {
|
|
|
|
steps.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipcRenderer.send(seq.id, { unset : steps });
|
|
|
|
seq.grid = [];
|
|
|
|
}
|
|
|
|
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.unset = function (x) {
|
|
|
|
'use strict';
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.grid[x] = undefined
|
2019-03-22 21:06:57 +00:00
|
|
|
ipcRenderer.send(seq.id, { unset : [ x ]});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the light value at a specific step and then update
|
|
|
|
* GUI grid via .state()
|
|
|
|
*
|
|
|
|
* @param {integer} x Step in sequence
|
|
|
|
* @param {array} rgb Light value in RGB
|
|
|
|
**/
|
|
|
|
seq.setLight = function (x, rgb) {
|
|
|
|
'use strict';
|
|
|
|
let color = rgb.join(',');
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.grid[x].light = color;
|
|
|
|
ipcRenderer.send(seq.id, { x, cmd : seq.grid[x].cmd, light : color });
|
2019-03-22 21:06:57 +00:00
|
|
|
};
|
|
|
|
|
2019-03-22 08:33:53 +00:00
|
|
|
/**
|
|
|
|
* Function bound to the change event on the loop counter
|
|
|
|
* input element
|
|
|
|
*
|
|
|
|
* @param {integer} count Integer to set loops to
|
|
|
|
*/
|
|
|
|
seq.setLoops = function (count) {
|
|
|
|
'use strict';
|
2019-03-31 00:29:01 +00:00
|
|
|
seq.gridLoops = count;
|
2019-03-22 08:33:53 +00:00
|
|
|
seq.stats();
|
2019-03-31 00:29:01 +00:00
|
|
|
ipcRenderer.send(seq.id, { loops : seq.gridLoops })
|
2019-03-22 08:33:53 +00:00
|
|
|
};
|
|
|
|
|
2016-05-16 14:41:11 +00:00
|
|
|
seq.stats = function () {
|
2016-06-21 19:25:29 +00:00
|
|
|
'use strict';
|
2019-03-22 08:33:53 +00:00
|
|
|
let ms = 0;
|
|
|
|
let c = '';
|
|
|
|
let cam_total = 0;
|
|
|
|
let proj_total = 0;
|
2019-03-31 00:29:01 +00:00
|
|
|
let real_total = seq.grid.filter(function (elem) {
|
2019-03-22 08:33:53 +00:00
|
|
|
if (elem === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2016-05-16 14:41:11 +00:00
|
|
|
|
|
|
|
//timing
|
2019-03-31 00:29:01 +00:00
|
|
|
for (let step of seq.grid) {
|
2019-03-22 21:06:57 +00:00
|
|
|
c = seq.cmd;
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.camera_forward || c === cfg.cmd.camera_backward){
|
|
|
|
ms += cfg.arduino.cam.time;
|
|
|
|
ms += cfg.arduino.cam.delay;
|
|
|
|
ms += cfg.arduino.serialDelay;
|
2016-05-16 14:41:11 +00:00
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.projector_forward || c === cfg.cmd.projector_backward){
|
|
|
|
ms += cfg.arduino.proj.time;
|
|
|
|
ms += cfg.arduino.proj.delay;
|
|
|
|
ms += cfg.arduino.serialDelay;
|
2016-05-16 14:41:11 +00:00
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.black_forward || c === cfg.cmd.black_backward){
|
|
|
|
ms += cfg.arduino.black.before;
|
|
|
|
ms += cfg.arduino.black.after;
|
|
|
|
ms += cfg.arduino.cam.time;
|
|
|
|
ms += cfg.arduino.cam.delay;
|
|
|
|
ms += cfg.arduino.serialDelay;
|
2016-05-16 14:41:11 +00:00
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
ms += cfg.arduino.sequenceDelay;
|
2016-05-16 14:41:11 +00:00
|
|
|
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.camera_forward || c === cfg.cmd.black_forward) {
|
2016-05-16 14:41:11 +00:00
|
|
|
cam_total++;
|
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.camera_backward || c === cfg.cmd.black_backward) {
|
2016-05-16 14:41:11 +00:00
|
|
|
cam_total--;
|
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.projector_forward) {
|
2016-05-16 14:41:11 +00:00
|
|
|
proj_total++;
|
|
|
|
}
|
2019-03-22 08:33:53 +00:00
|
|
|
if (c === cfg.cmd.projector_backward) {
|
2016-05-16 14:41:11 +00:00
|
|
|
proj_total--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//timing
|
2019-03-31 00:29:01 +00:00
|
|
|
ms = ms * seq.gridLoops;
|
2016-05-16 14:41:11 +00:00
|
|
|
if (ms < 2000) {
|
|
|
|
$('#seq_stats .timing span').text(ms + 'ms');
|
|
|
|
} else {
|
|
|
|
$('#seq_stats .timing span').text(humanizeDuration(ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
//ending frames
|
2019-03-31 00:29:01 +00:00
|
|
|
cam_total = cam_total * seq.gridLoops;
|
|
|
|
proj_total = proj_total * seq.gridLoops;
|
2016-05-16 14:41:11 +00:00
|
|
|
|
2019-03-31 00:29:01 +00:00
|
|
|
$('#seq_stats .cam_end span').text(gui.fmtZero(cam.pos + cam_total, 6));
|
|
|
|
$('#seq_stats .proj_end span').text(gui.fmtZero(proj.pos + proj_total, 6));
|
2016-05-16 14:41:11 +00:00
|
|
|
|
|
|
|
//count
|
2019-03-31 00:29:01 +00:00
|
|
|
$('#seq_stats .seq_count span').text(real_total.length * seq.gridLoops);
|
2016-05-16 14:41:11 +00:00
|
|
|
return ms;
|
|
|
|
};
|
2019-03-22 21:06:57 +00:00
|
|
|
|
2016-05-16 14:41:11 +00:00
|
|
|
seq.clear = function () {
|
2016-06-21 19:25:29 +00:00
|
|
|
'use strict';
|
2019-03-22 08:33:53 +00:00
|
|
|
seq.size = 24;
|
2019-04-04 22:49:07 +00:00
|
|
|
seq.unsetAll();
|
|
|
|
seq.progress(0, 0);
|
2016-05-16 14:41:11 +00:00
|
|
|
};
|
|
|
|
|
2019-03-18 23:42:12 +00:00
|
|
|
seq.cancel = function () {
|
|
|
|
gui.spinner(true, `Cancelling sequence...`);
|
|
|
|
seq.running = false;
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.stop();
|
2019-03-18 23:42:12 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 03:14:48 +00:00
|
|
|
|
2016-05-16 14:41:11 +00:00
|
|
|
module.exports = seq;
|