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);
|
|
|
|
})
|
2018-02-12 19:26:44 +00:00
|
|
|
};
|
2017-12-21 04:47:37 +00:00
|
|
|
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
|
|
|
}
|
2018-02-12 19:26:44 +00:00
|
|
|
};
|
2020-05-19 22:40:19 +00:00
|
|
|
web.advanced = function () {
|
|
|
|
const len = parseInt(document.getElementById('len').value);
|
|
|
|
const multiple = parseInt(document.getElementById('multiple').value);
|
|
|
|
const params = {
|
|
|
|
len,
|
|
|
|
multiple
|
|
|
|
}
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify(params)
|
|
|
|
}
|
|
|
|
if (!params.len) {
|
|
|
|
return alert('You must set a total frame count.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!params.multiple) {
|
|
|
|
return alert('You must set a frame multiple value.');
|
|
|
|
}
|
|
|
|
fetch('/sequence', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.advancedSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error getting /sequence');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.advancedSuccess = function (res) {
|
|
|
|
if (res.started && res.started != false) {
|
|
|
|
STATE.sequence = true;
|
|
|
|
document.getElementById('seq').focus();
|
|
|
|
seqState(true);
|
2020-05-20 03:23:42 +00:00
|
|
|
seqProgress();
|
2020-05-19 22:40:19 +00:00
|
|
|
} else if (res.stopped) {
|
|
|
|
STATE.sequence = false;
|
|
|
|
document.getElementById('seq').blur();
|
|
|
|
seqState(false);
|
|
|
|
getState();
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('Sequence complete');
|
|
|
|
getState();
|
|
|
|
}, STATE.advanced + 1000);
|
|
|
|
};
|
2018-02-12 19:26:44 +00:00
|
|
|
web.reset = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({})
|
|
|
|
}
|
2018-02-12 20:05:50 +00:00
|
|
|
const proceed = confirm(`Reset INTVAL3 to default settings and clear counter?`);
|
|
|
|
if (!proceed) return false
|
2018-02-12 19:26:44 +00:00
|
|
|
fetch('/reset', opts)
|
|
|
|
.then(web.useJson)
|
2018-02-12 19:57:06 +00:00
|
|
|
.then(setState)
|
2018-02-12 19:26:44 +00:00
|
|
|
.catch(err => {
|
|
|
|
console.error('Error posting to /reset');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.restart = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({})
|
|
|
|
}
|
2018-02-12 20:05:50 +00:00
|
|
|
const proceed = confirm(`Restart the INTVAL3? You will be disconnected from it during this process.`);
|
|
|
|
if (!proceed) return false;
|
2018-02-12 19:26:44 +00:00
|
|
|
fetch('/restart', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.restartSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error posting to /restart');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.restartSuccess = function (res) {
|
|
|
|
console.dir(res)
|
|
|
|
};
|
|
|
|
web.update = function () {
|
|
|
|
const opts = {
|
|
|
|
method : 'POST',
|
|
|
|
headers : web._header,
|
|
|
|
body : JSON.stringify({})
|
|
|
|
}
|
2018-02-12 20:05:50 +00:00
|
|
|
const proceed = confirm(`Check for updates? You will be disconnected from the INTVAL3 during this process.`);
|
|
|
|
if (!proceed) return false;
|
2018-02-12 19:26:44 +00:00
|
|
|
fetch('/update', opts)
|
|
|
|
.then(web.useJson)
|
|
|
|
.then(web.updateSuccess)
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Error posting to /update');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
};
|
|
|
|
web.updateSuccess = function (res) {
|
|
|
|
console.dir(res)
|
|
|
|
};
|
2017-11-22 17:04:45 +00:00
|
|
|
web.useJson = function (res) {
|
|
|
|
return res.json();
|
2018-02-12 19:26:44 +00:00
|
|
|
};
|
2017-11-22 17:04:45 +00:00
|
|
|
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;
|
2018-02-12 19:26:44 +00:00
|
|
|
window.reset = web.reset;
|
|
|
|
window.restart = web.restart;
|
|
|
|
window.update = web.update;
|
2020-05-19 22:40:19 +00:00
|
|
|
window.advanced = web.advanced;
|
2017-11-22 19:32:13 +00:00
|
|
|
console.log('started web')
|
2017-11-22 17:10:33 +00:00
|
|
|
};
|