Create the Timing class

This commit is contained in:
Matt McWilliams 2023-02-28 14:30:17 -05:00
parent 3c19cd35cf
commit 7741134917
13 changed files with 152 additions and 33 deletions

View File

@ -2497,6 +2497,7 @@ const devices = require('./lib/ui/devices.js');
const filmout = require('./lib/ui/filmout.js'); const filmout = require('./lib/ui/filmout.js');
const mse = require('./lib/ui/mscript.js'); const mse = require('./lib/ui/mscript.js');
const capper = require('./lib/ui/capper.js'); const capper = require('./lib/ui/capper.js');
const timing = require('./lib/ui/timing.js');
const Mscript = require('./lib/mscript'); const Mscript = require('./lib/mscript');
const { delay } = require('./lib/delay'); const { delay } = require('./lib/delay');
const alertObj = require('./lib/ui/alert.js'); const alertObj = require('./lib/ui/alert.js');

View File

@ -1,8 +0,0 @@
/**
* Delay in an async/await function
*
* @param {integer} ms Milliseconds to delay for
*
* @returns {Promise} Promise to resolve after timeout
**/
declare function delay(ms: number): Promise<unknown>;

View File

@ -83,6 +83,7 @@ class Devices {
else { else {
light.enable(); light.enable();
} }
timing.reset(p);
//devices.profile(arg.profile) //devices.profile(arg.profile)
} }
if (arg.projector_second) { if (arg.projector_second) {
@ -128,6 +129,7 @@ class Devices {
for (let key of keys) { for (let key of keys) {
cfg[key] = keys[key]; cfg[key] = keys[key];
} }
timing.reset(p);
if (typeof p.light !== 'undefined' && p.light === false) { if (typeof p.light !== 'undefined' && p.light === false) {
light.disable(); light.disable();
} }

File diff suppressed because one or more lines are too long

View File

@ -173,6 +173,7 @@ class Sequence {
} }
return true; return true;
}); });
console.dir(cfg);
//timing //timing
for (let step of this.grid) { for (let step of this.grid) {
if (!step) if (!step)

File diff suppressed because one or more lines are too long

54
app/lib/ui/timing.js Normal file
View File

@ -0,0 +1,54 @@
'use strict';
let timing;
class Timing {
constructor() {
this.data = {};
}
reset(profile) {
const keys = Object.keys(profile);
const cmds = Object.keys(cfg.cmd);
let cam;
let proj;
for (let key of keys) {
if (key === 'label') {
continue;
}
else if (key === 'cam') {
cam = 0;
cam += profile[key].time;
cam += profile[key].delay;
for (let cmd of cmds) {
if (cmd.indexOf('camera') !== -1 || cmd.indexOf('black') !== -1) {
this.data[cfg.cmd[cmd]] = cam;
}
}
}
else if (key === 'proj') {
proj = 0;
proj += profile[key].time;
proj += profile[key].delay;
for (let cmd of cmds) {
if (cmd.indexOf('projector') !== -1) {
this.data[cfg.cmd[cmd]] = proj;
}
}
}
}
}
//update with rolling average
update(cmd, ms) {
if (typeof this.data[cmd] !== 'undefined') {
this.data[cmd] = (this.data[cmd] + ms) / 2;
}
}
//get current value
get(cmd) {
if (typeof this.data[cmd] !== 'undefined') {
return this.data[cmd];
}
return 0;
}
}
timing = new Timing();
module.exports = timing;
//# sourceMappingURL=timing.js.map

1
app/lib/ui/timing.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/lib/ui/timing.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,IAAI,MAAe,CAAC;AAMpB,MAAM,MAAM;IAIX;QAHQ,SAAI,GAAgB,EAE3B,CAAA;IAGD,CAAC;IAEM,KAAK,CAAE,OAAa;QAC1B,MAAM,IAAI,GAAc,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAc,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,GAAY,CAAC;QACjB,IAAI,IAAa,CAAC;QAClB,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;YACrB,IAAI,GAAG,KAAK,OAAO,EAAE;gBACpB,SAAQ;aACR;iBAAM,IAAI,GAAG,KAAK,KAAK,EAAE;gBACzB,GAAG,GAAG,CAAC,CAAC;gBACR,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACzB,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;gBAC1B,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;oBACrB,IAAI,GAAG,CA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,26 +20,26 @@ const { delay } = require('delay')
//Objects //Objects
const mcopy = {} const mcopy = {}
let SYSTEM; let SYSTEM
let log; let log
let mainWindow; let mainWindow
let arduino; let arduino
let menu; let menu
let display; let display
let ffmpeg; let ffmpeg
let ffprobe; let ffprobe
let cam; let cam
let cam2; let cam2
let proj; let proj
let proj2; let proj2
let light; let light
let filmout; let filmout
let dev; let dev
let cmd; let cmd
let seq; let seq
let capper; let capper
let alert; let alert
let server; let server
const cfg = require('./data/cfg.json') const cfg = require('./data/cfg.json')
@ -142,12 +142,12 @@ var init = async function () {
app.on('ready', init) app.on('ready', init)
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
app.quit(); app.quit()
}); });
app.on('activate', () => { app.on('activate', () => {
if (mainWindow === null) { if (mainWindow === null) {
createWindow(); createWindow()
} }
}); });

View File

@ -23,6 +23,7 @@ const devices = require('./lib/ui/devices.js');
const filmout = require('./lib/ui/filmout.js'); const filmout = require('./lib/ui/filmout.js');
const mse = require('./lib/ui/mscript.js'); const mse = require('./lib/ui/mscript.js');
const capper = require('./lib/ui/capper.js'); const capper = require('./lib/ui/capper.js');
const timing = require('./lib/ui/timing.js');
const Mscript = require('./lib/mscript'); const Mscript = require('./lib/mscript');
const { delay } = require('./lib/delay'); const { delay } = require('./lib/delay');
const alertObj = require('./lib/ui/alert.js'); const alertObj = require('./lib/ui/alert.js');

View File

@ -79,6 +79,7 @@ class Devices {
} else { } else {
light.enable(); light.enable();
} }
timing.reset(p);
//devices.profile(arg.profile) //devices.profile(arg.profile)
} }
@ -128,6 +129,7 @@ class Devices {
for (let key of keys) { for (let key of keys) {
cfg[key] = keys[key] cfg[key] = keys[key]
} }
timing.reset(p);
if (typeof p.light !== 'undefined' && p.light === false) { if (typeof p.light !== 'undefined' && p.light === false) {
light.disable(); light.disable();
} else { } else {

View File

@ -207,7 +207,7 @@ class Sequence {
} }
return true; return true;
}); });
console.dir(cfg);
//timing //timing
for (let step of this.grid) { for (let step of this.grid) {
if (!step) continue if (!step) continue

65
app/src/lib/ui/timing.ts Normal file
View File

@ -0,0 +1,65 @@
'use strict';
let timing : Timing;
interface TimingData {
[key: string]: number;
}
class Timing {
private data : TimingData = {
}
constructor () {
}
public reset (profile : any) {
const keys : string[] = Object.keys(profile);
const cmds : string[] = Object.keys(cfg.cmd);
let cam : number;
let proj : number;
for (let key of keys) {
if (key === 'label') {
continue
} else if (key === 'cam') {
cam = 0;
cam += profile[key].time;
cam += profile[key].delay;
for (let cmd of cmds) {
if (cmd.indexOf('camera') !== -1 || cmd.indexOf('black') !== -1) {
this.data[cfg.cmd[cmd]] = cam;
}
}
} else if (key === 'proj') {
proj = 0;
proj += profile[key].time;
proj += profile[key].delay;
for (let cmd of cmds) {
if (cmd.indexOf('projector') !== -1) {
this.data[cfg.cmd[cmd]] = proj;
}
}
}
}
}
//update with rolling average
public update (cmd : string, ms : number) {
if (typeof this.data[cmd] !== 'undefined') {
this.data[cmd] = (this.data[cmd] + ms) / 2;
}
}
//get current value
public get (cmd : string) {
if (typeof this.data[cmd] !== 'undefined') {
return this.data[cmd];
}
return 0;
}
}
timing = new Timing();
module.exports = timing;