diff --git a/app/lib/proj/index.js b/app/lib/proj/index.js new file mode 100644 index 0000000..6ae37a1 --- /dev/null +++ b/app/lib/proj/index.js @@ -0,0 +1,169 @@ +/** class representing the Projector features **/ +class Projector { + /** + * + **/ + constructor(arduino, cfg, ui, dig) { + this.state = { dir: true, digital: false }; + this.arduino = null; + this.arduino = arduino; + this.cfg = cfg; + this.ui = ui; + this.dig = dig; + this.init(); + } + /** + * + **/ + async init() { + this.log = await require('log')({}); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('proj', this.listener.bind(this)); + this.ipc.on('digital', this.connectDigital.bind(this)); + } + /** + * + **/ + async set(dir, id) { + let cmd; + let ms; + if (dir) { + cmd = this.cfg.arduino.cmd.proj_forward; + } + else { + cmd = this.cfg.arduino.cmd.proj_backward; + } + this.state.dir = dir; + if (this.state.digital) { + //this.dig.set(dir) + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error setting projector direction', err); + } + } + return await this.end(cmd, id, ms); + } + /** + * + **/ + async move(frame, id) { + const cmd = this.cfg.arduino.cmd.projector; + let ms; + if (this.state.digital) { + try { + //ms = await this.dig.move() + } + catch (err) { + this.log.error(err); + } + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error moving projector', err); + } + } + this.log.info('Projector move time', { ms }); + return await this.end(this.cfg.arduino.cmd.projector, id, ms); + } + /** + * + **/ + async listener(event, arg) { + if (typeof arg.dir !== 'undefined') { + try { + await this.set(arg.dir, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.frame !== 'undefined') { + try { + await this.move(arg.frame, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.val !== 'undefined') { + //this.dig.state.frame = arg.val + } + event.returnValue = true; + } + /** + * + **/ + async end(cmd, id, ms) { + let message = ''; + if (cmd === this.cfg.arduino.cmd.proj_forward) { + message = 'Projector set to FORWARD'; + } + else if (cmd === this.cfg.arduino.cmd.proj_backward) { + message = 'Projector set to BACKWARD'; + } + else if (cmd === this.cfg.arduino.cmd.projector) { + message = 'Projector '; + if (this.state.dir) { + message += 'ADVANCED'; + } + else { + message += 'REWOUND'; + } + message += ' 1 frame'; + } + this.log.info(message, 'PROJECTOR'); + return await this.ui.send('proj', { cmd: cmd, id: id, ms: ms }); + } + /** + * Use a file as the "digital" source on "projector" + * + **/ + async connectDigital(evt, arg) { + let info; + let frames = 0; + try { + info = await this.dig.ffprobe.info(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + try { + frames = await this.dig.ffprobe.frames(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + this.dig.state.frame = 0; + this.dig.state.path = arg.path; + this.dig.state.fileName = arg.fileName; + this.dig.state.frames = frames; + this.dig.state.info = info; + this.log.info(`Opened ${this.dig.state.fileName}`, 'DIGITAL', true, true); + this.log.info(`Frames : ${frames}`, 'DIGITAL', true, true); + this.state.digital = true; + return await this.ui.send('digital', { valid: true, state: JSON.stringify(this.dig.state) }); + } +} +module.exports = function (arduino, cfg, ui, dig) { + return new Projector(arduino, cfg, ui, dig); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/app/lib/proj/index.js.map b/app/lib/proj/index.js.map new file mode 100644 index 0000000..f4171df --- /dev/null +++ b/app/lib/proj/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proj/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,MAAM,SAAS;IAUd;;QAEI;IACJ,YAAa,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;QAZtD,UAAK,GAAS,EAAE,GAAG,EAAG,IAAI,EAAE,OAAO,EAAG,KAAK,EAAE,CAAC;QAC9C,YAAO,GAAa,IAAI,CAAC;QAYhC,IAAI,CA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AAC,IAAI,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QACvC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAG,IAAI,EAAE,KAAK,EAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;CACD;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;IAC3E,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAA"} \ No newline at end of file diff --git a/app/lib/proj/package.json b/app/lib/proj/package.json new file mode 100644 index 0000000..9c9782f --- /dev/null +++ b/app/lib/proj/package.json @@ -0,0 +1,11 @@ +{ + "name": "proj", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/cli/lib/proj/index.js b/cli/lib/proj/index.js new file mode 100644 index 0000000..6ae37a1 --- /dev/null +++ b/cli/lib/proj/index.js @@ -0,0 +1,169 @@ +/** class representing the Projector features **/ +class Projector { + /** + * + **/ + constructor(arduino, cfg, ui, dig) { + this.state = { dir: true, digital: false }; + this.arduino = null; + this.arduino = arduino; + this.cfg = cfg; + this.ui = ui; + this.dig = dig; + this.init(); + } + /** + * + **/ + async init() { + this.log = await require('log')({}); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('proj', this.listener.bind(this)); + this.ipc.on('digital', this.connectDigital.bind(this)); + } + /** + * + **/ + async set(dir, id) { + let cmd; + let ms; + if (dir) { + cmd = this.cfg.arduino.cmd.proj_forward; + } + else { + cmd = this.cfg.arduino.cmd.proj_backward; + } + this.state.dir = dir; + if (this.state.digital) { + //this.dig.set(dir) + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error setting projector direction', err); + } + } + return await this.end(cmd, id, ms); + } + /** + * + **/ + async move(frame, id) { + const cmd = this.cfg.arduino.cmd.projector; + let ms; + if (this.state.digital) { + try { + //ms = await this.dig.move() + } + catch (err) { + this.log.error(err); + } + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error moving projector', err); + } + } + this.log.info('Projector move time', { ms }); + return await this.end(this.cfg.arduino.cmd.projector, id, ms); + } + /** + * + **/ + async listener(event, arg) { + if (typeof arg.dir !== 'undefined') { + try { + await this.set(arg.dir, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.frame !== 'undefined') { + try { + await this.move(arg.frame, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.val !== 'undefined') { + //this.dig.state.frame = arg.val + } + event.returnValue = true; + } + /** + * + **/ + async end(cmd, id, ms) { + let message = ''; + if (cmd === this.cfg.arduino.cmd.proj_forward) { + message = 'Projector set to FORWARD'; + } + else if (cmd === this.cfg.arduino.cmd.proj_backward) { + message = 'Projector set to BACKWARD'; + } + else if (cmd === this.cfg.arduino.cmd.projector) { + message = 'Projector '; + if (this.state.dir) { + message += 'ADVANCED'; + } + else { + message += 'REWOUND'; + } + message += ' 1 frame'; + } + this.log.info(message, 'PROJECTOR'); + return await this.ui.send('proj', { cmd: cmd, id: id, ms: ms }); + } + /** + * Use a file as the "digital" source on "projector" + * + **/ + async connectDigital(evt, arg) { + let info; + let frames = 0; + try { + info = await this.dig.ffprobe.info(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + try { + frames = await this.dig.ffprobe.frames(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + this.dig.state.frame = 0; + this.dig.state.path = arg.path; + this.dig.state.fileName = arg.fileName; + this.dig.state.frames = frames; + this.dig.state.info = info; + this.log.info(`Opened ${this.dig.state.fileName}`, 'DIGITAL', true, true); + this.log.info(`Frames : ${frames}`, 'DIGITAL', true, true); + this.state.digital = true; + return await this.ui.send('digital', { valid: true, state: JSON.stringify(this.dig.state) }); + } +} +module.exports = function (arduino, cfg, ui, dig) { + return new Projector(arduino, cfg, ui, dig); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/cli/lib/proj/index.js.map b/cli/lib/proj/index.js.map new file mode 100644 index 0000000..f4171df --- /dev/null +++ b/cli/lib/proj/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proj/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,MAAM,SAAS;IAUd;;QAEI;IACJ,YAAa,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;QAZtD,UAAK,GAAS,EAAE,GAAG,EAAG,IAAI,EAAE,OAAO,EAAG,KAAK,EAAE,CAAC;QAC9C,YAAO,GAAa,IAAI,CAAC;QAYhC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC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AAG,GAAG,CAAC,QAAQ,CAAC;QACvC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAG,IAAI,EAAE,KAAK,EAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;CACD;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;IAC3E,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAA"} \ No newline at end of file diff --git a/cli/lib/proj/package.json b/cli/lib/proj/package.json new file mode 100644 index 0000000..9c9782f --- /dev/null +++ b/cli/lib/proj/package.json @@ -0,0 +1,11 @@ +{ + "name": "proj", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/lib/proj/index.js b/lib/proj/index.js new file mode 100644 index 0000000..6ae37a1 --- /dev/null +++ b/lib/proj/index.js @@ -0,0 +1,169 @@ +/** class representing the Projector features **/ +class Projector { + /** + * + **/ + constructor(arduino, cfg, ui, dig) { + this.state = { dir: true, digital: false }; + this.arduino = null; + this.arduino = arduino; + this.cfg = cfg; + this.ui = ui; + this.dig = dig; + this.init(); + } + /** + * + **/ + async init() { + this.log = await require('log')({}); + this.ipc = require('electron').ipcMain; + this.listen(); + } + /** + * + **/ + listen() { + this.ipc.on('proj', this.listener.bind(this)); + this.ipc.on('digital', this.connectDigital.bind(this)); + } + /** + * + **/ + async set(dir, id) { + let cmd; + let ms; + if (dir) { + cmd = this.cfg.arduino.cmd.proj_forward; + } + else { + cmd = this.cfg.arduino.cmd.proj_backward; + } + this.state.dir = dir; + if (this.state.digital) { + //this.dig.set(dir) + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error setting projector direction', err); + } + } + return await this.end(cmd, id, ms); + } + /** + * + **/ + async move(frame, id) { + const cmd = this.cfg.arduino.cmd.projector; + let ms; + if (this.state.digital) { + try { + //ms = await this.dig.move() + } + catch (err) { + this.log.error(err); + } + } + else { + try { + ms = await this.arduino.send('projector', cmd); + } + catch (err) { + this.log.error('Error moving projector', err); + } + } + this.log.info('Projector move time', { ms }); + return await this.end(this.cfg.arduino.cmd.projector, id, ms); + } + /** + * + **/ + async listener(event, arg) { + if (typeof arg.dir !== 'undefined') { + try { + await this.set(arg.dir, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.frame !== 'undefined') { + try { + await this.move(arg.frame, arg.id); + } + catch (err) { + this.log.error(err); + } + } + else if (typeof arg.val !== 'undefined') { + //this.dig.state.frame = arg.val + } + event.returnValue = true; + } + /** + * + **/ + async end(cmd, id, ms) { + let message = ''; + if (cmd === this.cfg.arduino.cmd.proj_forward) { + message = 'Projector set to FORWARD'; + } + else if (cmd === this.cfg.arduino.cmd.proj_backward) { + message = 'Projector set to BACKWARD'; + } + else if (cmd === this.cfg.arduino.cmd.projector) { + message = 'Projector '; + if (this.state.dir) { + message += 'ADVANCED'; + } + else { + message += 'REWOUND'; + } + message += ' 1 frame'; + } + this.log.info(message, 'PROJECTOR'); + return await this.ui.send('proj', { cmd: cmd, id: id, ms: ms }); + } + /** + * Use a file as the "digital" source on "projector" + * + **/ + async connectDigital(evt, arg) { + let info; + let frames = 0; + try { + info = await this.dig.ffprobe.info(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + try { + frames = await this.dig.ffprobe.frames(arg.path); + } + catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid: false }); + return false; + } + this.dig.state.frame = 0; + this.dig.state.path = arg.path; + this.dig.state.fileName = arg.fileName; + this.dig.state.frames = frames; + this.dig.state.info = info; + this.log.info(`Opened ${this.dig.state.fileName}`, 'DIGITAL', true, true); + this.log.info(`Frames : ${frames}`, 'DIGITAL', true, true); + this.state.digital = true; + return await this.ui.send('digital', { valid: true, state: JSON.stringify(this.dig.state) }); + } +} +module.exports = function (arduino, cfg, ui, dig) { + return new Projector(arduino, cfg, ui, dig); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/proj/index.js.map b/lib/proj/index.js.map new file mode 100644 index 0000000..f4171df --- /dev/null +++ b/lib/proj/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proj/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,MAAM,SAAS;IAUd;;QAEI;IACJ,YAAa,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;QAZtD,UAAK,GAAS,EAAE,GAAG,EAAG,IAAI,EAAE,OAAO,EAAG,KAAK,EAAE,CAAC;QAC9C,YAAO,GAAa,IAAI,CAAC;QAYhC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf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AM,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAG,IAAI,EAAE,KAAK,EAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;CACD;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,OAAiB,EAAE,GAAS,EAAE,EAAQ,EAAE,GAAS;IAC3E,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAA"} \ No newline at end of file diff --git a/lib/proj/package.json b/lib/proj/package.json new file mode 100644 index 0000000..9c9782f --- /dev/null +++ b/lib/proj/package.json @@ -0,0 +1,11 @@ +{ + "name": "proj", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/src/proj/index.ts b/src/proj/index.ts new file mode 100644 index 0000000..5607522 --- /dev/null +++ b/src/proj/index.ts @@ -0,0 +1,172 @@ +/** class representing the Projector features **/ + +class Projector { + private state : any = { dir : true, digital : false }; + private arduino : Arduino = null; + //private dig : Digital = null; + private log : any; + private cfg : any; + private ui : any; + private ipc : any; + private dig : any; + + /** + * + **/ + constructor (arduino : Arduino, cfg : any, ui : any, dig : any) { + this.arduino = arduino; + this.cfg = cfg; + this.ui = ui; + this.dig = dig; + this.init(); + } + + /** + * + **/ + async init () { + this.log = await require('log')({}) + this.ipc = require('electron').ipcMain; + this.listen(); + } + + /** + * + **/ + private listen () { + this.ipc.on('proj', this.listener.bind(this)); + this.ipc.on('digital', this.connectDigital.bind(this)); + } + + /** + * + **/ + async set (dir : boolean, id : string) { + let cmd : string; + let ms : number; + if (dir) { + cmd = this.cfg.arduino.cmd.proj_forward + } else { + cmd = this.cfg.arduino.cmd.proj_backward + } + this.state.dir = dir + if (this.state.digital) { + //this.dig.set(dir) + } else { + try { + ms = await this.arduino.send('projector', cmd) + } catch (err) { + this.log.error('Error setting projector direction', err) + } + } + return await this.end(cmd, id, ms) + } + + /** + * + **/ + async move (frame : any, id : string) { + const cmd : string = this.cfg.arduino.cmd.projector; + let ms : number; + if (this.state.digital) { + try { + //ms = await this.dig.move() + } catch (err) { + this.log.error(err) + } + } else { + try { + ms = await this.arduino.send('projector', cmd) + } catch (err) { + this.log.error('Error moving projector', err) + } + } + this.log.info('Projector move time', { ms }); + return await this.end(this.cfg.arduino.cmd.projector, id, ms) + } + + /** + * + **/ + private async listener (event : any, arg : any){ + if (typeof arg.dir !== 'undefined') { + try { + await this.set(arg.dir, arg.id) + } catch (err) { + this.log.error(err) + } + } else if (typeof arg.frame !== 'undefined') { + try { + await this.move(arg.frame, arg.id) + } catch (err) { + this.log.error(err) + } + } else if (typeof arg.val !== 'undefined') { + this.dig.state.frame = arg.val + } + event.returnValue = true + } + + /** + * + **/ + async end (cmd : string, id : string, ms : number) { + let message : string = ''; + if (cmd === this.cfg.arduino.cmd.proj_forward) { + message = 'Projector set to FORWARD' + } else if (cmd === this.cfg.arduino.cmd.proj_backward) { + message = 'Projector set to BACKWARD' + } else if (cmd === this.cfg.arduino.cmd.projector) { + message = 'Projector ' + if (this.state.dir) { + message += 'ADVANCED' + } else { + message += 'REWOUND' + } + message += ' 1 frame' + } + this.log.info(message, 'PROJECTOR') + return await this.ui.send('proj', {cmd: cmd, id : id, ms: ms}) + } + + /** + * Use a file as the "digital" source on "projector" + * + **/ + async connectDigital (evt : any, arg : any) { + let info; + let frames = 0; + + try { + info = await this.dig.ffprobe.info(arg.path); + } catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid : false }); + return false; + } + try { + frames = await this.dig.ffprobe.frames(arg.path); + } catch (err) { + this.log.error(err, 'DIGITAL', true, true); + this.state.digital = false; + await this.ui.send('digital', { valid : false }); + return false; + } + + this.dig.state.frame = 0; + this.dig.state.path = arg.path; + this.dig.state.fileName = arg.fileName; + this.dig.state.frames = frames; + this.dig.state.info = info; + + this.log.info(`Opened ${this.dig.state.fileName}`, 'DIGITAL', true, true); + this.log.info(`Frames : ${frames}`, 'DIGITAL', true, true); + this.state.digital = true; + return await this.ui.send('digital', { valid : true, state : JSON.stringify(this.dig.state) }); + } +} + +module.exports = function (arduino : Arduino, cfg : any, ui : any, dig : any) { + return new Projector(arduino, cfg, ui, dig); +} \ No newline at end of file