Work towards issue #52. Adds a statement within the arduino.end() method that watches for an 'E' char byte and will alert the UI while pausing a running sequence. Needs to be in place for firmware to be able to throw errors to UI.

This commit is contained in:
sixteenmillimeter 2020-09-29 13:48:06 -04:00
parent c5d7f9c91f
commit 8672b6584a
11 changed files with 55 additions and 27 deletions

View File

@ -68,6 +68,14 @@ var createWindow = function () {
})
}
var errorState = function () {
if (seq && seq.running) {
//pause sequence if running
seq.pause();
}
mainWindow.webContents.send('error_state', { stop : true });
}
var init = async function () {
log = await require('log')({})
@ -85,7 +93,7 @@ var init = async function () {
display = require('display')(SYSTEM)
ffmpeg = require('ffmpeg')(SYSTEM)
ffprobe = require('ffprobe')(SYSTEM)
arduino = require('arduino')(cfg, ee)
arduino = require('arduino')(cfg, ee, errorState)
dev = require('devices')(arduino, settings, mainWindow)

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.6.5",
"version": "1.6.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.6.5",
"version": "1.6.6",
"description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js",
"scripts": {

View File

@ -19,6 +19,7 @@ class Devices {
listen () {
ipcRenderer.on('ready', this.ready.bind(this));
ipcRenderer.on('intval', this.intvalCb.bind(this));
ipcRenderer.on('error_state', this.errorState.bind(this));
}
async ready (event : any, arg : any) {
@ -172,6 +173,13 @@ class Devices {
$('#intval').removeClass('active');
}
}
errorState () {
gui.spinner(false);
gui.overlay(false);
gui.notify('DEVICES', `Hardware error detected`);
gui.warn('Error', 'Hardware error detected. Please address before continuing.');
}
}
devices = new Devices();

View File

@ -25,7 +25,7 @@ const KNOWN = [
* Class representing the arduino communication features
**/
class Arduino {
constructor() {
constructor(errorState) {
this.path = {};
this.known = KNOWN;
this.alias = {};
@ -35,6 +35,7 @@ class Arduino {
this.timer = 0;
this.lock = false;
this.locks = {};
this.errorState = errorState;
this.init();
}
async init() {
@ -169,6 +170,11 @@ class Arduino {
eventEmitter.emit('arduino_end', data);
delete this.queue[data];
}
else if (data === 'E') {
//error state
//stop sequence
//throw error in ui
}
else {
//console.log('Received stray "' + data + '"'); //silent to user
}
@ -391,10 +397,10 @@ class Arduino {
}
}
if (typeof module !== 'undefined' && module.parent) {
module.exports = function (c, ee) {
module.exports = function (c, ee, errorState) {
eventEmitter = ee;
cfg = c;
arduino = new Arduino();
arduino = new Arduino(errorState);
return arduino;
};
}

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "mcopy-cli",
"version": "1.6.5",
"version": "1.6.6",
"description": "CLI for controlling the mcopy optical printer platform",
"main": "index.js",
"scripts": {

View File

@ -1,5 +1,5 @@
{
"version": "1.6.5",
"version": "1.6.6",
"ext_port": 1111,
"profiles": {
"mcopy": {

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mcopy",
"version": "1.6.5",
"version": "1.6.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "mcopy",
"version": "1.6.5",
"version": "1.6.6",
"description": "Small gauge film optical printer platform",
"main": "build.js",
"directories": {

View File

@ -33,18 +33,20 @@ const KNOWN : string[] = [
class Arduino {
private log : any;
private path : any = {}
private known : string[] = KNOWN
private alias : any = {}
private serial : any = { connect : {}, projector : {}, camera : {}, light : {} }
private baud : number = 57600
private queue : any = {}
private timer : number = 0
private lock : boolean = false
private locks : any = {}
private confirmExec : any
private path : any = {};
private known : string[] = KNOWN;
private alias : any = {};
private serial : any = { connect : {}, projector : {}, camera : {}, light : {} };
private baud : number = 57600;
private queue : any = {};
private timer : number = 0;
private lock : boolean = false;
private locks : any = {};
private confirmExec : any;
private errorState : Function;
constructor () {
constructor (errorState : Function) {
this.errorState = errorState;
this.init()
}
@ -169,14 +171,18 @@ class Arduino {
}
end (serial : string, data : string) {
const end = new Date().getTime();
const ms = end - this.timer;
let complete;
const end : number = new Date().getTime();
const ms : number = end - this.timer;
let complete : any;
if (this.queue[data] !== undefined) {
this.locks[serial] = false;
complete = this.queue[data](ms); //execute callback
eventEmitter.emit('arduino_end', data);
delete this.queue[data];
} else if (data === 'E') {
//error state
//stop sequence
//throw error in ui
} else {
//console.log('Received stray "' + data + '"'); //silent to user
}
@ -397,10 +403,10 @@ class Arduino {
}
if (typeof module !== 'undefined' && module.parent) {
module.exports = function (c : any, ee : any) {
module.exports = function (c : any, ee : any, errorState : Function) {
eventEmitter = ee
cfg = c
arduino = new Arduino()
arduino = new Arduino(errorState)
return arduino
}
}