2019-03-21 19:43:03 +00:00
|
|
|
const devices = {};
|
2016-06-19 00:15:41 +00:00
|
|
|
|
|
|
|
devices.init = function () {
|
|
|
|
'use strict';
|
2019-02-22 18:33:48 +00:00
|
|
|
devices.listen();
|
2018-02-01 19:52:47 +00:00
|
|
|
devices.profiles();
|
2016-06-19 00:15:41 +00:00
|
|
|
gui.overlay(true);
|
2018-02-01 02:46:37 +00:00
|
|
|
gui.spinner(true, 'Checking for connected devices...');
|
2016-06-19 00:15:41 +00:00
|
|
|
};
|
2018-02-01 19:52:47 +00:00
|
|
|
devices.profiles = function () {
|
2019-02-22 18:33:48 +00:00
|
|
|
'use strict';
|
2019-03-22 08:33:53 +00:00
|
|
|
const keys = Object.keys(cfg.profiles);
|
2018-02-01 19:52:47 +00:00
|
|
|
const elem = $('#profile')
|
|
|
|
let opt;
|
|
|
|
elem.empty();
|
|
|
|
for (let key of keys) {
|
|
|
|
opt = $('<option>');
|
|
|
|
opt.val(key);
|
2019-03-22 08:33:53 +00:00
|
|
|
opt.text(cfg.profiles[key].label);
|
2018-02-01 19:52:47 +00:00
|
|
|
elem.append(opt);
|
|
|
|
}
|
|
|
|
elem.on('change', (t) => {
|
|
|
|
devices.profile($('#profile').val());
|
2019-02-22 18:33:48 +00:00
|
|
|
});
|
2018-02-01 19:52:47 +00:00
|
|
|
};
|
|
|
|
devices.profile = function (profile) {
|
2019-02-22 18:33:48 +00:00
|
|
|
'use strict';
|
2018-02-01 19:52:47 +00:00
|
|
|
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
|
2019-03-22 08:33:53 +00:00
|
|
|
const p = cfg.profiles[profile];
|
2018-02-01 19:52:47 +00:00
|
|
|
const keys = Object.keys(p);
|
|
|
|
for (let key of keys) {
|
2019-03-22 08:33:53 +00:00
|
|
|
cfg[key] = keys[key]
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2019-03-13 19:28:07 +00:00
|
|
|
if (typeof p.light !== 'undefined' && p.light === false) {
|
|
|
|
light.disable();
|
|
|
|
} else {
|
|
|
|
light.enable();
|
|
|
|
}
|
2018-02-07 18:44:24 +00:00
|
|
|
ipcRenderer.send('profile', { profile })
|
2018-02-01 19:52:47 +00:00
|
|
|
};
|
2016-06-19 00:15:41 +00:00
|
|
|
devices.listen = function () {
|
|
|
|
'use strict';
|
2018-01-09 18:01:19 +00:00
|
|
|
ipcRenderer.on('ready', devices.ready);
|
2018-01-31 15:42:11 +00:00
|
|
|
ipcRenderer.on('intval', devices.intvalCb);
|
2019-06-18 19:47:17 +00:00
|
|
|
ipcRenderer.on('filmout', devices.digitalCb);
|
2016-06-19 00:15:41 +00:00
|
|
|
};
|
2018-01-09 18:01:19 +00:00
|
|
|
devices.ready = function (event, arg) {
|
2016-06-19 00:15:41 +00:00
|
|
|
'use strict';
|
2019-05-28 21:41:39 +00:00
|
|
|
//console.dir(arg)
|
2018-01-09 18:01:19 +00:00
|
|
|
let opt;
|
2018-01-31 15:42:11 +00:00
|
|
|
let devs = [];
|
2018-02-01 19:52:47 +00:00
|
|
|
let notify = 'Connected to ';
|
2019-03-13 19:28:07 +00:00
|
|
|
let p;
|
2016-06-19 00:15:41 +00:00
|
|
|
gui.spinner(false);
|
|
|
|
gui.overlay(false);
|
2018-01-09 18:01:19 +00:00
|
|
|
for (let i in arg) {
|
2018-02-01 19:52:47 +00:00
|
|
|
devs.push(arg[i].arduino);
|
|
|
|
if (arg[i].arduino && arg[i].arduino !== '/dev/fake') {
|
2018-02-01 02:46:37 +00:00
|
|
|
if (notify === 'Connected to ') {
|
2018-02-01 19:52:47 +00:00
|
|
|
notify += arg[i].arduino + ' '
|
2018-02-01 02:46:37 +00:00
|
|
|
} else {
|
2018-02-01 19:52:47 +00:00
|
|
|
notify += `& ${arg[i].arduino}`
|
2018-02-01 02:46:37 +00:00
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
}
|
2018-01-09 18:01:19 +00:00
|
|
|
opt = $('<option>');
|
2018-02-01 19:52:47 +00:00
|
|
|
opt.val(`ARDUINO_${arg[i].arduino}`);
|
|
|
|
opt.text(arg[i].arduino);
|
2018-01-09 18:01:19 +00:00
|
|
|
$(`#${i}_device`).empty();
|
|
|
|
$(`#${i}_device`).append(opt);
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
|
|
|
if (notify !== 'Connected to ') {
|
2019-02-27 02:58:26 +00:00
|
|
|
gui.notify('DEVICES', notify);
|
2019-05-28 21:41:39 +00:00
|
|
|
} else {
|
|
|
|
gui.notify('DEVICES', 'Connected to mock devices')
|
2018-01-09 18:01:19 +00:00
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
if (devs.length > 0) {
|
|
|
|
$('#devices').empty();
|
|
|
|
for (let i of devs) {
|
|
|
|
opt = $('<option>');
|
|
|
|
opt.val(i);
|
|
|
|
opt.text(i);
|
|
|
|
$('#devices').append(opt);
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 18:44:24 +00:00
|
|
|
if (arg && arg.profile) {
|
|
|
|
$('#profile').val(arg.profile)
|
2019-03-09 03:32:43 +00:00
|
|
|
log.info(`Using configuration profile "${arg.profile}"`, 'DEVICES', true, true);
|
2019-03-22 08:33:53 +00:00
|
|
|
p = cfg.profiles[arg.profile];
|
2019-03-13 19:28:07 +00:00
|
|
|
if (typeof p.light !== 'undefined' && p.light === false) {
|
|
|
|
light.disable();
|
|
|
|
} else {
|
|
|
|
light.enable();
|
|
|
|
}
|
2018-02-07 18:44:24 +00:00
|
|
|
//devices.profile(arg.profile)
|
2019-02-26 21:43:38 +00:00
|
|
|
}
|
2019-03-24 01:58:22 +00:00
|
|
|
|
|
|
|
seq.set(0, cfg.cmd.camera_forward);
|
|
|
|
seq.set(1, cfg.cmd.projector_forward);
|
|
|
|
grid.state(0);
|
|
|
|
grid.state(1);
|
2019-05-28 17:41:25 +00:00
|
|
|
seq.stats();
|
2019-03-24 01:58:22 +00:00
|
|
|
|
2019-02-26 21:43:38 +00:00
|
|
|
if (arg.projector_second) {
|
2019-02-27 02:58:26 +00:00
|
|
|
//add second row of projector pads to grid
|
2019-04-16 14:01:42 +00:00
|
|
|
proj.second.enable();
|
2019-02-27 02:58:26 +00:00
|
|
|
}
|
|
|
|
if (arg.camera_second) {
|
|
|
|
//add second row of camera pads to grid
|
2019-04-16 14:01:42 +00:00
|
|
|
cam.second.enable();
|
2018-02-07 18:44:24 +00:00
|
|
|
}
|
2018-01-09 18:01:19 +00:00
|
|
|
return event.returnValue = true;
|
2016-06-19 00:15:41 +00:00
|
|
|
};
|
|
|
|
|
2018-01-31 15:42:11 +00:00
|
|
|
devices.intval = function () {
|
|
|
|
'use strict';
|
2019-02-08 19:28:57 +00:00
|
|
|
const url = $('#intval').val();
|
|
|
|
let proceed = false;
|
2018-01-31 15:42:11 +00:00
|
|
|
let obj = {
|
|
|
|
connect: true,
|
|
|
|
url : url
|
2019-02-08 19:28:57 +00:00
|
|
|
};
|
2018-01-31 15:42:11 +00:00
|
|
|
if ( url !== '' && typeof url !== 'undefined') {
|
2019-02-08 19:28:57 +00:00
|
|
|
proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`);
|
2018-01-31 15:42:11 +00:00
|
|
|
} else {
|
2019-02-08 19:28:57 +00:00
|
|
|
alert('Cannot connect to INTVAL3 url as entered.');
|
2018-01-31 15:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proceed) {
|
|
|
|
gui.overlay(true);
|
2018-02-01 02:46:37 +00:00
|
|
|
gui.spinner(true, `Connecting to INTVAL3 @ ${url}`);
|
2019-02-08 19:28:57 +00:00
|
|
|
ipcRenderer.send('intval', obj);
|
|
|
|
} else {
|
|
|
|
$('#camera_type_arduino').prop('checked', 'checked');
|
|
|
|
$('#intval').removeClass('active');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-08 23:21:16 +00:00
|
|
|
devices.intvalCb = function (evt, args) {
|
|
|
|
'use strict';
|
|
|
|
let state;
|
|
|
|
gui.spinner(false);
|
|
|
|
gui.overlay(false);
|
|
|
|
if (args.connected && args.connected === true) {
|
|
|
|
//success state
|
|
|
|
state = JSON.parse(args.state);
|
2019-03-31 00:29:01 +00:00
|
|
|
cam.pos = state.counter;
|
|
|
|
cam.dir = state.frame.dir;
|
2019-02-08 23:21:16 +00:00
|
|
|
$('#intval').val(args.url);
|
|
|
|
$('#intval').addClass('active');
|
|
|
|
$('#camera_type_intval').prop('checked', 'checked');
|
|
|
|
gui.notify('DEVICES', `Connected to INTVAL3 @ ${args.url}`)
|
|
|
|
gui.updateState()
|
|
|
|
} else {
|
|
|
|
$('#camera_type_arduino').prop('checked', 'checked');
|
|
|
|
$('#intval').removeClass('active');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-08 19:28:57 +00:00
|
|
|
devices.digitalSelect = function () {
|
2019-02-08 23:21:16 +00:00
|
|
|
'use strict';
|
2019-02-08 19:28:57 +00:00
|
|
|
const elem = $('#digital');
|
2019-02-28 22:50:13 +00:00
|
|
|
const extensions = ['mpg', 'mpeg', 'mov', 'mkv', 'avi', 'mp4'];
|
2019-02-08 23:21:16 +00:00
|
|
|
dialog.showOpenDialog({
|
|
|
|
title : `Select video or image sequence`,
|
|
|
|
properties : [`openFile`], // openDirectory, multiSelection, openFile
|
|
|
|
defaultPath: 'c:/',
|
2019-02-27 02:58:26 +00:00
|
|
|
filters : [
|
|
|
|
{
|
|
|
|
name: 'All Files',
|
|
|
|
extensions: ['*']
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}, (files) => {
|
|
|
|
let valid = false;
|
|
|
|
console.dir(files)
|
|
|
|
let path = files[0];
|
|
|
|
let displayName;
|
|
|
|
if (path && path !== '') {
|
|
|
|
for (let ext of extensions) {
|
|
|
|
if (path.toLowerCase().indexOf(`.${ext}`) !== -1) {
|
|
|
|
valid = true;
|
2019-02-08 23:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-27 02:58:26 +00:00
|
|
|
if (!valid) return false;
|
|
|
|
log.info(`Selected video ${path.split('/').pop()}`, 'DIGITAL', true);
|
|
|
|
elem.attr('data-file', path);
|
|
|
|
displayName = path.split('/').pop()
|
|
|
|
elem.val(displayName);
|
|
|
|
$('#video_file').val(displayName);
|
|
|
|
}
|
|
|
|
})
|
2019-02-08 19:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
devices.digital = function () {
|
|
|
|
'use strict';
|
|
|
|
const elem = $('#digital');
|
2019-02-08 23:21:16 +00:00
|
|
|
const path = elem.attr('data-file');
|
|
|
|
const fileName = elem.val();
|
2019-02-08 19:28:57 +00:00
|
|
|
let proceed = false;
|
|
|
|
let obj = {
|
2019-02-08 23:21:16 +00:00
|
|
|
path,
|
|
|
|
fileName
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path && path !== '') {
|
|
|
|
proceed = confirm(`Are you sure you want to use ${fileName}?`);
|
2019-02-08 19:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proceed) {
|
2019-02-08 23:21:16 +00:00
|
|
|
gui.overlay(true);
|
|
|
|
gui.spinner(true, `Getting info about ${fileName}`);
|
2019-06-18 19:47:17 +00:00
|
|
|
ipcRenderer.send('filmout', obj)
|
2018-01-31 15:42:11 +00:00
|
|
|
} else {
|
2019-02-08 23:21:16 +00:00
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
|
|
$('#digital').removeClass('active');
|
2018-01-31 15:42:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-08 23:21:16 +00:00
|
|
|
devices.digitalCb = function (evt, args) {
|
2018-01-31 15:42:11 +00:00
|
|
|
'use strict';
|
2018-02-01 19:52:47 +00:00
|
|
|
let state;
|
2019-02-11 06:08:20 +00:00
|
|
|
let color = [255,255,255];
|
2018-02-01 02:46:37 +00:00
|
|
|
gui.spinner(false);
|
|
|
|
gui.overlay(false);
|
2019-02-08 23:21:16 +00:00
|
|
|
if (args.valid && args.valid === true) {
|
2018-02-01 02:46:37 +00:00
|
|
|
//success state
|
2018-02-01 19:52:47 +00:00
|
|
|
state = JSON.parse(args.state);
|
2019-02-08 23:21:16 +00:00
|
|
|
$('#digital').addClass('active');
|
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
|
|
gui.notify('DEVICES', `Using video ${state.fileName}`);
|
|
|
|
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.set(0, 'PF');
|
2019-03-22 01:02:28 +00:00
|
|
|
grid.state(0);
|
2019-03-24 01:58:22 +00:00
|
|
|
|
2019-03-22 21:06:57 +00:00
|
|
|
seq.set(1, 'CF');
|
|
|
|
seq.setLight(1, color);
|
2019-03-22 01:02:28 +00:00
|
|
|
grid.state(1);
|
2019-02-08 23:21:16 +00:00
|
|
|
|
2019-03-18 22:35:49 +00:00
|
|
|
if (light.disabled) {
|
|
|
|
light.enable();
|
|
|
|
}
|
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
$('#seq_loop').val(`${state.frames - 1}`).trigger('change');
|
2019-02-11 06:08:20 +00:00
|
|
|
|
2019-02-08 23:21:16 +00:00
|
|
|
gui.updateState();
|
2018-02-01 02:46:37 +00:00
|
|
|
} else {
|
2019-02-08 23:21:16 +00:00
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
|
|
$('#digital').removeClass('active');
|
2018-02-01 02:46:37 +00:00
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
};
|
|
|
|
|
2016-06-19 00:15:41 +00:00
|
|
|
module.exports = devices;
|