Intval connect feature, for accessing an intval3 over the web

This commit is contained in:
mmcwilliams 2018-01-31 10:42:11 -05:00
parent 6613558221
commit 43770b539f
4 changed files with 93 additions and 18 deletions

View File

@ -236,7 +236,7 @@
</div> </div>
<div class="spacer"> <div class="spacer">
<input type="text" id="intval" name="intval" placeholder="INTVAL3 URL"/> <input type="text" id="intval" name="intval" placeholder="INTVAL3 URL"/>
<input type="radio" name="camera_type" value="intval" /> <input type="radio" name="camera_type" value="intval" onclick="devices.intval();" />
</div> </div>
<div> <div>
<h4>Light</h4> <h4>Light</h4>

View File

@ -1,16 +1,14 @@
'use strict' 'use strict'
const req = require('request') const req = require('request')
const devices = {}
class Intval { class Intval {
constructor (device, url) { constructor (url) {
devices[device] = `http://${url}` this._baseUrl = `http://${url}`
} }
move (device, cb) { move (cb) {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const url = `${this._baseUrl}/frame`
const url = `${baseUrl}/frame`
//console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
@ -20,10 +18,9 @@ class Intval {
cb(ms) cb(ms)
}) })
} }
setDir (device, dir, cb) { setDir (dir, cb) {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const url = `${this._baseUrl}/dir?dir=${dir}`
const url = `${baseUrl}/dir?dir=${dir}`
//console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
@ -34,10 +31,9 @@ class Intval {
}) })
} }
setExposure (device, exposure, cb) { setExposure (exposure, cb) {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const url = `${this._baseUrl}/exposure?exposure=${exposure}`
const url = `${baseUrl}/exposure?exposure=${exposure}`
//console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
@ -47,6 +43,24 @@ class Intval {
cb(ms) cb(ms)
}) })
} }
connect (cb) {
const timeStart = +new Date()
const url = `${this._baseUrl}/status`
const opts = {
method : 'GET',
uri : url,
timeout: 5000
}
req(opts, (err, res, body) => {
let ms = (+new Date()) - timeStart
if (err) {
//console.error(err)
return cb(err, ms)
}
cb(null, ms, body)
})
}
} }
module.exports = Intval module.exports = Intval

View File

@ -1,3 +1,4 @@
var devices = {}; var devices = {};
devices.init = function () { devices.init = function () {
@ -10,20 +11,63 @@ devices.listen = function () {
'use strict'; 'use strict';
ipcRenderer.on('ready', devices.ready); ipcRenderer.on('ready', devices.ready);
ipcRenderer.on('intval', devices.intvalCb);
}; };
devices.ready = function (event, arg) { devices.ready = function (event, arg) {
'use strict'; 'use strict';
let opt; let opt;
let devs = [];
gui.spinner(false); gui.spinner(false);
gui.overlay(false); gui.overlay(false);
for (let i in arg) { for (let i in arg) {
if (arg[i] !== '/dev/fake') {
devs.push(arg[i]);
}
opt = $('<option>'); opt = $('<option>');
opt.val(arg[i]); opt.val(arg[i]);
opt.text(arg[i]); opt.text(arg[i]);
$(`#${i}_device`).empty(); $(`#${i}_device`).empty();
$(`#${i}_device`).append(opt); $(`#${i}_device`).append(opt);
} }
if (devs.length > 0) {
$('#devices').empty();
for (let i of devs) {
opt = $('<option>');
opt.val(i);
opt.text(i);
$('#devices').append(opt);
}
}
return event.returnValue = true; 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);
ipcRenderer.send('intval', obj)
} else {
$('input[name=camera_type][value=arduino]').prop('checked', 'checked');
}
};
devices.intvalCb = function (a, b) {
'use strict';
console.dir(a);
console.dir(b);
};
module.exports = devices; module.exports = devices;

View File

@ -157,8 +157,6 @@ var distinguishDevices = function (devices) {
} }
}) })
} }
console.dir(mcopy.settings)
console.dir(checklist)
checklist = devices.map(device => { checklist = devices.map(device => {
return next => { return next => {
@ -171,6 +169,7 @@ var distinguishDevices = function (devices) {
}) })
} }
}) })
async.series(checklist, () => { async.series(checklist, () => {
//done checking devices //done checking devices
if (!connected.projector) { if (!connected.projector) {
@ -307,7 +306,9 @@ proj.end = function (cmd, id, ms) {
mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms}) mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms})
} }
var cam = {} var cam = {
intval : null
}
cam.state = { cam.state = {
dir : true //default dir dir : true //default dir
} }
@ -358,8 +359,24 @@ cam.listen = function () {
cam.move(arg.frame, arg.id) cam.move(arg.frame, arg.id)
} }
event.returnValue = true event.returnValue = true
}); })
}; ipcMain.on('intval', (event, arg) => {
console.dir(arg)
if (arg.connect) {
cam.intval = new Intval(arg.url)
/*cam.intval.connect((err, ms, state) => {
if (err) {
log.info(`Cannot connect to ${arg.url}`, 'INTVAL', true, true)
cam.intval = null
} else {
log.info()
}
})*/
} else if (arg.disconnect) {
cam.intval = null
}
})
}
cam.end = function (cmd, id, ms) { cam.end = function (cmd, id, ms) {
var message = '' var message = ''
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) { if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {