Create a "digital" module, moving the "dig" object from the main.js process to it's own class.

This commit is contained in:
mmcwilliams 2019-03-21 14:58:00 -04:00
parent 72575ce2a4
commit fce259d29b
12 changed files with 276 additions and 0 deletions

56
app/lib/digital/index.js Normal file
View File

@ -0,0 +1,56 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const delay = require("delay");
const dig = {};
dig.state = {
frame: 0,
frames: 0,
path: null,
fileName: null,
info: {},
dir: true
};
dig.set = function (dir) {
dig.state.dir = dir;
};
dig.move = async function () {
let start = +new Date();
let last = dig.state.dir + 0;
if (dig.state.dir) {
dig.state.frame++;
}
else {
dig.state.frame--;
}
if (dig.state.frame < 1) {
dig.state.frame = 1;
}
return (+new Date()) - start;
};
dig.start = async function (lightState) {
try {
await dig.ffmpeg.clearAll();
}
catch (err) {
console.error(err);
}
try {
await dig.ffmpeg.frame(dig.state, lightState);
}
catch (err) {
console.error(err);
}
dig.display.start(dig.state.frame);
await delay(20);
};
dig.end = async function () {
await delay(20);
dig.display.end();
};
module.exports = (display, ffmpeg, ffprobe) => {
dig.display = display;
dig.ffmpeg = ffmpeg;
dig.ffprobe = ffprobe;
return dig;
};
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/digital/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,+BAAgC;AAEhC,MAAM,GAAG,GAAS,EAAE,CAAC;AACrB,GAAG,CAAC,KAAK,GAAG;IACX,KAAK,EAAG,CAAC;IACT,MAAM,EAAG,CAAC;IACV,IAAI,EAAG,IAAI;IACX,QAAQ,EAAG,IAAI;IACf,IAAI,EAAG,EAAE;IACT,GAAG,EAAG,IAAI;CACV,CAAC;AAEF,GAAG,CAAC,GAAG,GAAI,UAAU,GAAa;IACjC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;AACrB,CAAC,CAAA;AAED,GAAG,CAAC,IAAI,GAAG,KAAK;IACf,IAAI,KAA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G,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,OAAO,GAAG,CAAC;AACZ,CAAC,CAAA"}

View File

@ -0,0 +1,11 @@
{
"name": "digital",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

9
app/package-lock.json generated
View File

@ -1536,6 +1536,9 @@
"kuler": "1.0.x" "kuler": "1.0.x"
} }
}, },
"digital": {
"version": "file:lib/digital"
},
"display": { "display": {
"version": "file:lib/display" "version": "file:lib/display"
}, },
@ -4275,6 +4278,9 @@
"resolve": "^1.1.7" "resolve": "^1.1.7"
} }
}, },
"light": {
"version": "file:lib/light"
},
"load-json-file": { "load-json-file": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
@ -5699,6 +5705,9 @@
"through2": "~0.2.3" "through2": "~0.2.3"
} }
}, },
"proj": {
"version": "file:lib/proj"
},
"promise": { "promise": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "http://registry.npmjs.org/promise/-/promise-1.3.0.tgz", "resolved": "http://registry.npmjs.org/promise/-/promise-1.3.0.tgz",

View File

@ -43,6 +43,7 @@
"cam": "file:lib/cam", "cam": "file:lib/cam",
"capture": "file:lib/capture", "capture": "file:lib/capture",
"delay": "file:lib/delay", "delay": "file:lib/delay",
"digital": "file:lib/digital",
"display": "file:lib/display", "display": "file:lib/display",
"electron-updater": "^4.0.6", "electron-updater": "^4.0.6",
"exec": "file:lib/exec", "exec": "file:lib/exec",
@ -52,10 +53,12 @@
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"humanize-duration": "^3.15.1", "humanize-duration": "^3.15.1",
"intval": "file:lib/intval", "intval": "file:lib/intval",
"light": "file:lib/light",
"log": "file:lib/log", "log": "file:lib/log",
"moment": "^2.22.2", "moment": "^2.22.2",
"mscript": "file:lib/mscript", "mscript": "file:lib/mscript",
"node-notifier": "^5.3.0", "node-notifier": "^5.3.0",
"proj": "file:lib/proj",
"serialport": "^7.0.2", "serialport": "^7.0.2",
"server": "file:lib/server", "server": "file:lib/server",
"settings": "file:lib/settings", "settings": "file:lib/settings",

56
cli/lib/digital/index.js Normal file
View File

@ -0,0 +1,56 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const delay = require("delay");
const dig = {};
dig.state = {
frame: 0,
frames: 0,
path: null,
fileName: null,
info: {},
dir: true
};
dig.set = function (dir) {
dig.state.dir = dir;
};
dig.move = async function () {
let start = +new Date();
let last = dig.state.dir + 0;
if (dig.state.dir) {
dig.state.frame++;
}
else {
dig.state.frame--;
}
if (dig.state.frame < 1) {
dig.state.frame = 1;
}
return (+new Date()) - start;
};
dig.start = async function (lightState) {
try {
await dig.ffmpeg.clearAll();
}
catch (err) {
console.error(err);
}
try {
await dig.ffmpeg.frame(dig.state, lightState);
}
catch (err) {
console.error(err);
}
dig.display.start(dig.state.frame);
await delay(20);
};
dig.end = async function () {
await delay(20);
dig.display.end();
};
module.exports = (display, ffmpeg, ffprobe) => {
dig.display = display;
dig.ffmpeg = ffmpeg;
dig.ffprobe = ffprobe;
return dig;
};
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/digital/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,+BAAgC;AAEhC,MAAM,GAAG,GAAS,EAAE,CAAC;AACrB,GAAG,CAAC,KAAK,GAAG;IACX,KAAK,EAAG,CAAC;IACT,MAAM,EAAG,CAAC;IACV,IAAI,EAAG,IAAI;IACX,QAAQ,EAAG,IAAI;IACf,IAAI,EAAG,EAAE;IACT,GAAG,EAAG,IAAI;CACV,CAAC;AAEF,GAAG,CAAC,GAAG,GA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,OAAO,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,OAAa,EAAE,MAAY,EAAE,OAAa,EAAE,EAAE;IAC/D,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,OAAO,GAAG,CAAC;AACZ,CAAC,CAAA"}

View File

@ -0,0 +1,11 @@
{
"name": "digital",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

56
lib/digital/index.js Normal file
View File

@ -0,0 +1,56 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const delay = require("delay");
const dig = {};
dig.state = {
frame: 0,
frames: 0,
path: null,
fileName: null,
info: {},
dir: true
};
dig.set = function (dir) {
dig.state.dir = dir;
};
dig.move = async function () {
let start = +new Date();
let last = dig.state.dir + 0;
if (dig.state.dir) {
dig.state.frame++;
}
else {
dig.state.frame--;
}
if (dig.state.frame < 1) {
dig.state.frame = 1;
}
return (+new Date()) - start;
};
dig.start = async function (lightState) {
try {
await dig.ffmpeg.clearAll();
}
catch (err) {
console.error(err);
}
try {
await dig.ffmpeg.frame(dig.state, lightState);
}
catch (err) {
console.error(err);
}
dig.display.start(dig.state.frame);
await delay(20);
};
dig.end = async function () {
await delay(20);
dig.display.end();
};
module.exports = (display, ffmpeg, ffprobe) => {
dig.display = display;
dig.ffmpeg = ffmpeg;
dig.ffprobe = ffprobe;
return dig;
};
//# sourceMappingURL=index.js.map

1
lib/digital/index.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/digital/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,+BAAgC;AAEhC,MAAM,GAAG,GAAS,EAAE,CAAC;AACrB,GAAG,CAAC,KAAK,G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AAK,CAAC,KAAK,CAAC,CAAA;IAClC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA;AAChB,CAAC,CAAA;AAED,GAAG,CAAC,GAAG,GAAG,KAAK;IACd,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA;IACf,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,OAAa,EAAE,MAAY,EAAE,OAAa,EAAE,EAAE;IAC/D,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,OAAO,GAAG,CAAC;AACZ,CAAC,CAAA"}

11
lib/digital/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "digital",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

60
src/digital/index.ts Normal file
View File

@ -0,0 +1,60 @@
'use strict';
import delay = require('delay');
const dig : any = {};
dig.state = {
frame : 0,
frames : 0,
path : null,
fileName : null,
info : {},
dir : true
};
dig.set = function (dir : boolean) {
dig.state.dir = dir;
}
dig.move = async function () {
let start = +new Date()
let last = dig.state.dir + 0;
if (dig.state.dir) {
dig.state.frame++
} else {
dig.state.frame--
}
if (dig.state.frame < 1) {
dig.state.frame = 1
}
return (+new Date()) - start
}
dig.start = async function (lightState: number[]) {
try {
await dig.ffmpeg.clearAll()
} catch (err) {
console.error(err)
}
try {
await dig.ffmpeg.frame(dig.state, lightState)
} catch (err) {
console.error(err)
}
dig.display.start(dig.state.frame)
await delay(20)
}
dig.end = async function () {
await delay(20)
dig.display.end()
}
module.exports = (display : any, ffmpeg : any, ffprobe : any) => {
dig.display = display;
dig.ffmpeg = ffmpeg;
dig.ffprobe = ffprobe;
return dig;
}