218 lines
5.3 KiB
JavaScript
218 lines
5.3 KiB
JavaScript
var devices = {};
|
|
|
|
devices.init = function () {
|
|
'use strict';
|
|
devices.listen();
|
|
devices.profiles();
|
|
gui.overlay(true);
|
|
gui.spinner(true, 'Checking for connected devices...');
|
|
};
|
|
devices.profiles = function () {
|
|
'use strict';
|
|
const keys = Object.keys(mcopy.cfg.profiles);
|
|
const elem = $('#profile')
|
|
let opt;
|
|
elem.empty();
|
|
for (let key of keys) {
|
|
opt = $('<option>');
|
|
opt.val(key);
|
|
opt.text(mcopy.cfg.profiles[key].label);
|
|
elem.append(opt);
|
|
}
|
|
elem.on('change', (t) => {
|
|
devices.profile($('#profile').val());
|
|
});
|
|
};
|
|
devices.profile = function (profile) {
|
|
'use strict';
|
|
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
|
|
const p = mcopy.cfg.profiles[profile];
|
|
const keys = Object.keys(p);
|
|
for (let key of keys) {
|
|
mcopy.cfg[key] = keys[key]
|
|
}
|
|
ipcRenderer.send('profile', { profile })
|
|
};
|
|
devices.listen = function () {
|
|
'use strict';
|
|
ipcRenderer.on('ready', devices.ready);
|
|
ipcRenderer.on('intval', devices.intvalCb);
|
|
ipcRenderer.on('digital', devices.digitalCb);
|
|
};
|
|
devices.ready = function (event, arg) {
|
|
'use strict';
|
|
console.dir(arg)
|
|
let opt;
|
|
let devs = [];
|
|
let notify = 'Connected to ';
|
|
gui.spinner(false);
|
|
gui.overlay(false);
|
|
for (let i in arg) {
|
|
devs.push(arg[i].arduino);
|
|
if (arg[i].arduino && arg[i].arduino !== '/dev/fake') {
|
|
if (notify === 'Connected to ') {
|
|
notify += arg[i].arduino + ' '
|
|
} else {
|
|
notify += `& ${arg[i].arduino}`
|
|
}
|
|
}
|
|
opt = $('<option>');
|
|
opt.val(`ARDUINO_${arg[i].arduino}`);
|
|
opt.text(arg[i].arduino);
|
|
$(`#${i}_device`).empty();
|
|
$(`#${i}_device`).append(opt);
|
|
}
|
|
if (notify !== 'Connected to ') {
|
|
gui.notify('DEVICES', notify)
|
|
}
|
|
if (devs.length > 0) {
|
|
$('#devices').empty();
|
|
for (let i of devs) {
|
|
opt = $('<option>');
|
|
opt.val(i);
|
|
opt.text(i);
|
|
$('#devices').append(opt);
|
|
}
|
|
}
|
|
if (arg && arg.profile) {
|
|
$('#profile').val(arg.profile)
|
|
//devices.profile(arg.profile)
|
|
}
|
|
return event.returnValue = true;
|
|
};
|
|
|
|
devices.intval = function () {
|
|
'use strict';
|
|
const url = $('#intval').val();
|
|
let proceed = false;
|
|
let obj = {
|
|
connect: true,
|
|
url : url
|
|
};
|
|
if ( url !== '' && typeof url !== 'undefined') {
|
|
proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`);
|
|
} else {
|
|
alert('Cannot connect to INTVAL3 url as entered.');
|
|
}
|
|
|
|
if (proceed) {
|
|
gui.overlay(true);
|
|
gui.spinner(true, `Connecting to INTVAL3 @ ${url}`);
|
|
ipcRenderer.send('intval', obj);
|
|
} else {
|
|
$('#camera_type_arduino').prop('checked', 'checked');
|
|
$('#intval').removeClass('active');
|
|
}
|
|
};
|
|
|
|
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);
|
|
mcopy.state.camera.pos = state.counter;
|
|
mcopy.state.camera.direction = state.frame.dir;
|
|
$('#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');
|
|
}
|
|
};
|
|
|
|
devices.digitalSelect = function () {
|
|
'use strict';
|
|
const elem = $('#digital');
|
|
const extensions = ['mpg', 'mpeg', 'mov', 'mkv', 'avi'];
|
|
dialog.showOpenDialog({
|
|
title : `Select video or image sequence`,
|
|
properties : [`openFile`], // openDirectory, multiSelection, openFile
|
|
defaultPath: 'c:/',
|
|
filters :
|
|
[
|
|
{
|
|
name: 'Videos',
|
|
extensions
|
|
},
|
|
{
|
|
name: 'All Files',
|
|
extensions: ['*']
|
|
},
|
|
]
|
|
}, (files) => {
|
|
let valid = false;
|
|
console.dir(files)
|
|
let path = files[0]
|
|
if (path && path !== '') {
|
|
for (let ext of extensions) {
|
|
if (path.toLowerCase().indexOf(`.${ext}`) !== -1) {
|
|
valid = true;
|
|
}
|
|
}
|
|
if (!valid) return false;
|
|
log.info(`Selected video ${path.split('/').pop()}`, 'DIGITAL', true);
|
|
elem.attr('data-file', path);
|
|
elem.val(path.split('/').pop());
|
|
}
|
|
})
|
|
}
|
|
|
|
devices.digital = function () {
|
|
'use strict';
|
|
const elem = $('#digital');
|
|
const path = elem.attr('data-file');
|
|
const fileName = elem.val();
|
|
let proceed = false;
|
|
let obj = {
|
|
path,
|
|
fileName
|
|
}
|
|
|
|
if (path && path !== '') {
|
|
proceed = confirm(`Are you sure you want to use ${fileName}?`);
|
|
}
|
|
|
|
if (proceed) {
|
|
gui.overlay(true);
|
|
gui.spinner(true, `Getting info about ${fileName}`);
|
|
ipcRenderer.send('digital', obj)
|
|
} else {
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
$('#digital').removeClass('active');
|
|
}
|
|
};
|
|
|
|
devices.digitalCb = function (evt, args) {
|
|
'use strict';
|
|
let state;
|
|
let color = [255,255,255];
|
|
gui.spinner(false);
|
|
gui.overlay(false);
|
|
if (args.valid && args.valid === true) {
|
|
//success state
|
|
state = JSON.parse(args.state);
|
|
$('#digital').addClass('active');
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
gui.notify('DEVICES', `Using video ${state.fileName}`);
|
|
|
|
mcopy.state.sequence.arr = ['PF', 'CF'];
|
|
gui.grid.setLight(1, color);
|
|
gui.grid.state(0);
|
|
gui.grid.state(1);
|
|
|
|
$('#seq_loop').val(`${state.frames}`).trigger('change');
|
|
|
|
gui.updateState();
|
|
} else {
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
$('#digital').removeClass('active');
|
|
}
|
|
};
|
|
|
|
module.exports = devices; |