Add new display and capture modules. Don't need new capture module rn.

This commit is contained in:
mmcwilliams 2019-02-08 13:16:42 -05:00
parent 2dbed1215d
commit b9a6da957d
3 changed files with 195 additions and 213 deletions

161
app/display.html Normal file
View File

@ -0,0 +1,161 @@
<!doctype html>
<html>
<head>
<title>display</title>
<style>
body{
background: #000;
padding: 0;
margin: 0;
max-width: 100%;
max-height: 100vh;
}
body.meter {
background: rgb(117, 117, 117);
}
#img {
position: absolute;
/*background-image: url(".../img/background.jpg");*/
background-repeat:no-repeat;
background-size: contain;
background-position: center;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#can{
margin: 0;
background: #fff;
display: none;
position: fixed;
left: 0;
top: 0;
}
#can.show{
display: block;
}
</style>
</head>
<body>
<div id="img">
</div>
<canvas id="can">
</canvas>
<script>
'use strict';
const { remote, ipcRenderer } = require('electron')
async function setImage (src) {
return new Promise(async (resolve, reject) => {
//let img = new Image()
let img = document.getElementById('img')
let body = document.querySelector('body')
if (body.classList.contains('meter')) {
body.classList.remove('meter')
}
img.style.backgroundImage = `url('${src}')`;
//img.onload = () => {
//document.body.appendChild(img)
//return resolve(img)
//}
//img.onerror = reject
//img.src = src
})
}
async function setMeter () {
let body = document.querySelector('body')
if (!body.classList.contains('meter')) {
body.classList.add('meter')
}
}
async function setGrid () {
const can = document.getElementById('can')
const ctx = can.getContext('2d')
if (!can.classList.contains('show')) {
can.classList.add('show')
}
can.width = window.innerWidth
can.height = window.innerHeight
can.style.width = `${window.innerWidth}px`
can.style.height = `${window.innerHeight}px`
try{
await drawGrid(can, ctx)
} catch (err) {
alert(JSON.stringify(err))
}
}
async function drawGrid (can, ctx) {
const count = 20
const half = Math.round(count / 2)
const w = can.width
const h = can.height
const wsec = w / count
const hsec= h / count
ctx.moveTo(w / 2, 0)
ctx.lineTo(w / 2, h)
ctx.stroke()
ctx.moveTo(0, h / 2)
ctx.lineTo(w, h / 2)
ctx.stroke()
for (let i = 0; i < count; i++) {
ctx.moveTo(wsec * i, hsec * i)
ctx.lineTo(wsec * i, h - (hsec * i))
ctx.stroke()
ctx.moveTo(wsec * i, hsec * i)
ctx.lineTo(w - (wsec * i), hsec * i)
ctx.stroke()
}
ctx.font = '30px Arial'
for (let i = 0; i < half; i++) {
ctx.fillText(`${(half - i)}`, (wsec * i) + 15, (h / 2) - 15)
ctx.fillText(`${(half - i)}`, (w - (wsec * i)) - 25, (h / 2) - 15)
ctx.fillText(`${(half - i)}`, (w / 2) + 15, (hsec * i) + 25 )
ctx.fillText(`${(half - i)}`, (w / 2) + 15, (h - (hsec * i)) - 15)
}
}
async function onDigital (event, arg) {
console.log('called')
if (arg.src) {
try {
await setImage(arg.src)
} catch (err) {
console.error(err)
}
} else if (arg.meter) {
try {
await setMeter()
} catch (err) {
console.error(err)
}
} else if (arg.grid) {
try {
await setGrid()
} catch (err) {
console.error(err)
}
}
return event.returnValue = true
}
async function onEscape (evt) {
let isEscape = false
let win
evt = evt || window.event
if ('key' in evt) {
isEscape = (evt.key == 'Escape' || evt.key == 'Esc')
} else {
isEscape = (evt.keyCode == 27)
}
if (isEscape) {
win = remote.getCurrentWindow()
win.close()
}
}
ipcRenderer.on('display', onDigital)
document.onkeydown = onEscape
</script>
</body>
</html>

View File

@ -1,221 +1,42 @@
var capture = {},
eventEmitter,
fs = require('fs'),
exec = require('child_process').exec;
'use strict';
capture.active = false;
capture.store = {
events : [],
start : 0
};
const req = require('request');
capture.start = function (first) {
'use strict';
//reset storage
if (capture.active) {
capture.store.events = [];
capture.store.start = +new Date();
const SerialPort = require('serialport');
const Readline = SerialPort.parsers.Readline;
const parser = new Readline('');
const newlineRe = new RegExp('\n', 'g');
const returnRe = new RegExp('\r', 'g');
const exec = require('exec');
const delay = require('delay');
let system = {};
let INTVAL;
async function capture_intval () {
let framePath = `${INTVAL}/frame`;
let res;
try{
res = await req(framePath);
} catch (err) {
return exit('Error triggering frame', 8);
}
};
capture.end = function () {
'use strict';
if (capture.active) {
return capture.save();
} else {
return '';
if (res) {
console.log(res);
}
};
capture.proj_start = function () {
'use strict';
var e = {
'start' : +new Date()
};
capture.store.events.push(e);
};
capture.proj_end = function () {
'use strict';
var e = {
'end' : +new Date()
};
capture.store.events.push(e);
};
//out-000001
capture.pad = function (frame, len) {
'use strict';
var pad = '',
ch = '0';
frame += '';
len = len - frame.length;
if (len <= 0) return frame;
while (true) {
if (len & 1) {
pad += ch;
}
len >>= 1;
if (len) {
ch += ch;
} else {
break;
}
}
return pad + frame;
};
capture.extract = function (input, output, good, real, neg) {
'use strict';
var tc = capture.report.timecode(good),
frame = capture.pad(real, 6),
neg_cmd = ' -vf lutrgb="r=negval:g=negval:b=negval" ',
cmd = 'ffmpeg -ss ' + tc + ' -i ' + input + '{{neg_cmd}}-vframes 1 ' + output + 'out-' + frame + '.tif';
if (neg) {
cmd = cmd.replace('{{neg_cmd}}', neg_cmd);
} else {
cmd = cmd.replace('{{neg_cmd}}', ' ');
}
console.log(cmd);
exec(cmd, function (err, std) {
console.log(err);
console.log(std);
});
};
capture.cp = function (input, output, good, real) {
'use strict';
var still = '';
};
capture.test = function () {
'use strict';
var i = -1,
len = 10,
intval,
next = function () {
i++
if (i === len) {
clearInterval(intval);
intval = null;
//console.dir(capture.store);
parse();
} else {
if (i % 2 === 0) {
capture.proj_start();
} else {
capture.proj_end();
}
}
},
parse = function () {
capture.report.parse(45, 0);
};
capture.start();
next();
intval = setInterval(next, 800);
};
capture.init = function () {
'use strict';
eventEmitter.on('arduino_send', function (cmd) {
if (capture.active
&& cmd.trim() === 'p') {
capture.proj_start();
}
});
eventEmitter.on('arduino_end', function (cmd) {
if (capture.active
&& cmd.trim() === 'p') {
capture.proj_end();
}
});
};
return true;
}
capture.save = function () {
'use strict';
var file = './data/transfer-',
time = +new Date(),
json = JSON.stringify(capture.store);
fs.writeFileSync(file + time + '.json', json, 'utf8');
return file + time + '.json';
};
async function capture_serial () {
//ffmpeg -f image2 -framerate 24 -start_number 090000 -i input_file_%06d.ext -c:v v210 -an output_file
//'-%06d
}
capture.report = {};
capture.report.parse = function (inmark, first, report, fps) {
'use strict';
var all = [],
output = {
good : [],
real : []
},
good = [],
real,
f,
frame,
last = -1,
i;
if (typeof fps === 'undefined') {
fps = 24;
}
f = 1000 / fps;
if (typeof report === 'undefined') {
report = capture.store;
}
if (typeof first === 'undefined') {
first = 0;
}
if (typeof inmark === 'undefined') {
inmark = 0;
}
//first clean frame
for (i = 0; i < report.events.length; i++) {
if (typeof report.events[i].end !== 'undefined') {
frame = (report.events[i].end - report.start) / f;
frame = Math.round(frame);
last = frame;
} else if (typeof report.events[i].start !== 'undefined') {
frame = (report.events[i].start - report.start) / f;
frame = Math.round(frame);
if (last !== -1) {
//console.log(last + '-' + frame);
all.push(capture.report.arr(last, frame));
}
}
}
good = all.map(function (arr) {
var center = Math.round(arr.length / 2);
return arr[center] + inmark;
});
async function capture () {
}
real = output.map(function (val, i) {
return first + i;
});
output.good = good;
output.real = real;
return output;
};
capture.report.arr = function (start, end) {
'use strict';
var arr = [],
i;
for (i = start; i < end + 1; i++) {
arr.push(i);
}
return arr;
};
capture.report.timecode = function (frame) {
'use strict';
//00:03:00 no dropframe
var a = capture.pad(Math.floor((frame / 60) / 60), 2),
b = capture.pad(Math.floor(frame / 60), 2),
c = capture.pad(frame % 24);
return a + ':' + b + ':' + c;
};
capture.report.render = function () {
'use strict';
};
module.exports = function (ee) {
eventEmitter = ee;
module.exports = (sys) => {
system = sys;
return capture;
};
}

View File

@ -112,7 +112,7 @@ async function start (frame) {
module.exports = function (sys) {
system = sys;
TMPDIR = path.join(system.tmp, 'intval_go_node');
TMPDIR = path.join(system.tmp, 'mcopy_digital');
if (system.platform !== 'nix') {
wv = new WebView();