Add cam functionality

This commit is contained in:
Matt 2016-04-17 23:02:22 -04:00
parent 24aebc4c31
commit 4d11f1f985
3 changed files with 303 additions and 186 deletions

View File

@ -2464,8 +2464,10 @@ var remote = require('remote'),
mcopy = {},
light = {},
proj = {},
cam = {},
nav = {},
seq = {},
cmd = {},
gui = {},
log = {};
//console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) );
@ -2547,11 +2549,12 @@ log.display = function (action, service, status, time) {
obj.time = moment().format(log.time);
}
w2ui['log'].add(obj);
setTimeout(function () {
$('#grid_log_table').animate({
scrollTop: $('#grid_log_table').prop('scrollHeight')
}, 100);
}, 100);
if (nav.active === 'controls') {
w2ui['log'].scrollIntoView(log.count - 1);
w2ui['log'].selectNone();
w2ui['log'].select(log.count - 1);
}
return obj;
};
log.report = function (obj) {
@ -2720,9 +2723,28 @@ seq.clear = function () {
mcopy.state.sequence.arr = [];
};
//mcopy.gui.updateState();
cmd.proj_forward = function (callback) {
var res = function (ms) {
//mcopy.gui.updateState();
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
proj.set(true, function (ms) {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
}
};
/*
mcopy.cmd = {};
mcopy.cmd.cam_forward = function (callback) {
cmd.cam_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
//gui action
@ -2745,7 +2767,7 @@ mcopy.cmd.cam_forward = function (callback) {
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.cam_backward = function (callback) {
cmd.cam_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
//gui action
@ -2766,30 +2788,8 @@ mcopy.cmd.cam_backward = function (callback) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}
};
mcopy.cmd.proj_forward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos++;
mcopy.gui.updateState();
mcopy.log('Projector moved +1 frame to ' + mcopy.state.projector.pos);
//gui action
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
mcopy.log('Advancing projector...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_forward, function (ms) {
mcopy.state.projector.direction = true;
mcopy.gui.trad.updateDir({value:'proj_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.proj_backward = function (callback) {
cmd.proj_backward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos--;
mcopy.gui.updateState();
@ -2811,52 +2811,7 @@ mcopy.cmd.proj_backward = function (callback) {
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved +1 BLACK 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;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved -1 BLACK 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;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}
};*/
*/
proj.queue = {};
proj.lock = false;
@ -2929,6 +2884,77 @@ proj.listen = function () {
});
};
cam.queue = {};
cam.lock = false;
cam.init = function () {
'use strict';
cam.listen();
};
cam.set = function (dir, callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('cam', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.move = function (callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('cam', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.end = function (cmd, id) {
'use strict';
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {
mcopy.state.camera.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) {
mcopy.state.camera.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.camera) {
if (mcopy.state.camera.direction) {
mcopy.state.camera.pos += 1;
} else {
mcopy.state.camera.pos -= 1;
}
}
if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback();
}
delete cam.queue[id];
cam.lock = false;
}
};
cam.listen = function () {
'use strict';
ipcRenderer.on('cam', function (event, arg) {
cam.end(arg.cmd, arg.id);
return event.returnValue = true;
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
@ -3628,6 +3654,7 @@ gui.grid.events = function () {
};
//NAV GUI
nav.active = 'sequencer';
nav.init = function () {
'use strict';
$('#toolbar').w2toolbar({
@ -3647,10 +3674,14 @@ nav.init = function () {
};
nav.change = function (id) {
'use strict';
nav.active = id;
$('.screen').hide();
$('#' + id).show();
if (id === 'controls') {
w2ui['log'].resize();
w2ui['log'].scrollIntoView(log.count - 1);
w2ui['log'].selectNone();
w2ui['log'].select(log.count - 1);
} else if (id === 'light') {
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
@ -3665,4 +3696,5 @@ var init = function () {
log.init();
light.init();
proj.init();
cam.init();
};

View File

@ -10,7 +10,8 @@ var electron = require('electron'),
winston = require('winston'),
moment = require('moment'),
Q = require('q'),
mcopy = {};
mcopy = {},
arduino;
mcopy.cfg = {};
mcopy.cfgFile = './data/cfg.json';
@ -26,8 +27,6 @@ mcopy.cfgStore = function () {
fs.writeFileSync(mcopy.cfgFile, data, 'utf8');
};
var arduino;
var mainWindow;
var init = function () {
@ -38,6 +37,7 @@ var init = function () {
log.init();
light.init();
proj.init();
cam.init();
arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg);
setTimeout(function () {
@ -258,14 +258,14 @@ proj.set = function (dir, id) {
cmd = mcopy.cfg.arduino.cmd.proj_backward;
}
proj.state.dir = dir;
arduino.send(cmd, function () {
proj.end(cmd, id);
arduino.send(cmd, function (ms) {
proj.end(cmd, id, ms);
});
};
proj.move = function (frame, id) {
'use strict';
arduino.send(mcopy.cfg.arduino.cmd.projector, function () {
proj.end(mcopy.cfg.arduino.cmd.projector, id);
arduino.send(mcopy.cfg.arduino.cmd.projector, function (ms) {
proj.end(mcopy.cfg.arduino.cmd.projector, id, ms);
});
};
proj.listen = function () {
@ -279,7 +279,8 @@ proj.listen = function () {
event.returnValue = true;
});
};
proj.end = function (cmd, id) {
proj.end = function (cmd, id, ms) {
'use strict';
var message = '';
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) {
message = 'Projector set to FORWARD';
@ -295,7 +296,65 @@ proj.end = function (cmd, id) {
message += ' 1 frame';
}
log.info(message, 'PROJ', true, true);
mainWindow.webContents.send('proj', {cmd: cmd, id : id});
mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms});
};
var cam = {};
cam.state = {
dir : true //default dir
};
cam.init = function () {
'use strict';
cam.listen();
};
cam.set = function (dir, id) {
'use strict';
var cmd;
if (dir) {
cmd = mcopy.cfg.arduino.cmd.cam_forward;
} else {
cmd = mcopy.cfg.arduino.cmd.cam_backward;
}
cam.state.dir = dir;
arduino.send(cmd, function (ms) {
cam.end(cmd, id, ms);
});
};
cam.move = function (frame, id) {
'use strict';
arduino.send(mcopy.cfg.arduino.cmd.camera, function (ms) {
cam.end(mcopy.cfg.arduino.cmd.camera, id, ms);
});
};
cam.listen = function () {
'use strict';
ipcMain.on('cam', function (event, arg) {
if (typeof arg.dir !== 'undefined') {
cam.set(arg.dir, arg.id);
} else if (typeof arg.frame !== 'undefined') {
cam.move(arg.frame, arg.id);
}
event.returnValue = true;
});
};
cam.end = function (cmd, id, ms) {
'use strict';
var message = '';
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {
message = 'Camera set to FORWARD';
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) {
message = 'Camera set to BACKWARD';
} else if (cmd === mcopy.cfg.arduino.cmd.camera) {
message = 'Camera ';
if (cam.state.dir) {
message += 'ADVANCED';
} else {
message += 'REWOUND'
}
message += ' 1 frame';
}
log.info(message, 'CAM', true, true);
mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms});
};
var log = {};

View File

@ -8,8 +8,10 @@ var remote = require('remote'),
mcopy = {},
light = {},
proj = {},
cam = {},
nav = {},
seq = {},
cmd = {},
gui = {},
log = {};
//console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) );
@ -91,11 +93,12 @@ log.display = function (action, service, status, time) {
obj.time = moment().format(log.time);
}
w2ui['log'].add(obj);
setTimeout(function () {
$('#grid_log_table').animate({
scrollTop: $('#grid_log_table').prop('scrollHeight')
}, 100);
}, 100);
if (nav.active === 'controls') {
w2ui['log'].scrollIntoView(log.count - 1);
w2ui['log'].selectNone();
w2ui['log'].select(log.count - 1);
}
return obj;
};
log.report = function (obj) {
@ -264,9 +267,45 @@ seq.clear = function () {
mcopy.state.sequence.arr = [];
};
//mcopy.gui.updateState();
cmd.proj_forward = function (callback) {
var res = function (ms) {
//mcopy.gui.updateState();
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
proj.set(true, function (ms) {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
}
};
cmd.proj_backward = function (callback) {
var res = function (ms) {
//mcopy.gui.updateState();
if (callback) { callback(); }
};
if (mcopy.state.projector.direction) {
proj.set(false, function (ms) {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
proj.move(res);
}, mcopy.cfg.arduino.serialDelay);
}
};
/*
mcopy.cmd = {};
mcopy.cmd.cam_forward = function (callback) {
cmd.cam_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
//gui action
@ -289,7 +328,7 @@ mcopy.cmd.cam_forward = function (callback) {
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.cam_backward = function (callback) {
cmd.cam_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
//gui action
@ -310,97 +349,7 @@ mcopy.cmd.cam_backward = function (callback) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.camera, res);
}
};
mcopy.cmd.proj_forward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos++;
mcopy.gui.updateState();
mcopy.log('Projector moved +1 frame to ' + mcopy.state.projector.pos);
//gui action
if (callback) { callback(); }
};
if (!mcopy.state.projector.direction) {
mcopy.log('Advancing projector...');
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_forward, function (ms) {
mcopy.state.projector.direction = true;
mcopy.gui.trad.updateDir({value:'proj_forward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.proj_backward = function (callback) {
var res = function (ms) {
mcopy.state.projector.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Projector moved -1 frame to ' + mcopy.state.projector.pos);
if (callback) { callback(); }
};
if (mcopy.state.projector.direction) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.proj_backward, function (ms) {
mcopy.state.projector.direction = false;
mcopy.gui.trad.updateDir({value:'proj_backward'});
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.projector, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_forward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos++;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved +1 BLACK 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;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
}
};
mcopy.cmd.black_backward = function (callback) {
var res = function (ms) {
mcopy.state.camera.pos--;
mcopy.gui.updateState();
//gui action
mcopy.log('Camera moved -1 BLACK 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;
setTimeout(function () {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}, mcopy.cfg.arduino.serialDelay);
});
} else {
//black
mcopy.arduino.send(mcopy.cfg.arduino.cmd.black, res);
}
};*/
*/
proj.queue = {};
proj.lock = false;
@ -473,6 +422,77 @@ proj.listen = function () {
});
};
cam.queue = {};
cam.lock = false;
cam.init = function () {
'use strict';
cam.listen();
};
cam.set = function (dir, callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('cam', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.move = function (callback) {
'use strict';
var obj;
if (cam.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('cam', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
cam.queue[obj.id] = obj;
cam.lock = true;
};
cam.end = function (cmd, id) {
'use strict';
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {
mcopy.state.camera.direction = true;
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) {
mcopy.state.camera.direction = false;
} else if (cmd === mcopy.cfg.arduino.cmd.camera) {
if (mcopy.state.camera.direction) {
mcopy.state.camera.pos += 1;
} else {
mcopy.state.camera.pos -= 1;
}
}
if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback();
}
delete cam.queue[id];
cam.lock = false;
}
};
cam.listen = function () {
'use strict';
ipcRenderer.on('cam', function (event, arg) {
cam.end(arg.cmd, arg.id);
return event.returnValue = true;
});
};
//LIGHT
light.preview_state = false; //light is on/off for preview viewing
light.color = [255, 255, 255]; //default color
@ -1172,6 +1192,7 @@ gui.grid.events = function () {
};
//NAV GUI
nav.active = 'sequencer';
nav.init = function () {
'use strict';
$('#toolbar').w2toolbar({
@ -1191,10 +1212,14 @@ nav.init = function () {
};
nav.change = function (id) {
'use strict';
nav.active = id;
$('.screen').hide();
$('#' + id).show();
if (id === 'controls') {
w2ui['log'].resize();
w2ui['log'].scrollIntoView(log.count - 1);
w2ui['log'].selectNone();
w2ui['log'].select(log.count - 1);
} else if (id === 'light') {
if (w2ui['colors'].active === 'rgb') {
light.rgb.set(light.color);
@ -1209,4 +1234,5 @@ var init = function () {
log.init();
light.init();
proj.init();
cam.init();
};