Set counter, exposure and delay all with fetch() and vanilla js dom manipulation.

This commit is contained in:
mmcwilliams 2017-11-21 18:09:59 -05:00
parent ab609c4f31
commit f706926f26
1 changed files with 54 additions and 37 deletions

View File

@ -344,15 +344,16 @@
var setDelayScale = function () { var setDelayScale = function () {
'use strict'; 'use strict';
var scale = $('#scale').val(); const scale = document.getElementById('scale').value;
const elem = document.getElementsById('delay');
if (scale === 'ms') { if (scale === 'ms') {
$('#delay').val(STATE.delay); elem.value = STATE.delay;
} else if (scale === 'sec') { } else if (scale === 'sec') {
$('#delay').val(STATE.delay / 1000); elem.value = STATE.delay / 1000;
} else if (scale === 'min') { } else if (scale === 'min') {
$('#delay').val(STATE.delay / (1000 * 60)); elem.value = STATE.delay / (1000 * 60);
} else if (scale === 'hour') { } else if (scale === 'hour') {
$('#delay').val(STATE.delay / (1000 * 60 * 60)); elem.value = STATE.delay / (1000 * 60 * 60);
} }
STATE.delayScale = scale; STATE.delayScale = scale;
}; };
@ -479,62 +480,78 @@
STATE.delay = res.frame.delay; STATE.delay = res.frame.delay;
}; };
web.setExposure = function () { web.setExposure = function () {
var exposure = $('#exposure').val(); let exposure = document.getElementById('exposure').value;
let scaledExposure;
let opts
if (exposure === '' || exposure === null) { if (exposure === '' || exposure === null) {
exposure = 0; exposure = 0;
} }
var scaledExposure = scaleTime(exposure, STATE.scale); scaledExposure = scaleTime(exposure, STATE.scale);
$.ajax({ opts = {
method : 'POST', method : 'POST',
url : '/exposure', headers : web._header,
data : JSON.stringify({ exposure : scaledExposure }), body : JSON.stringify({ eposure : scaledExposure })
contentType: 'application/json', }
dataType : 'json', fetch('/exposure', opts)
success : web.setExposureSuccess .then(web.useJson)
}); .then(web.setExposureSuccess)
.catch(err => {
console.error('Error setting exposure');
console.error(err);
});
}; };
web.setExposureSuccess = function (res) { web.setExposureSuccess = function (res) {
var exposure; let exposure;
if (res.exposure < BOLEX.expected) { if (res.exposure < BOLEX.expected) {
res.exposure = BOLEX.expected; res.exposure = BOLEX.expected;
} }
STATE.exposure = res.exposure; STATE.exposure = res.exposure;
exposure = shutter(STATE.exposure); exposure = shutter(STATE.exposure);
$('#str').text(exposure.str); document.getElementById('str').value = exposure.str;
console.log('setExposure to ' + res.exposure); console.log(`setExposure to ${res.exposure}`);
}; };
web.setDelay = function () { web.setDelay = function () {
var delay = $('#delay').val(); const delay = document.getElementById('delay').value;
var scaledDelay = scaleTime(delay, STATE.delayScale); const scaledDelay = scaleTime(delay, STATE.delayScale)
$.ajax({ let opts = {
method : 'POST', method : 'POST',
url : '/delay', headers : web._header,
data : JSON.stringify({ delay : scaledDelay }), body : JSON.stringify({ delay : scaledDelay })
contentType: 'application/json', }
dataType : 'json', fetch('/delay', opts)
success : web.setDelaySuccess .then(web.useJson)
}); .then(web.setDelaySuccess)
.catch(err => {
console.error('Error setting delay');
console.error(err);
})
}; };
web.setDelaySuccess = function (res) { web.setDelaySuccess = function (res) {
STATE.delay = res.delay; STATE.delay = res.delay;
console.log('setDelay to ' + res.delay); console.log(`setDelay to ${res.delay}`);
}; };
web.setCounter = function () { web.setCounter = function () {
var counter = $('#counter').val(); const counter = document.getElementById('counter').value;
$.ajax({ const opts = {
method : 'POST', method : 'POST',
url : '/counter', headers : web._header,
data : JSON.stringify({ counter : counter }), data : JSON.stringify({ counter : counter })
contentType: 'application/json', }
dataType : 'json', fetch('/counter', opt)
success : web.setCounterSuccess .then(web.useJson)
}); .then(web.setCounterSuccess)
.catch(err => {
console.error('Error setting counter');
console.error(err);
})
}; };
web.setCounterSuccess = function (res) { web.setCounterSuccess = function (res) {
STATE.counter = res.counter; STATE.counter = res.counter;
console.log('setCounter to ' + res.counter); console.log(`setCounter to ${res.counter}`);
}; };
web.useJson = function (res) {
return res.json();
}
web.init = function () { web.init = function () {
frame = web.frame; frame = web.frame;
getState = web.getState; getState = web.getState;