2022-07-13 19:21:26 +00:00
|
|
|
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2024-05-23 22:49:18 +00:00
|
|
|
exports.Capper = void 0;
|
2024-05-24 00:51:35 +00:00
|
|
|
const electron_1 = require("electron");
|
2024-05-19 22:14:33 +00:00
|
|
|
const log_1 = require("log");
|
2022-07-13 19:21:26 +00:00
|
|
|
/** class representing capper functions **/
|
|
|
|
class Capper {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
constructor(arduino, cfg, ui, filmout) {
|
|
|
|
this.state = {
|
|
|
|
capper: false
|
|
|
|
};
|
|
|
|
this.arduino = null;
|
2024-05-24 00:51:35 +00:00
|
|
|
this.ipc = electron_1.ipcMain;
|
2022-07-13 19:21:26 +00:00
|
|
|
this.id = 'capper';
|
|
|
|
this.arduino = arduino;
|
|
|
|
this.cfg = cfg;
|
|
|
|
this.ui = ui;
|
|
|
|
this.filmout = filmout;
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async init() {
|
2024-05-19 22:14:33 +00:00
|
|
|
this.log = await (0, log_1.Log)({ label: this.id });
|
2022-07-13 19:21:26 +00:00
|
|
|
this.listen();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
listen() {
|
|
|
|
this.ipc.on(this.id, this.listener.bind(this));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async capper(state, id) {
|
|
|
|
let cmd;
|
|
|
|
let ms;
|
|
|
|
if (state) {
|
|
|
|
cmd = this.cfg.arduino.cmd[`${this.id}_on`];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmd = this.cfg.arduino.cmd[`${this.id}_off`];
|
|
|
|
}
|
|
|
|
this.state.capper = state;
|
|
|
|
try {
|
|
|
|
ms = await this.arduino.send(this.id, cmd);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err);
|
|
|
|
}
|
|
|
|
return await this.end(cmd, id, ms);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async listener(event, arg) {
|
2022-07-15 22:11:26 +00:00
|
|
|
if (typeof arg.state !== 'undefined') {
|
2022-07-13 19:21:26 +00:00
|
|
|
try {
|
2022-07-15 22:11:26 +00:00
|
|
|
await this.capper(arg.state, arg.id);
|
2022-07-13 19:21:26 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.returnValue = true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async end(cmd, id, ms) {
|
|
|
|
let message = '';
|
|
|
|
if (cmd === this.cfg.arduino.cmd.capper_on) {
|
|
|
|
message = 'Capper set to ON';
|
|
|
|
}
|
|
|
|
else if (cmd === this.cfg.arduino.cmd.capper_off) {
|
|
|
|
message = 'Capper set to OFF';
|
|
|
|
}
|
|
|
|
message += ` ${ms}ms`;
|
|
|
|
this.log.info(message);
|
2024-05-24 03:36:51 +00:00
|
|
|
await this.ui.send(this.id, { cmd: cmd, id: id, ms: ms });
|
2024-05-23 22:49:18 +00:00
|
|
|
return ms;
|
2022-07-13 19:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-23 22:49:18 +00:00
|
|
|
exports.Capper = Capper;
|
2024-05-24 00:51:35 +00:00
|
|
|
module.exports = { Capper };
|
2022-07-13 19:21:26 +00:00
|
|
|
//# sourceMappingURL=index.js.map
|