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-03-22 01:02:28 +00:00
|
|
|
constructor(arduino, cfg, ui, dig, second = false) {
|
2019-03-21 23:34:56 +00:00
|
|
|
this.state = {
|
|
|
|
pos: 0,
|
|
|
|
dir: true,
|
|
|
|
digital: false
|
|
|
|
};
|
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;
|
|
|
|
this.dig = dig;
|
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-03-21 22:03:53 +00:00
|
|
|
if (this.dig.state.enabled) {
|
|
|
|
this.dig.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
|
|
|
}
|
|
|
|
}
|
|
|
|
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-03-21 22:03:53 +00:00
|
|
|
if (this.dig.state.enabled) {
|
2019-03-21 19:00:47 +00:00
|
|
|
try {
|
2019-03-21 22:03:53 +00:00
|
|
|
ms = await this.dig.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-03-21 19:31:17 +00:00
|
|
|
this.dig.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');
|
2019-03-21 23:34:56 +00:00
|
|
|
return await this.ui.send(this.id, { cmd: cmd, id: id, ms: ms });
|
2019-03-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 22:49:07 +00:00
|
|
|
module.exports = function (arduino, cfg, ui, dig, second) {
|
|
|
|
return new Projector(arduino, cfg, ui, dig, second);
|
2019-03-21 19:00:47 +00:00
|
|
|
};
|
|
|
|
//# sourceMappingURL=index.js.map
|