2018-01-31 15:42:11 +00:00
|
|
|
|
2016-06-19 00:15:41 +00:00
|
|
|
var devices = {};
|
|
|
|
|
|
|
|
devices.init = function () {
|
|
|
|
'use strict';
|
2018-02-01 19:52:47 +00:00
|
|
|
devices.listen();;
|
|
|
|
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 () {
|
|
|
|
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(keys[0]);
|
|
|
|
};
|
|
|
|
devices.profile = function (profile) {
|
|
|
|
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]
|
|
|
|
}
|
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);
|
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';
|
2018-02-01 19:52:47 +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 ';
|
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 ') {
|
|
|
|
gui.notify('DEVICES', notify)
|
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)
|
|
|
|
//devices.profile(arg.profile)
|
|
|
|
}
|
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';
|
|
|
|
const url = $('#intval').val()
|
|
|
|
let proceed = false
|
|
|
|
let obj = {
|
|
|
|
connect: true,
|
|
|
|
url : url
|
|
|
|
}
|
|
|
|
if ( url !== '' && typeof url !== 'undefined') {
|
2018-02-01 19:52:47 +00:00
|
|
|
proceed = confirm(`Are you sure you want to connect to INTVAL3 @ ${url}?`)
|
2018-01-31 15:42:11 +00:00
|
|
|
} else {
|
|
|
|
alert('Cannot connect to INTVAL3 url as entered.')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proceed) {
|
|
|
|
gui.overlay(true);
|
2018-02-01 02:46:37 +00:00
|
|
|
gui.spinner(true, `Connecting to INTVAL3 @ ${url}`);
|
2018-01-31 15:42:11 +00:00
|
|
|
ipcRenderer.send('intval', obj)
|
|
|
|
} else {
|
2018-02-01 02:46:37 +00:00
|
|
|
$('#camera_type_arduino').prop('checked', 'checked');
|
2018-02-01 19:52:47 +00:00
|
|
|
$('#intval').removeClass('active');
|
2018-01-31 15:42:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-01 02:46:37 +00:00
|
|
|
devices.intvalCb = function (evt, args) {
|
2018-01-31 15:42:11 +00:00
|
|
|
'use strict';
|
2018-02-01 19:52:47 +00:00
|
|
|
let state;
|
2018-02-01 02:46:37 +00:00
|
|
|
gui.spinner(false);
|
|
|
|
gui.overlay(false);
|
|
|
|
if (args.connected && args.connected === true) {
|
|
|
|
//success state
|
2018-02-01 19:52:47 +00:00
|
|
|
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()
|
2018-02-01 02:46:37 +00:00
|
|
|
} else {
|
|
|
|
$('#camera_type_arduino').prop('checked', 'checked');
|
2018-02-01 19:52:47 +00:00
|
|
|
$('#intval').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;
|