Update commands

This commit is contained in:
Matt McWilliams 2023-03-18 17:00:13 -04:00
parent fbe954280f
commit 174b900cd8
4 changed files with 302 additions and 267 deletions

View File

@ -186,7 +186,10 @@
"capper_on": "A", "capper_on": "A",
"capper_off": "B", "capper_off": "B",
"takeup_forward": "D", "takeup_forward": "D",
"takeup_backward": "E" "takeup_backward": "F",
"error" : "E",
"camera_exposure" : "G",
"state" : "H"
} }
} }
} }

View File

@ -1,267 +1,293 @@
/* jslint esversion: 6*/ /* jslint esversion: 6*/
'use strict';
const gui = {}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
//GUI return new (P || (P = Promise))(function (resolve, reject) {
gui.init = function () { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
gui.version(); function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}; };
let gui;
gui.fmtZero = function (val, len) { class GUI {
'use strict'; constructor() {
const raw = val; this.id = 'gui';
let str = val + ''; this.notifierWorking = true;
let output = ''; this.spinnerCfg = {
if (raw < 0) { lines: 11,
output = '-' + Array(len - (str.length - 1)).join('0') + str.replace('-', ''); length: 15,
} else { width: 7,
if (str.length < len) { radius: 20,
output = Array(len - str.length).join('0') + str; corners: 1,
} else if (str.length >= len) { rotate: 0,
str = parseInt(str) + ''; direction: 1,
output = Array(len - str.length).join('0') + str; color: '#F2F2F1',
} speed: 1,
} trail: 60,
return output; shadow: true,
}; hwaccel: true,
gui.counterFormat = function (t, normal, prevent) { className: 'spinner',
'use strict'; zIndex: 2e9,
const raw = t.value; top: '50%',
t.value = gui.fmtZero(raw, 6); left: '50%' // Left position relative to parent
if (typeof normal !== 'undefined' && parseInt(raw) !== normal) { };
$(t).addClass('changed'); }
} else { init() {
$(t).removeClass('changed'); this.version();
} this.listen();
}; }
gui.counterUpdate = function (which, raw) { listen() {
'use strict'; ipcRenderer.on(this.id, this.listener.bind(this));
const formattedVal = gui.fmtZero(raw, 6); }
$(`.${which} .count`).val(formattedVal); listener(event, arg) {
}; if (arg.notify) {
gui.notifierWorking = true; this.notify(arg.notify.title, arg.notify.message);
gui.notify = function (title, message) { }
'use strict'; }
if (!gui.notifierWorking) { fmtZero(val, len) {
return true; const raw = val;
} let str = val + '';
return new Promise((resolve, reject) => { let output = '';
try { if (raw < 0) {
notifier.notify({ output = '-' + Array(len - (str.length - 1)).join('0') + str.replace('-', '');
title: title, }
message: message, else {
//icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons) if (str.length < len) {
sound: true, // Only Notification Center or Windows Toasters output = Array(len - str.length).join('0') + str;
wait: true // Wait with callback, until user action is taken against notification }
}, function (err, response) { else if (str.length >= len) {
// Response is response from notification str = parseInt(str) + '';
if (err) { output = Array(len - str.length).join('0') + str;
gui.notifierWorking = false; }
log.error(`Error with notification`, err); }
return reject(err); return output;
} }
return resolve(true); counterFormat(t, normal = null) {
}); const raw = t.value;
} catch (err) { t.value = gui.fmtZero(raw, 6);
gui.notifierWorking = false; if (typeof normal !== 'undefined' && parseInt(raw) !== normal) {
//notify-send is not found $(t).addClass('changed');
//determine an alternate for raspian }
//this feels like a hack else {
} $(t).removeClass('changed');
}); }
}; }
gui.updateCam = async function (t) { counterUpdate(which, raw) {
'use strict'; const formattedVal = this.fmtZero(raw, 6);
const val = t.value; $(`.${which} .count`).val(formattedVal);
let change; }
notify(title, message) {
if (parseInt(val) === cam.pos) { const config = {
return false; title,
} message,
change = await gui.confirm(`Are you sure you want to set camera counter to ${val}?`); //icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
sound: true,
if (change) { wait: true // Wait with callback, until user action is taken against notification
cam.pos = parseInt(val); };
gui.updateState(); if (!this.notifierWorking) {
} else { return new Promise((resolve, reject) => { return resolve(true); });
t.value = cam.pos; }
gui.counterFormat(t); return new Promise((resolve, reject) => {
} try {
}; notifier.notify(config, function (err, response) {
gui.updateCam2 = async function (t) { // Response is response from notification
'use strict'; if (err) {
const val = t.value; this.notifierWorking = false;
let change; log.error(`Error with notification`, err);
return reject(err);
if (parseInt(val) === cam.pos) { }
return false; return resolve(true);
} }.bind(this));
change = await gui.confirm(`Are you sure you want to set second camera counter to ${val}?`); }
catch (err) {
if (change) { this.notifierWorking = false;
cam.second.pos = parseInt(val); //notify-send is not found
gui.updateState(); //determine an alternate for raspian
} else { //this feels like a hack
t.value = cam.second.pos; }
gui.counterFormat(t); });
} }
}; updateCam(t) {
gui.updateProj = async function (t) { return __awaiter(this, void 0, void 0, function* () {
'use strict'; const val = t.value;
const val = t.value; let change;
let change; if (parseInt(val) === cam.pos) {
if (parseInt(val) === proj.pos) { return false;
return false; }
} change = yield this.confirm(`Are you sure you want to set camera counter to ${val}?`);
change = await gui.confirm(`Are you sure you want to set projector counter to ${val}?`); if (change) {
if (change) { cam.pos = parseInt(val);
proj.pos = parseInt(val); this.updateState();
gui.updateState(); }
} else { else {
t.value = proj.pos; t.value = cam.pos;
gui.counterFormat(t); this.counterFormat(t);
} }
proj.setValue(t.value); });
}; }
gui.updateProj2 = async function (t) { updateCam2(t) {
'use strict'; return __awaiter(this, void 0, void 0, function* () {
const val = t.value; const val = t.value;
let change; let change;
if (parseInt(val) === proj.second.pos) { if (parseInt(val) === cam.pos) {
return false; return false;
} }
change = await gui.confirm(`Are you sure you want to set second projector counter to ${val}?`); change = yield this.confirm(`Are you sure you want to set second camera counter to ${val}?`);
if (change) { if (change) {
proj.second.pos = parseInt(val); cam.second.pos = parseInt(val);
gui.updateState(); this.updateState();
} else { }
t.value = proj.second.pos; else {
gui.counterFormat(t); t.value = cam.second.pos;
} this.counterFormat(t);
proj.setValue(t.value); }
}; });
}
gui.updateState = function () { updateProj(t) {
'use strict'; return __awaiter(this, void 0, void 0, function* () {
const cpos = cam.pos; const val = t.value;
const ppos = proj.pos; let change;
if (parseInt(val) === proj.pos) {
const p2pos = proj.second.pos; return false;
const c2pos = cam.second.pos; }
change = yield this.confirm(`Are you sure you want to set projector counter to ${val}?`);
$('#seq_cam_count').val(cpos).change(); if (change) {
$('#seq_proj_count').val(ppos).change(); proj.pos = parseInt(val);
this.updateState();
$('#seq_cam_count_2').val(cpos).change(); }
$('#seq_proj_count_2').val(ppos).change(); else {
t.value = proj.pos;
$('#seq_cam_2_count').val(c2pos).change(); this.counterFormat(t);
$('#seq_proj_2_count').val(p2pos).change(); }
proj.setValue(t.value);
$('#seq_cam_2_count_2').val(c2pos).change(); });
$('#seq_proj_2_count_2').val(p2pos).change(); }
}; updateProj2(t) {
gui.spinnerCfg = { return __awaiter(this, void 0, void 0, function* () {
lines: 11, // The number of lines to draw const val = t.value;
length: 15, // The length of each line let change;
width: 7, // The line thickness if (parseInt(val) === proj.second.pos) {
radius: 20, // The radius of the inner circle return false;
corners: 1, // Corner roundness (0..1) }
rotate: 0, // The rotation offset change = yield this.confirm(`Are you sure you want to set second projector counter to ${val}?`);
direction: 1, // 1: clockwise, -1: counterclockwise if (change) {
color: '#F2F2F1', // #rgb or #rrggbb or array of colors proj.second.pos = parseInt(val);
speed: 1, // Rounds per second this.updateState();
trail: 60, // Afterglow percentage }
shadow: true, // Whether to render a shadow else {
hwaccel: true, // Whether to use hardware acceleration t.value = proj.second.pos;
className: 'spinner', // The CSS class to assign to the spinner this.counterFormat(t);
zIndex: 2e9, // The z-index (defaults to 2000000000) }
top: '50%', // Top position relative to parent proj.setValue(t.value);
left: '50%' // Left position relative to parent });
}; }
gui.spinner = function (state, msg, progress, cancel) { updateState() {
'use strict'; const cpos = cam.pos;
let target; const ppos = proj.pos;
let spinner; const p2pos = proj.second.pos;
if (msg && msg !== '') { const c2pos = cam.second.pos;
gui.spinnerMsg(msg); $('#seq_cam_count').val(cpos).change();
} $('#seq_proj_count').val(ppos).change();
if (state && !$('#spinner').hasClass('created')) { $('#seq_cam_count_2').val(cpos).change();
target = document.getElementById('spinner'); $('#seq_proj_count_2').val(ppos).change();
spinner = new Spinner(gui.spinnerCfg).spin(target); $('#seq_cam_2_count').val(c2pos).change();
$('#spinnerProgress').hide(); $('#seq_proj_2_count').val(p2pos).change();
$('#spinner').addClass('created'); $('#seq_cam_2_count_2').val(c2pos).change();
} else if (state) { $('#seq_proj_2_count_2').val(p2pos).change();
$('#spinner').show(); }
} else if (!state) { spinner(state, msg = null, progress = false, cancel = false) {
$('#spinner').hide(); let target;
gui.spinnerMsg(''); let spinner;
} if (msg && msg !== '') {
if (progress) { this.spinnerMsg(msg);
$('#spinnerProgress').show(); }
} else { if (state && !$('#spinner').hasClass('created')) {
$('#spinnerProgress').hide(); target = document.getElementById('spinner');
} spinner = new Spinner(this.spinnerCfg).spin(target);
if (cancel) { $('#spinnerProgress').hide();
$('#spinnerCancel').show(); $('#spinner').addClass('created');
} else { }
$('#spinnerCancel').hide(); else if (state) {
} $('#spinner').show();
}; }
gui.spinnerMsg = function (msg) { else if (!state) {
'use strict'; $('#spinner').hide();
$('#spinnerMsg').text(msg); this.spinnerMsg('');
}; }
gui.overlay = function (state) { if (progress) {
'use strict'; $('#spinnerProgress').show();
if (state) { }
$('#overlay').show(); else {
} else { $('#spinnerProgress').hide();
$('#overlay').hide(); }
} if (cancel) {
}; $('#spinnerCancel').show();
}
gui.info = async function (title, message) { else {
'use strict'; $('#spinnerCancel').hide();
const config = { }
type : 'info', }
buttons : ['Ok'], spinnerMsg(msg) {
title: title, $('#spinnerMsg').text(msg);
message : message }
}; overlay(state) {
return dialog.showMessageBox(config); if (state) {
}; $('#overlay').show();
gui.confirm = async function (message, cancel = 'Cancel') { }
const config = { else {
buttons : ['Yes', cancel], $('#overlay').hide();
message }
} }
const res = await dialog.showMessageBox(config); info(title, message) {
return res.response === 0; return __awaiter(this, void 0, void 0, function* () {
}; const config = {
gui.choice = async function (message, choices) { type: 'info',
const config = { buttons: ['Ok'],
buttons : choices, title: title,
defaultId : 0, message: message
message };
} return dialog.showMessageBox(config);
const res = await dialog.showMessageBox(config); });
return res.response; }
}; confirm(message, cancel = 'Cancel') {
gui.warn = async function (title, message) { return __awaiter(this, void 0, void 0, function* () {
'use strict'; const config = {
const config = { buttons: ['Yes', cancel],
type : 'warning', message
buttons : ['Ok'], };
title: title, const res = yield dialog.showMessageBox(config);
message : message return res.response === 0;
}; });
return dialog.showMessageBox(config); }
}; choice(message, choices) {
gui.error = function () {}; return __awaiter(this, void 0, void 0, function* () {
const config = {
gui.version = function () { buttons: choices,
$('#version').text(PACKAGE.version); defaultId: 0,
message
};
const res = yield dialog.showMessageBox(config);
return res.response;
});
}
warn(title, message) {
return __awaiter(this, void 0, void 0, function* () {
const config = {
type: 'warning',
buttons: ['Ok'],
title,
message
};
return dialog.showMessageBox(config);
});
}
version() {
$('#version').text(PACKAGE.version);
}
error() {
}
} }
gui = new GUI();
module.exports = gui; module.exports = gui;
//# sourceMappingURL=index.js.map

View File

@ -186,7 +186,10 @@
"capper_on": "A", "capper_on": "A",
"capper_off": "B", "capper_off": "B",
"takeup_forward": "D", "takeup_forward": "D",
"takeup_backward": "E" "takeup_backward": "F",
"error" : "E",
"camera_exposure" : "G",
"state" : "H"
} }
} }
} }

View File

@ -186,7 +186,10 @@
"capper_on": "A", "capper_on": "A",
"capper_off": "B", "capper_off": "B",
"takeup_forward": "D", "takeup_forward": "D",
"takeup_backward": "E" "takeup_backward": "F",
"error" : "E",
"camera_exposure" : "G",
"state" : "H"
} }
} }
} }