Control sequence with GUIs

This commit is contained in:
mmcw-dev 2017-12-20 23:47:37 -05:00
parent ccd87b4d7e
commit e880e44a5c
5 changed files with 78 additions and 5 deletions

View File

@ -193,7 +193,7 @@ button.focus{
} }
#frame{ #frame{
padding: 10px 0; padding: 20px 0;
font-size: 24px; font-size: 24px;
} }
@ -254,6 +254,7 @@ footer > div.selected{
#seq{ #seq{
margin-top: 40px; margin-top: 40px;
padding: 10px 0;
} }
#overlay{ #overlay{

View File

@ -10,7 +10,8 @@ const STATE = {
delay : 0, delay : 0,
scale : 'ms', scale : 'ms',
delayScale : 'ms', delayScale : 'ms',
counter : 0 counter : 0,
sequence : false
}; };
//functions //functions
@ -160,6 +161,12 @@ var setState = function (res) {
exposure = shutter(STATE.exposure); exposure = shutter(STATE.exposure);
exposureScale = scaleAuto(STATE.exposure); exposureScale = scaleAuto(STATE.exposure);
if (res.sequence === true) {
STATE.sequence = true;
mobile.ble.active = true;
document.getElementById('seq').classList.add('focus');
}
document.getElementById('str').value = exposure.str; document.getElementById('str').value = exposure.str;
document.getElementById('scale').value = exposureScale; document.getElementById('scale').value = exposureScale;
setExposureScale(); setExposureScale();

View File

@ -245,6 +245,40 @@ mobile.counterSuccess = function () {
mobile.getState(); mobile.getState();
}; };
mobile.sequence = function () {
const opts = {
type : 'sequence'
};
if (!mobile.ble.connected) {
return alert('Not connected to an INTVAL device.');
}
ble.write(mobile.ble.device.id,
mobile.ble.SERVICE_ID,
mobile.ble.CHAR_ID,
stringToBytes(JSON.stringify(opts)), //check length?
mobile.frameSuccess,
mobile.ble.onError);
document.getElementById('seq').classList.add('focus');
mobile.ble.active = true;
};
mobile.sequenceSuccess = function () {
console.log('Sequence state changed');
mobile.getState();
setTimeout(() => {
if (STATE.sequence) {
mobile.ble.active = true;
if (!document.getElementById('seq').classList.contains('focus')) {
document.getElementById('seq').classList.add('focus');
}
} else {
mobile.ble.active = false;
document.getElementById('seq').classList.remove('focus');
}
}, 20);
}
function bytesToString (buffer) { function bytesToString (buffer) {
return String.fromCharCode.apply(null, new Uint8Array(buffer)); return String.fromCharCode.apply(null, new Uint8Array(buffer));
}; };

View File

@ -134,6 +134,27 @@ web.setCounterSuccess = function (res) {
forceCounter(res.counter); forceCounter(res.counter);
console.log(`setCounter to ${res.counter}`); console.log(`setCounter to ${res.counter}`);
}; };
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) {
document.getElementById('seq').focus();
} else if (res.stopped) {
document.getElementById('seq').blur();
}
}
web.useJson = function (res) { web.useJson = function (res) {
return res.json(); return res.json();
} }

View File

@ -311,7 +311,7 @@ function rSequence (req, res, next) {
} else { } else {
console.time('sequence time') console.time('sequence time')
intval._state.sequence = true intval._state.sequence = true
sequence.start({ let seq_id = sequence.start({
loop : [ (next) => { loop : [ (next) => {
intval.frame(dir, exposure, (len) => { intval.frame(dir, exposure, (len) => {
next() next()
@ -324,7 +324,13 @@ function rSequence (req, res, next) {
}, (seq) => { }, (seq) => {
console.timeEnd('sequence time') console.timeEnd('sequence time')
}) })
res.send({ started : true })
if (seq_id === false) {
res.send({ started : false })
} else {
res.send({ started : true , id : seq_id })
}
return next() return next()
} }
} }
@ -453,12 +459,13 @@ function bSequence (obj, cb) {
if (intval._state.sequence && sequence._state.active) { if (intval._state.sequence && sequence._state.active) {
return sequence.setStop(() => { return sequence.setStop(() => {
intval._state.sequence = false intval._state.sequence = false
log.info('sequence stop'. { method : 'ble', id : seq_id })
return cb() return cb()
}) })
} else { } else {
console.time('sequence time') console.time('sequence time')
intval._state.sequence = true intval._state.sequence = true
sequence.start({ let seq_id = sequence.start({
loop : [ (next) => { loop : [ (next) => {
intval.frame(dir, exposure, (len) => { intval.frame(dir, exposure, (len) => {
next() next()
@ -471,6 +478,9 @@ function bSequence (obj, cb) {
}, (seq) => { }, (seq) => {
console.timeEnd('sequence time') console.timeEnd('sequence time')
}) })
if (seq_id !== false) {
log.info('sequence start'. { method : 'ble', id : seq_id })
}
return cb() return cb()
} }
} }