Add devices module after refactor

This commit is contained in:
mmcwilliams 2019-06-24 14:31:26 -04:00
parent 9331a766df
commit ad67e2f010
3 changed files with 482 additions and 482 deletions

View File

@ -1,51 +1,22 @@
const devices = {};
devices.init = function () {
'use strict'; 'use strict';
devices.listen(); let devices;
devices.profiles(); class Devices {
constructor() {
this.id = 'devices';
this.init();
}
init() {
this.listen();
this.profiles();
gui.overlay(true); gui.overlay(true);
gui.spinner(true, 'Checking for connected devices...'); gui.spinner(true, 'Checking for connected devices...');
};
devices.profiles = function () {
'use strict';
const keys = Object.keys(cfg.profiles);
const elem = $('#profile')
let opt;
elem.empty();
for (let key of keys) {
opt = $('<option>');
opt.val(key);
opt.text(cfg.profiles[key].label);
elem.append(opt);
} }
elem.on('change', (t) => { listen() {
devices.profile($('#profile').val()); ipcRenderer.on('ready', this.ready.bind(this));
}); ipcRenderer.on('intval', this.intvalCb.bind(this));
}; ipcRenderer.on('digital', this.digitalCb.bind(this));
devices.profile = function (profile) {
'use strict';
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
const p = cfg.profiles[profile];
const keys = Object.keys(p);
for (let key of keys) {
cfg[key] = keys[key]
} }
if (typeof p.light !== 'undefined' && p.light === false) { ready(event, arg) {
light.disable();
} else {
light.enable();
}
ipcRenderer.send('profile', { profile })
};
devices.listen = function () {
'use strict';
ipcRenderer.on('ready', devices.ready);
ipcRenderer.on('intval', devices.intvalCb);
ipcRenderer.on('filmout', devices.digitalCb);
};
devices.ready = function (event, arg) {
'use strict';
//console.dir(arg) //console.dir(arg)
let opt; let opt;
let devs = []; let devs = [];
@ -57,9 +28,10 @@ devices.ready = function (event, arg) {
devs.push(arg[i].arduino); devs.push(arg[i].arduino);
if (arg[i].arduino && arg[i].arduino !== '/dev/fake') { if (arg[i].arduino && arg[i].arduino !== '/dev/fake') {
if (notify === 'Connected to ') { if (notify === 'Connected to ') {
notify += arg[i].arduino + ' ' notify += arg[i].arduino + ' ';
} else { }
notify += `& ${arg[i].arduino}` else {
notify += `& ${arg[i].arduino}`;
} }
} }
opt = $('<option>'); opt = $('<option>');
@ -70,8 +42,9 @@ devices.ready = function (event, arg) {
} }
if (notify !== 'Connected to ') { if (notify !== 'Connected to ') {
gui.notify('DEVICES', notify); gui.notify('DEVICES', notify);
} else { }
gui.notify('DEVICES', 'Connected to mock devices') else {
gui.notify('DEVICES', 'Connected to mock devices');
} }
if (devs.length > 0) { if (devs.length > 0) {
$('#devices').empty(); $('#devices').empty();
@ -83,23 +56,22 @@ devices.ready = function (event, arg) {
} }
} }
if (arg && arg.profile) { if (arg && arg.profile) {
$('#profile').val(arg.profile) $('#profile').val(arg.profile);
log.info(`Using configuration profile "${arg.profile}"`, 'DEVICES', true, true); log.info(`Using configuration profile "${arg.profile}"`, 'DEVICES', true, true);
p = cfg.profiles[arg.profile]; p = cfg.profiles[arg.profile];
if (typeof p.light !== 'undefined' && p.light === false) { if (typeof p.light !== 'undefined' && p.light === false) {
light.disable(); light.disable();
} else { }
else {
light.enable(); light.enable();
} }
//devices.profile(arg.profile) //devices.profile(arg.profile)
} }
seq.set(0, cfg.cmd.camera_forward); seq.set(0, cfg.cmd.camera_forward);
seq.set(1, cfg.cmd.projector_forward); seq.set(1, cfg.cmd.projector_forward);
grid.state(0); grid.state(0);
grid.state(1); grid.state(1);
seq.stats(); seq.stats();
if (arg.projector_second) { if (arg.projector_second) {
//add second row of projector pads to grid //add second row of projector pads to grid
proj.second.enable(); proj.second.enable();
@ -109,10 +81,39 @@ devices.ready = function (event, arg) {
cam.second.enable(); cam.second.enable();
} }
return event.returnValue = true; return event.returnValue = true;
}; }
profiles() {
devices.intval = function () { const keys = Object.keys(cfg.profiles);
'use strict'; const elem = $('#profile');
let opt;
elem.empty();
for (let key of keys) {
opt = $('<option>');
opt.val(key);
opt.text(cfg.profiles[key].label);
elem.append(opt);
}
elem.on('change', (t) => {
const val = $('#profile').val();
this.profile(val);
});
}
profile(profile) {
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
const p = cfg.profiles[profile];
const keys = Object.keys(p);
for (let key of keys) {
cfg[key] = keys[key];
}
if (typeof p.light !== 'undefined' && p.light === false) {
light.disable();
}
else {
light.enable();
}
ipcRenderer.send('profile', { profile });
}
intval() {
const url = $('#intval').val(); const url = $('#intval').val();
let proceed = false; let proceed = false;
let obj = { let obj = {
@ -121,22 +122,21 @@ devices.intval = function () {
}; };
if (url !== '' && typeof url !== 'undefined') { if (url !== '' && typeof url !== 'undefined') {
proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`); proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`);
} else { }
else {
alert('Cannot connect to INTVAL3 url as entered.'); alert('Cannot connect to INTVAL3 url as entered.');
} }
if (proceed) { if (proceed) {
gui.overlay(true); gui.overlay(true);
gui.spinner(true, `Connecting to INTVAL3 @ ${url}`); gui.spinner(true, `Connecting to INTVAL3 @ ${url}`);
ipcRenderer.send('intval', obj); ipcRenderer.send('intval', obj);
} else { }
else {
$('#camera_type_arduino').prop('checked', 'checked'); $('#camera_type_arduino').prop('checked', 'checked');
$('#intval').removeClass('active'); $('#intval').removeClass('active');
} }
}; }
intvalCb(evt, args) {
devices.intvalCb = function (evt, args) {
'use strict';
let state; let state;
gui.spinner(false); gui.spinner(false);
gui.overlay(false); gui.overlay(false);
@ -148,21 +148,20 @@ devices.intvalCb = function (evt, args) {
$('#intval').val(args.url); $('#intval').val(args.url);
$('#intval').addClass('active'); $('#intval').addClass('active');
$('#camera_type_intval').prop('checked', 'checked'); $('#camera_type_intval').prop('checked', 'checked');
gui.notify('DEVICES', `Connected to INTVAL3 @ ${args.url}`) gui.notify('DEVICES', `Connected to INTVAL3 @ ${args.url}`);
gui.updateState() gui.updateState();
} else { }
else {
$('#camera_type_arduino').prop('checked', 'checked'); $('#camera_type_arduino').prop('checked', 'checked');
$('#intval').removeClass('active'); $('#intval').removeClass('active');
} }
}; }
digitalSelect() {
devices.digitalSelect = function () {
'use strict';
const elem = $('#digital'); const elem = $('#digital');
const extensions = ['mpg', 'mpeg', 'mov', 'mkv', 'avi', 'mp4']; const extensions = ['mpg', 'mpeg', 'mov', 'mkv', 'avi', 'mp4'];
dialog.showOpenDialog({ dialog.showOpenDialog({
title: `Select video or image sequence`, title: `Select video or image sequence`,
properties : [`openFile`], // openDirectory, multiSelection, openFile properties: [`openFile`],
defaultPath: 'c:/', defaultPath: 'c:/',
filters: [ filters: [
{ {
@ -172,7 +171,6 @@ devices.digitalSelect = function () {
] ]
}, (files) => { }, (files) => {
let valid = false; let valid = false;
console.dir(files)
let path = files[0]; let path = files[0];
let displayName; let displayName;
if (path && path !== '') { if (path && path !== '') {
@ -181,18 +179,17 @@ devices.digitalSelect = function () {
valid = true; valid = true;
} }
} }
if (!valid) return false; if (!valid)
return false;
log.info(`Selected video ${path.split('/').pop()}`, 'DIGITAL', true); log.info(`Selected video ${path.split('/').pop()}`, 'DIGITAL', true);
elem.attr('data-file', path); elem.attr('data-file', path);
displayName = path.split('/').pop() displayName = path.split('/').pop();
elem.val(displayName); elem.val(displayName);
$('#video_file').val(displayName); $('#video_file').val(displayName);
} }
}) });
} }
digital() {
devices.digital = function () {
'use strict';
const elem = $('#digital'); const elem = $('#digital');
const path = elem.attr('data-file'); const path = elem.attr('data-file');
const fileName = elem.val(); const fileName = elem.val();
@ -200,24 +197,21 @@ devices.digital = function () {
let obj = { let obj = {
path, path,
fileName fileName
} };
if (path && path !== '') { if (path && path !== '') {
proceed = confirm(`Are you sure you want to use ${fileName}?`); proceed = confirm(`Are you sure you want to use ${fileName}?`);
} }
if (proceed) { if (proceed) {
gui.overlay(true); gui.overlay(true);
gui.spinner(true, `Getting info about ${fileName}`); gui.spinner(true, `Getting info about ${fileName}`);
ipcRenderer.send('filmout', obj) ipcRenderer.send('digital', obj);
} else { }
else {
$('#projector_type_digital').prop('checked', 'checked'); $('#projector_type_digital').prop('checked', 'checked');
$('#digital').removeClass('active'); $('#digital').removeClass('active');
} }
}; }
digitalCb(evt, args) {
devices.digitalCb = function (evt, args) {
'use strict';
let state; let state;
let color = [255, 255, 255]; let color = [255, 255, 255];
gui.spinner(false); gui.spinner(false);
@ -228,25 +222,22 @@ devices.digitalCb = function (evt, args) {
$('#digital').addClass('active'); $('#digital').addClass('active');
$('#projector_type_digital').prop('checked', 'checked'); $('#projector_type_digital').prop('checked', 'checked');
gui.notify('DEVICES', `Using video ${state.fileName}`); gui.notify('DEVICES', `Using video ${state.fileName}`);
seq.set(0, 'PF'); seq.set(0, 'PF');
grid.state(0); grid.state(0);
seq.set(1, 'CF'); seq.set(1, 'CF');
seq.setLight(1, color); seq.setLight(1, color);
grid.state(1); grid.state(1);
if (light.disabled) { if (light.disabled) {
light.enable(); light.enable();
} }
$('#seq_loop').val(`${state.frames - 1}`).trigger('change'); $('#seq_loop').val(`${state.frames - 1}`).trigger('change');
gui.updateState(); gui.updateState();
} else { }
else {
$('#projector_type_digital').prop('checked', 'checked'); $('#projector_type_digital').prop('checked', 'checked');
$('#digital').removeClass('active'); $('#digital').removeClass('active');
} }
}; }
}
devices = new Devices();
module.exports = devices; module.exports = devices;

View File

@ -3,3 +3,4 @@
./node_modules/.bin/tsc ./src/lib/ui/grid.ts --outFile ./lib/ui/grid.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016 ./node_modules/.bin/tsc ./src/lib/ui/grid.ts --outFile ./lib/ui/grid.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016
./node_modules/.bin/tsc ./src/lib/ui/seq.ts --outFile ./lib/ui/seq.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016 ./node_modules/.bin/tsc ./src/lib/ui/seq.ts --outFile ./lib/ui/seq.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016
./node_modules/.bin/tsc ./src/lib/ui/filmout.ts --outFile ./lib/ui/filmout.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016 ./node_modules/.bin/tsc ./src/lib/ui/filmout.ts --outFile ./lib/ui/filmout.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016
./node_modules/.bin/tsc ./src/lib/ui/devices.ts --outFile ./lib/ui/devices.js --noImplicitAny --lib ES2017 --lib ES2016 --lib dom -t ES2016

View File

@ -10,62 +10,40 @@ declare var log : any;
declare var w2popup : any; declare var w2popup : any;
declare var cam : any; declare var cam : any;
declare var proj : any; declare var proj : any;
declare var light : any;
declare var grid : any;
declare var ipcRenderer : any;
declare var dialog : any;
const devices = {}; let devices : Devices;
devices.init = function () { class Devices {
'use strict'; private id : string = 'devices';
devices.listen(); constructor () {
devices.profiles(); this.init();
}
init () {
this.listen();
this.profiles();
gui.overlay(true); gui.overlay(true);
gui.spinner(true, 'Checking for connected devices...'); gui.spinner(true, 'Checking for connected devices...');
};
devices.profiles = function () {
'use strict';
const keys = Object.keys(cfg.profiles);
const elem = $('#profile')
let opt;
elem.empty();
for (let key of keys) {
opt = $('<option>');
opt.val(key);
opt.text(cfg.profiles[key].label);
elem.append(opt);
} }
elem.on('change', (t) => { listen () {
devices.profile($('#profile').val()); ipcRenderer.on('ready', this.ready.bind(this));
}); ipcRenderer.on('intval', this.intvalCb.bind(this));
}; ipcRenderer.on('digital', this.digitalCb.bind(this));
devices.profile = function (profile) {
'use strict';
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
const p = cfg.profiles[profile];
const keys = Object.keys(p);
for (let key of keys) {
cfg[key] = keys[key]
} }
if (typeof p.light !== 'undefined' && p.light === false) {
light.disable(); ready (event : any, arg : any) {
} else {
light.enable();
}
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) //console.dir(arg)
let opt; let opt : any;
let devs = []; let devs : any[] = [];
let notify = 'Connected to '; let notify : string = 'Connected to ';
let p; let p : any;
gui.spinner(false); gui.spinner(false);
gui.overlay(false); gui.overlay(false);
for (let i in arg) { for (let i in arg) {
devs.push(arg[i].arduino); devs.push(arg[i].arduino);
if (arg[i].arduino && arg[i].arduino !== '/dev/fake') { if (arg[i].arduino && arg[i].arduino !== '/dev/fake') {
@ -81,11 +59,13 @@ devices.ready = function (event, arg) {
$(`#${i}_device`).empty(); $(`#${i}_device`).empty();
$(`#${i}_device`).append(opt); $(`#${i}_device`).append(opt);
} }
if (notify !== 'Connected to ') { if (notify !== 'Connected to ') {
gui.notify('DEVICES', notify); gui.notify('DEVICES', notify);
} else { } else {
gui.notify('DEVICES', 'Connected to mock devices') gui.notify('DEVICES', 'Connected to mock devices')
} }
if (devs.length > 0) { if (devs.length > 0) {
$('#devices').empty(); $('#devices').empty();
for (let i of devs) { for (let i of devs) {
@ -95,6 +75,7 @@ devices.ready = function (event, arg) {
$('#devices').append(opt); $('#devices').append(opt);
} }
} }
if (arg && arg.profile) { if (arg && arg.profile) {
$('#profile').val(arg.profile) $('#profile').val(arg.profile)
log.info(`Using configuration profile "${arg.profile}"`, 'DEVICES', true, true); log.info(`Using configuration profile "${arg.profile}"`, 'DEVICES', true, true);
@ -122,16 +103,48 @@ devices.ready = function (event, arg) {
cam.second.enable(); cam.second.enable();
} }
return event.returnValue = true; return event.returnValue = true;
}; }
devices.intval = function () { profiles () {
'use strict'; const keys : string[] = Object.keys(cfg.profiles);
const url = $('#intval').val(); const elem : any = $('#profile')
let proceed = false; let opt;
let obj = { elem.empty();
for (let key of keys) {
opt = $('<option>');
opt.val(key);
opt.text(cfg.profiles[key].label);
elem.append(opt);
}
elem.on('change', (t : any) => {
const val : string = $('#profile').val() as string;
this.profile(val);
});
}
profile (profile : string) {
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
const p : any = cfg.profiles[profile];
const keys : any[] = Object.keys(p);
for (let key of keys) {
cfg[key] = keys[key]
}
if (typeof p.light !== 'undefined' && p.light === false) {
light.disable();
} else {
light.enable();
}
ipcRenderer.send('profile', { profile })
}
intval () {
const url : string = $('#intval').val() as string;
let proceed : boolean = false;
let obj : any = {
connect: true, connect: true,
url : url url : url
}; };
if ( url !== '' && typeof url !== 'undefined') { if ( url !== '' && typeof url !== 'undefined') {
proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`); proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`);
} else { } else {
@ -146,11 +159,10 @@ devices.intval = function () {
$('#camera_type_arduino').prop('checked', 'checked'); $('#camera_type_arduino').prop('checked', 'checked');
$('#intval').removeClass('active'); $('#intval').removeClass('active');
} }
}; }
devices.intvalCb = function (evt, args) { intvalCb (evt : any, args : any) {
'use strict'; let state : any;
let state;
gui.spinner(false); gui.spinner(false);
gui.overlay(false); gui.overlay(false);
if (args.connected && args.connected === true) { if (args.connected && args.connected === true) {
@ -167,12 +179,10 @@ devices.intvalCb = function (evt, args) {
$('#camera_type_arduino').prop('checked', 'checked'); $('#camera_type_arduino').prop('checked', 'checked');
$('#intval').removeClass('active'); $('#intval').removeClass('active');
} }
}; }
digitalSelect () {
devices.digitalSelect = function () { const elem : any = $('#digital');
'use strict'; const extensions : string[] = ['mpg', 'mpeg', 'mov', 'mkv', 'avi', 'mp4'];
const elem = $('#digital');
const extensions = ['mpg', 'mpeg', 'mov', 'mkv', 'avi', 'mp4'];
dialog.showOpenDialog({ dialog.showOpenDialog({
title : `Select video or image sequence`, title : `Select video or image sequence`,
properties : [`openFile`], // openDirectory, multiSelection, openFile properties : [`openFile`], // openDirectory, multiSelection, openFile
@ -183,11 +193,10 @@ devices.digitalSelect = function () {
extensions: ['*'] extensions: ['*']
}, },
] ]
}, (files) => { }, (files : string[]) => {
let valid = false; let valid : boolean = false;
console.dir(files) let path : string = files[0];
let path = files[0]; let displayName : string;
let displayName;
if (path && path !== '') { if (path && path !== '') {
for (let ext of extensions) { for (let ext of extensions) {
if (path.toLowerCase().indexOf(`.${ext}`) !== -1) { if (path.toLowerCase().indexOf(`.${ext}`) !== -1) {
@ -203,14 +212,12 @@ devices.digitalSelect = function () {
} }
}) })
} }
digital () {
devices.digital = function () { const elem : any = $('#digital');
'use strict'; const path : string = elem.attr('data-file');
const elem = $('#digital'); const fileName : string = elem.val();
const path = elem.attr('data-file'); let proceed : boolean = false;
const fileName = elem.val(); let obj : any = {
let proceed = false;
let obj = {
path, path,
fileName fileName
} }
@ -227,12 +234,10 @@ devices.digital = function () {
$('#projector_type_digital').prop('checked', 'checked'); $('#projector_type_digital').prop('checked', 'checked');
$('#digital').removeClass('active'); $('#digital').removeClass('active');
} }
}; }
digitalCb (evt : any, args : any) {
devices.digitalCb = function (evt, args) { let state : any;
'use strict'; let color : number[] = [255, 255, 255];
let state;
let color = [255,255,255];
gui.spinner(false); gui.spinner(false);
gui.overlay(false); gui.overlay(false);
if (args.valid && args.valid === true) { if (args.valid && args.valid === true) {
@ -260,6 +265,9 @@ devices.digitalCb = function (evt, args) {
$('#projector_type_digital').prop('checked', 'checked'); $('#projector_type_digital').prop('checked', 'checked');
$('#digital').removeClass('active'); $('#digital').removeClass('active');
} }
}; }
}
devices = new Devices();
module.exports = devices; module.exports = devices;