Cleanup whitespace/semicolons and add concept for passing an exposure length to the image in millis.

This commit is contained in:
Matt McWilliams 2024-01-19 06:49:03 -05:00
parent d31ac53bd1
commit 4181c22995
4 changed files with 32 additions and 22 deletions

View File

@ -190,7 +190,8 @@
"error": "E", "error": "E",
"camera_exposure": "G", "camera_exposure": "G",
"state": "H", "state": "H",
"home": "I" "home": "I",
"offset": "O"
} }
} }
} }

View File

@ -59,6 +59,11 @@
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
const remote = require('@electron/remote') const remote = require('@electron/remote')
let imgTmp; let imgTmp;
function delay (ms) {
return new Promise((resolve) => {
return setTimeout(resolve, ms)
})
}
async function setImage (src) { async function setImage (src) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
imgTmp = new Image() imgTmp = new Image()
@ -67,11 +72,18 @@
body.className = '' body.className = ''
body.classList.add('image') body.classList.add('image')
imgTmp.onload = function () { imgTmp.onload = function () {
img.style.backgroundImage = `url('${src}')`; img.style.backgroundImage = `url('${src}')`
return resolve(src); return resolve(src)
}; }
imgTmp.src = src; imgTmp.src = src
}); })
}
function setBlank () {
let img = document.getElementById('img')
img.style.background = ''
img.style.backgroundUrl = ''
img.style.backgroundColor = 'black'
} }
async function onMeter () { async function onMeter () {
console.log('meter') console.log('meter')
@ -134,7 +146,7 @@
const dpr = window.devicePixelRatio || 1 const dpr = window.devicePixelRatio || 1
const screen = window.outerWidth / window.outerHeight const screen = window.outerWidth / window.outerHeight
const body = document.querySelector('body') const body = document.querySelector('body')
let ctx; let ctx
body.className = '' body.className = ''
if (!can.classList.contains('show')) { if (!can.classList.contains('show')) {
can.classList.add('show') can.classList.add('show')
@ -221,12 +233,20 @@
} }
async function onDigital (event, arg) { async function onDigital (event, arg) {
if (arg.src) { if (arg.src) {
if (arg.exposure) {
setBlank()
await delay(10)
}
try { try {
await setImage(arg.src) await setImage(arg.src)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} }
ipcRenderer.send('display_load', { src : arg.src }); if (arg.exposure) {
await delay(arg.exposure)
setBlank()
}
ipcRenderer.send('display_load', { src : arg.src })
} }
return event.returnValue = true return event.returnValue = true
} }

View File

@ -1,13 +1 @@
declare const execRaw: any; declare const execRaw: any;
/**
* Promisified child_process.exec
*
* @param cmd
* @param arg
* @param opts See child_process.exec node docs
* @param {stream.Writable} opts.stdout If defined, child process stdout will be piped to it.
* @param {stream.Writable} opts.stderr If defined, child process stderr will be piped to it.
*
* @returns {Promise<{ stdout: string, stderr: stderr }>}
*/
declare function exec(...args: string[]): Promise<unknown>;

View File

@ -190,7 +190,8 @@
"error": "E", "error": "E",
"camera_exposure": "G", "camera_exposure": "G",
"state": "H", "state": "H",
"home": "I" "home": "I",
"offset": "O"
} }
} }
} }