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