2019-03-21 22:03:53 +00:00
|
|
|
"use strict";
|
2019-03-21 19:00:47 +00:00
|
|
|
/** class representing the Projector features **/
|
2019-03-21 22:03:53 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const Log = require("log");
|
2019-03-21 19:00:47 +00:00
|
|
|
class Projector {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-18 20:52:26 +00:00
|
|
|
constructor(arduino, cfg, ui, filmout, second = false) {
|
2019-03-21 23:34:56 +00:00
|
|
|
this.state = {
|
|
|
|
pos: 0,
|
2019-06-18 20:52:26 +00:00
|
|
|
dir: true
|
2019-03-21 23:34:56 +00:00
|
|
|
};
|
2019-03-21 19:00:47 +00:00
|
|
|
this.arduino = null;
|
2019-03-21 23:34:56 +00:00
|
|
|
this.id = 'projector';
|
2019-03-21 19:00:47 +00:00
|
|
|
this.arduino = arduino;
|
|
|
|
this.cfg = cfg;
|
|
|
|
this.ui = ui;
|
2019-06-18 20:52:26 +00:00
|
|
|
this.filmout = filmout;
|
2019-03-22 01:02:28 +00:00
|
|
|
if (second)
|
|
|
|
this.id += '_second';
|
2019-03-21 19:00:47 +00:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async init() {
|
2019-03-21 23:45:48 +00:00
|
|
|
this.log = await Log({ label: this.id });
|
2019-03-21 19:00:47 +00:00
|
|
|
this.ipc = require('electron').ipcMain;
|
|
|
|
this.listen();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
listen() {
|
2019-03-21 23:34:56 +00:00
|
|
|
this.ipc.on(this.id, this.listener.bind(this));
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async set(dir, id) {
|
|
|
|
let cmd;
|
|
|
|
let ms;
|
|
|
|
if (dir) {
|
2019-03-22 01:02:28 +00:00
|
|
|
cmd = this.cfg.arduino.cmd[`${this.id}_forward`];
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-22 01:02:28 +00:00
|
|
|
cmd = this.cfg.arduino.cmd[`${this.id}_backward`];
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
this.state.dir = dir;
|
2019-06-18 20:52:26 +00:00
|
|
|
if (this.filmout.state.enabled) {
|
|
|
|
this.filmout.set(dir);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
2019-03-21 23:34:56 +00:00
|
|
|
ms = await this.arduino.send(this.id, cmd);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
2019-03-22 01:02:28 +00:00
|
|
|
this.log.error(`Error setting ${this.id} direction`, err);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-31 02:13:50 +00:00
|
|
|
console.dir(ms);
|
2019-03-21 19:00:47 +00:00
|
|
|
return await this.end(cmd, id, ms);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async move(frame, id) {
|
2019-03-21 23:45:48 +00:00
|
|
|
const cmd = this.cfg.arduino.cmd[this.id];
|
2019-03-21 19:00:47 +00:00
|
|
|
let ms;
|
2019-06-18 20:52:26 +00:00
|
|
|
if (this.filmout.state.enabled) {
|
2019-03-21 19:00:47 +00:00
|
|
|
try {
|
2019-06-18 20:52:26 +00:00
|
|
|
ms = await this.filmout.move();
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
2019-03-21 23:34:56 +00:00
|
|
|
ms = await this.arduino.send(this.id, cmd);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
2019-03-22 01:02:28 +00:00
|
|
|
this.log.error(`Error moving ${this.id}`, err);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 22:49:07 +00:00
|
|
|
//this.log.info('Projector move time', { ms });
|
|
|
|
return await this.end(cmd, id, ms);
|
|
|
|
}
|
|
|
|
async both(frame, id) {
|
2019-04-20 14:15:28 +00:00
|
|
|
const cmd = this.cfg.arduino.cmd[this.id + 's'];
|
2019-04-04 22:49:07 +00:00
|
|
|
let ms;
|
|
|
|
try {
|
|
|
|
ms = await this.arduino.send(this.id, cmd);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(`Error moving ${this.id}`, err);
|
|
|
|
}
|
|
|
|
//this.log.info('Projectors move time', { ms });
|
2019-03-21 23:45:48 +00:00
|
|
|
return await this.end(cmd, id, ms);
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
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') {
|
2019-03-21 23:34:56 +00:00
|
|
|
this.state.pos = arg.val;
|
2019-06-18 20:52:26 +00:00
|
|
|
this.filmout.state.frame = arg.val;
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
event.returnValue = true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async end(cmd, id, ms) {
|
|
|
|
let message = '';
|
2019-03-22 01:02:28 +00:00
|
|
|
if (cmd === this.cfg.arduino.cmd.projector_forward) {
|
2019-03-21 19:00:47 +00:00
|
|
|
message = 'Projector set to FORWARD';
|
|
|
|
}
|
2019-03-22 01:02:28 +00:00
|
|
|
else if (cmd === this.cfg.arduino.cmd.projector_backward) {
|
2019-03-21 19:00:47 +00:00
|
|
|
message = 'Projector set to BACKWARD';
|
|
|
|
}
|
2019-03-22 01:02:28 +00:00
|
|
|
else if (cmd === this.cfg.arduino.cmd.projector_second_forward) {
|
|
|
|
message = 'Projector second set to FORWARD';
|
|
|
|
}
|
|
|
|
else if (cmd === this.cfg.arduino.cmd.projector_second_backward) {
|
|
|
|
message = 'Projector second set to BACKWARD';
|
|
|
|
}
|
2019-03-21 19:00:47 +00:00
|
|
|
else if (cmd === this.cfg.arduino.cmd.projector) {
|
|
|
|
message = 'Projector ';
|
|
|
|
if (this.state.dir) {
|
|
|
|
message += 'ADVANCED';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message += 'REWOUND';
|
|
|
|
}
|
|
|
|
message += ' 1 frame';
|
|
|
|
}
|
2019-03-22 01:02:28 +00:00
|
|
|
else if (cmd === this.cfg.arduino.cmd.projector_second) {
|
2019-04-04 22:49:07 +00:00
|
|
|
message = 'Projector second ';
|
2019-03-22 01:02:28 +00:00
|
|
|
if (this.state.dir) {
|
|
|
|
message += 'ADVANCED';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message += 'REWOUND';
|
|
|
|
}
|
|
|
|
message += ' 1 frame';
|
|
|
|
}
|
2019-04-04 22:49:07 +00:00
|
|
|
else if (cmd === this.cfg.arduino.cmd.projectors) {
|
|
|
|
message += 'Projectors both MOVED 1 frame each';
|
|
|
|
}
|
|
|
|
message += ` ${ms}ms`;
|
2019-03-21 19:00:47 +00:00
|
|
|
this.log.info(message, 'PROJECTOR');
|
2023-07-31 02:13:50 +00:00
|
|
|
return await this.ui.send(this.id, { cmd, id, ms });
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-18 20:52:26 +00:00
|
|
|
module.exports = function (arduino, cfg, ui, filmout, second) {
|
|
|
|
return new Projector(arduino, cfg, ui, filmout, second);
|
2019-03-21 19:00:47 +00:00
|
|
|
};
|
|
|
|
//# sourceMappingURL=index.js.map
|