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 class="spacer">
<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>
<h4>Light</h4>

View File

@ -1,16 +1,14 @@
'use strict'
const req = require('request')
const devices = {}
class Intval {
constructor (device, url) {
devices[device] = `http://${url}`
constructor (url) {
this._baseUrl = `http://${url}`
}
move (device, cb) {
move (cb) {
const timeStart = +new Date()
const baseUrl = devices[device]
const url = `${baseUrl}/frame`
const url = `${this._baseUrl}/frame`
//console.log(url)
req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart
@ -20,10 +18,9 @@ class Intval {
cb(ms)
})
}
setDir (device, dir, cb) {
setDir (dir, cb) {
const timeStart = +new Date()
const baseUrl = devices[device]
const url = `${baseUrl}/dir?dir=${dir}`
const url = `${this._baseUrl}/dir?dir=${dir}`
//console.log(url)
req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart
@ -34,10 +31,9 @@ class Intval {
})
}
setExposure (device, exposure, cb) {
setExposure (exposure, cb) {
const timeStart = +new Date()
const baseUrl = devices[device]
const url = `${baseUrl}/exposure?exposure=${exposure}`
const url = `${this._baseUrl}/exposure?exposure=${exposure}`
//console.log(url)
req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart
@ -47,6 +43,24 @@ class Intval {
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

View File

@ -1,3 +1,4 @@
var devices = {};
devices.init = function () {
@ -10,20 +11,63 @@ devices.listen = function () {
'use strict';
ipcRenderer.on('ready', devices.ready);
ipcRenderer.on('intval', devices.intvalCb);
};
devices.ready = function (event, arg) {
'use strict';
let opt;
let devs = [];
gui.spinner(false);
gui.overlay(false);
for (let i in arg) {
if (arg[i] !== '/dev/fake') {
devs.push(arg[i]);
}
opt = $('<option>');
opt.val(arg[i]);
opt.text(arg[i]);
$(`#${i}_device`).empty();
$(`#${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;
};
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;

View File

@ -157,8 +157,6 @@ var distinguishDevices = function (devices) {
}
})
}
console.dir(mcopy.settings)
console.dir(checklist)
checklist = devices.map(device => {
return next => {
@ -171,6 +169,7 @@ var distinguishDevices = function (devices) {
})
}
})
async.series(checklist, () => {
//done checking devices
if (!connected.projector) {
@ -307,7 +306,9 @@ proj.end = function (cmd, id, ms) {
mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms})
}
var cam = {}
var cam = {
intval : null
}
cam.state = {
dir : true //default dir
}
@ -358,8 +359,24 @@ cam.listen = function () {
cam.move(arg.frame, arg.id)
}
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) {
var message = ''
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {