2017-11-22 17:04:45 +00:00
|
|
|
'use strict'
|
|
|
|
const web = {};
|
|
|
|
web._header = new Headers({ 'content-type' : 'application/json' })
|
|
|
|
web.frame = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header
|
|
|
|
};
|
|
|
|
fetch('/frame', opts)
|
|
|
|
.then(res => {
|
|
|
|
return res.json()
|
|
|
|
})
|
|
|
|
.then(web.frameSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error triggering frame')
|
|
|
|
console.error(err)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
web.frameSuccess = function (res) {
|
|
|
|
document.getElementById('frame').blur();
|
|
|
|
console.log(`Frame ${res.dir ? 'forward' : 'backward'} took ${res.len}ms`)
|
|
|
|
if (res.dir === true) {
|
|
|
|
incCounter(1);
|
|
|
|
} else {
|
|
|
|
incCounter(-1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
web.setDir = function () {
|
|
|
|
const dir = !document.getElementById('dir').checked;
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({ dir : dir })
|
|
|
|
};
|
|
|
|
fetch('/dir', opts)
|
|
|
|
.then(res => {
|
|
|
|
return res.json()
|
|
|
|
})
|
|
|
|
.then(web.setDirSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error setting direction')
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
web.setDirSuccess = function (res) {
|
|
|
|
STATE.dir = res.dir;
|
|
|
|
setDirLabel(res.dir);
|
|
|
|
console.log(`setDir to ${res.dir}`);
|
|
|
|
};
|
|
|
|
web.getState = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'GET'
|
|
|
|
}
|
|
|
|
fetch('/status', opts)
|
|
|
|
.then(res => {
|
|
|
|
return res.json();
|
|
|
|
})
|
2017-12-13 22:52:25 +00:00
|
|
|
.then(setState)
|
2017-11-22 17:04:45 +00:00
|
|
|
.catch(err => {
|
|
|
|
console.error('Error getting state');
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
web.setExposure = function () {
|
|
|
|
let exposure = document.getElementById('exposure').value;
|
|
|
|
let scaledExposure;
|
|
|
|
let opts
|
|
|
|
if (exposure === '' || exposure === null) {
|
|
|
|
exposure = 0;
|
|
|
|
}
|
|
|
|
scaledExposure = scaleTime(exposure, STATE.scale);
|
|
|
|
opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({ exposure : scaledExposure })
|
|
|
|
}
|
|
|
|
fetch('/exposure', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.setExposureSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error setting exposure');
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
web.setExposureSuccess = function (res) {
|
|
|
|
let exposure;
|
|
|
|
if (res.exposure < BOLEX.expected) {
|
|
|
|
res.exposure = BOLEX.expected;
|
|
|
|
}
|
|
|
|
STATE.exposure = res.exposure;
|
|
|
|
exposure = shutter(STATE.exposure);
|
2017-12-24 03:30:17 +00:00
|
|
|
document.getElementById('str').innerHTML = exposure.str;
|
2017-11-22 17:04:45 +00:00
|
|
|
console.log(`setExposure to ${res.exposure}`);
|
|
|
|
};
|
|
|
|
web.setDelay = function () {
|
|
|
|
const delay = document.getElementById('delay').value;
|
|
|
|
const scaledDelay = scaleTime(delay, STATE.delayScale)
|
|
|
|
let opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({ delay : scaledDelay })
|
|
|
|
}
|
|
|
|
fetch('/delay', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.setDelaySuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error setting delay');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.setDelaySuccess = function (res) {
|
|
|
|
STATE.delay = res.delay;
|
|
|
|
console.log(`setDelay to ${res.delay}`);
|
|
|
|
};
|
|
|
|
web.setCounter = function () {
|
|
|
|
const counter = document.getElementById('counter').value;
|
|
|
|
const change = prompt(`Change counter value?`, counter);
|
|
|
|
if (change === null || !isNumeric(change)) return false;
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({ counter : change })
|
|
|
|
}
|
|
|
|
fetch('/counter', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.setCounterSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error setting counter');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.setCounterSuccess = function (res) {
|
|
|
|
STATE.counter = res.counter;
|
|
|
|
forceCounter(res.counter);
|
|
|
|
console.log(`setCounter to ${res.counter}`);
|
|
|
|
};
|
2017-12-21 04:47:37 +00:00
|
|
|
web.sequence = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({})
|
|
|
|
}
|
|
|
|
fetch('/sequence', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.sequenceSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error getting /sequence');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
web.sequenceSuccess = function (res) {
|
|
|
|
if (res.started && res.started != false) {
|
2017-12-21 04:59:36 +00:00
|
|
|
STATE.sequence = true;
|
2017-12-21 04:47:37 +00:00
|
|
|
document.getElementById('seq').focus();
|
2017-12-22 20:28:09 +00:00
|
|
|
seqState(true);
|
2017-12-21 04:47:37 +00:00
|
|
|
} else if (res.stopped) {
|
2017-12-21 04:59:36 +00:00
|
|
|
STATE.sequence = false;
|
2017-12-21 04:47:37 +00:00
|
|
|
document.getElementById('seq').blur();
|
2017-12-22 20:28:09 +00:00
|
|
|
seqState(false);
|
2017-12-21 05:15:55 +00:00
|
|
|
mobile.getState();
|
2017-12-21 04:47:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 17:04:45 +00:00
|
|
|
web.useJson = function (res) {
|
|
|
|
return res.json();
|
|
|
|
}
|
|
|
|
web.init = function () {
|
2017-11-23 13:59:49 +00:00
|
|
|
window.frame = web.frame;
|
|
|
|
window.getState = web.getState;
|
|
|
|
window.setDir = web.setDir;
|
2017-12-13 22:52:25 +00:00
|
|
|
window.setDelay = web.setDelay;
|
2017-11-23 13:59:49 +00:00
|
|
|
window.setExposure = web.setExposure;
|
|
|
|
window.setCounter = web.setCounter;
|
2017-12-21 04:49:51 +00:00
|
|
|
window.sequence = web.sequence;
|
2017-11-22 19:32:13 +00:00
|
|
|
console.log('started web')
|
2017-11-22 17:10:33 +00:00
|
|
|
};
|