From e880e44a5c3ea9346187e8b95092fed368b00e91 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Wed, 20 Dec 2017 23:47:37 -0500 Subject: [PATCH] Control sequence with GUIs --- app/www/static/css/index.css | 3 ++- app/www/static/js/intval.core.js | 9 +++++++- app/www/static/js/intval.mobile.js | 34 ++++++++++++++++++++++++++++++ app/www/static/js/intval.web.js | 21 ++++++++++++++++++ index.js | 16 +++++++++++--- 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/app/www/static/css/index.css b/app/www/static/css/index.css index 675d780..b7e093b 100644 --- a/app/www/static/css/index.css +++ b/app/www/static/css/index.css @@ -193,7 +193,7 @@ button.focus{ } #frame{ - padding: 10px 0; + padding: 20px 0; font-size: 24px; } @@ -254,6 +254,7 @@ footer > div.selected{ #seq{ margin-top: 40px; + padding: 10px 0; } #overlay{ diff --git a/app/www/static/js/intval.core.js b/app/www/static/js/intval.core.js index 81dee9c..f0c768d 100644 --- a/app/www/static/js/intval.core.js +++ b/app/www/static/js/intval.core.js @@ -10,7 +10,8 @@ const STATE = { delay : 0, scale : 'ms', delayScale : 'ms', - counter : 0 + counter : 0, + sequence : false }; //functions @@ -160,6 +161,12 @@ var setState = function (res) { exposure = shutter(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('scale').value = exposureScale; setExposureScale(); diff --git a/app/www/static/js/intval.mobile.js b/app/www/static/js/intval.mobile.js index 6254471..fbe2f92 100644 --- a/app/www/static/js/intval.mobile.js +++ b/app/www/static/js/intval.mobile.js @@ -245,6 +245,40 @@ mobile.counterSuccess = function () { 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) { return String.fromCharCode.apply(null, new Uint8Array(buffer)); }; diff --git a/app/www/static/js/intval.web.js b/app/www/static/js/intval.web.js index 66b9850..6bff2b1 100644 --- a/app/www/static/js/intval.web.js +++ b/app/www/static/js/intval.web.js @@ -134,6 +134,27 @@ web.setCounterSuccess = function (res) { forceCounter(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) { return res.json(); } diff --git a/index.js b/index.js index 40a50e3..8c3417e 100644 --- a/index.js +++ b/index.js @@ -311,7 +311,7 @@ function rSequence (req, res, next) { } else { console.time('sequence time') intval._state.sequence = true - sequence.start({ + let seq_id = sequence.start({ loop : [ (next) => { intval.frame(dir, exposure, (len) => { next() @@ -324,7 +324,13 @@ function rSequence (req, res, next) { }, (seq) => { 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() } } @@ -453,12 +459,13 @@ function bSequence (obj, cb) { if (intval._state.sequence && sequence._state.active) { return sequence.setStop(() => { intval._state.sequence = false + log.info('sequence stop'. { method : 'ble', id : seq_id }) return cb() }) } else { console.time('sequence time') intval._state.sequence = true - sequence.start({ + let seq_id = sequence.start({ loop : [ (next) => { intval.frame(dir, exposure, (len) => { next() @@ -471,6 +478,9 @@ function bSequence (obj, cb) { }, (seq) => { console.timeEnd('sequence time') }) + if (seq_id !== false) { + log.info('sequence start'. { method : 'ble', id : seq_id }) + } return cb() } }