Incredibly close to #80 and #81. Can get state confirmation at startup. Can send exposure string and get confirmation after. Cannot get state outside of initial confirmation. Something is either locked or failing to wait?

This commit is contained in:
Matt McWilliams 2023-07-10 22:33:16 -04:00
parent 5133295f38
commit 0cc167b3a6
16 changed files with 132 additions and 52 deletions

View File

@ -693,6 +693,9 @@ button:focus {
#settings > div.right .cam_time { #settings > div.right .cam_time {
height: 111px; height: 111px;
} }
#settings > div.right > div {
width: 270px;
}
#settings > div > div { #settings > div > div {
width: 360px; width: 360px;
} }
@ -745,8 +748,9 @@ button:focus {
width: 200px; width: 200px;
} }
#settings button { #settings button {
margin-top: -1px; margin-top: 0px;
float: right; float: right;
padding: 8px 16px 9px;
} }
#settings input[type=radio] { #settings input[type=radio] {
float: right; float: right;

View File

@ -462,10 +462,12 @@
<div class="proj_time"> <div class="proj_time">
<h4>Projector Time (ms)</h4> <h4>Projector Time (ms)</h4>
<input type="number" readonly id="proj_time" value="0" /> <input type="number" readonly id="proj_time" value="0" />
<button id="submit_proj_time" class="hide"></button>
</div> </div>
<div class="cam_time"> <div class="cam_time">
<h4>Camera Time (ms)</h4> <h4>Camera Time (ms)</h4>
<input type="number" readonly id="cam_time" value="0" /> <input type="number" readonly id="cam_time" value="0" />
<button id="submit_cam_time" class="hide" onclick="cam.exposure($('#cam_time').val());"></button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -27,6 +27,9 @@
.cam_time{ .cam_time{
height: 111px; height: 111px;
} }
& > div {
width: 270px;
}
} }
} }
> div > div{ > div > div{
@ -49,8 +52,9 @@
width: 200px; width: 200px;
} }
button{ button{
margin-top: -1px; margin-top: 0px;
float: right; float: right;
padding: 8px 16px 9px;
} }
input[type=radio]{ input[type=radio]{
float: right; float: right;

View File

@ -30,7 +30,7 @@ class Arduino {
this.known = KNOWN; this.known = KNOWN;
this.alias = {}; this.alias = {};
this.serial = { connect: {}, projector: {}, camera: {}, light: {} }; this.serial = { connect: {}, projector: {}, camera: {}, light: {} };
this.hasState = { projector: false, camera: false, light: false }; this.hasState = {};
this.baud = 57600; this.baud = 57600;
this.queue = {}; this.queue = {};
this.timer = 0; this.timer = 0;
@ -93,7 +93,7 @@ class Arduino {
**/ **/
async sendAsync(device, cmd) { async sendAsync(device, cmd) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
//this.log.info(`${device} -> ${cmd}`) this.log.info(`${device} -> ${cmd}`);
this.queue[cmd] = (ms) => { this.queue[cmd] = (ms) => {
return resolve(ms); return resolve(ms);
}; };
@ -108,8 +108,9 @@ class Arduino {
async send(serial, cmd) { async send(serial, cmd) {
const device = this.alias[serial]; const device = this.alias[serial];
let results; let results;
//this.log.info(`${cmd} -> ${serial}`) this.log.info(`${cmd} -> ${serial}`);
if (this.locks[serial]) { if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`);
return false; return false;
} }
this.timer = new Date().getTime(); this.timer = new Date().getTime();
@ -175,6 +176,8 @@ class Arduino {
async state(serial, confirm = false) { async state(serial, confirm = false) {
const device = confirm ? this.alias['connect'] : this.alias[serial]; const device = confirm ? this.alias['connect'] : this.alias[serial];
let results; let results;
this.log.info(serial);
this.log.info(device);
if (this.locks[serial]) { if (this.locks[serial]) {
return null; return null;
} }
@ -221,7 +224,7 @@ class Arduino {
delete this.queue[data]; delete this.queue[data];
} }
else if (data[0] === cfg.arduino.cmd.state) { else if (data[0] === cfg.arduino.cmd.state) {
complete = this.queue[cfg.arduino.cmd.state](ms); complete = this.queue[cfg.arduino.cmd.state](data);
delete this.queue[cfg.arduino.cmd.state]; delete this.queue[cfg.arduino.cmd.state];
return data; return data;
} }
@ -278,7 +281,6 @@ class Arduino {
}); });
} }
confirmEnd(data) { confirmEnd(data) {
this.log.info(data);
if (data === cfg.arduino.cmd.connect if (data === cfg.arduino.cmd.connect
|| data === cfg.arduino.cmd.projector_identifier || data === cfg.arduino.cmd.projector_identifier
|| data === cfg.arduino.cmd.camera_identifier || data === cfg.arduino.cmd.camera_identifier
@ -306,7 +308,7 @@ class Arduino {
this.confirmExec = {}; this.confirmExec = {};
} }
else if (data[0] === cfg.arduino.cmd.state) { else if (data[0] === cfg.arduino.cmd.state) {
this.queue[cfg.arduino.cmd.state](0); this.queue[cfg.arduino.cmd.state](data);
delete this.queue[cfg.arduino.cmd.state]; delete this.queue[cfg.arduino.cmd.state];
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -161,28 +161,43 @@ class Camera {
async exposure(exposure, id) { async exposure(exposure, id) {
const cmd = this.cfg.arduino.cmd.camera_exposure; const cmd = this.cfg.arduino.cmd.camera_exposure;
const str = `${exposure}`; const str = `${exposure}`;
const started = +new Date();
let ms; let ms;
let confirmState;
if (this.intval) { if (this.intval) {
return this.intval.setExposure(this.id, exposure, (ms) => { return this.intval.setExposure(this.id, exposure, (ms) => {
return this.end(cmd, id, ms); return this.end(cmd, id, ms);
}); });
} }
else if (this.arduino.hasState[id]) { else if (this.arduino.hasState[this.id]) {
this.log.info(`Sending cmd ${cmd}`);
try { try {
ms = await this.arduino.send(this.id, cmd); ms = this.arduino.send(this.id, cmd);
} }
catch (err) { catch (err) {
this.log.error('Error sending camera exposure command', err); this.log.error('Error sending camera exposure command', err);
} }
await delay_1.delay(1); await delay_1.delay(1);
this.log.info(`Sending str ${str}`);
try { try {
this.arduino.sendString(this.id, str); ms = await this.arduino.sendString(this.id, str);
} }
catch (err) { catch (err) {
this.log.error('Error sending camera exposure string', err); this.log.error('Error sending camera exposure string', err);
} }
await delay_1.delay(1); this.log.info(`Sent str ${str}`);
await ms; await ms;
this.log.info(`Sent cmd ${cmd}`);
await delay_1.delay(1);
this.log.info(`Sending state request`);
try {
confirmState = await this.arduino.state(this.id, false);
}
catch (err) {
this.log.error(`Error confirming set state`, err);
}
console.dir(confirmState);
ms = (+new Date()) - started;
return await this.end(cmd, id, ms); return await this.end(cmd, id, ms);
} }
return 0; return 0;
@ -256,6 +271,14 @@ class Camera {
this.log.error(err); this.log.error(err);
} }
} }
else if (typeof arg.exposure !== 'undefined') {
try {
await this.exposure(arg.exposure, arg.id);
}
catch (err) {
this.log.error(err);
}
}
event.returnValue = true; event.returnValue = true;
} }
/** /**

File diff suppressed because one or more lines are too long

View File

@ -134,6 +134,9 @@ class Devices {
catch (err) { catch (err) {
this.log.error('Error checking state capability', err); this.log.error('Error checking state capability', err);
} }
if (this.arduino.hasState[device.toString()]) {
this.arduino.hasState[type] = true;
}
return type; return type;
} }
/** /**
@ -471,10 +474,17 @@ class Devices {
if (!this.connected.projector) { if (!this.connected.projector) {
await this.fakeProjector(); await this.fakeProjector();
} }
else if (this.arduino.hasState['projector']) {
p.state = true;
}
p.arduino = this.connected.projector; p.arduino = this.connected.projector;
if (!this.connected.camera) { if (!this.connected.camera) {
await this.fakeCamera(); await this.fakeCamera();
} }
else if (this.arduino.hasState['camera']) {
c.state = true;
c.exposure = true;
}
c.arduino = this.connected.camera; c.arduino = this.connected.camera;
if (!this.connected.light) { if (!this.connected.light) {
await this.fakeLight(); await this.fakeLight();

File diff suppressed because one or more lines are too long

View File

@ -81,7 +81,7 @@ cam.end = function (c, id, ms) {
gui.counterUpdate('cam2', cam.second.pos); gui.counterUpdate('cam2', cam.second.pos);
} }
timing.update(c, ms); timing.update(c, ms);
gui.counterUpdate('cam', cam.pos) gui.counterUpdate('cam', cam.pos);
if (typeof cam.queue[id] !== 'undefined') { if (typeof cam.queue[id] !== 'undefined') {
if (typeof cam.queue[id].callback !== 'undefined') { if (typeof cam.queue[id].callback !== 'undefined') {
cam.queue[id].callback(ms); cam.queue[id].callback(ms);
@ -91,15 +91,13 @@ cam.end = function (c, id, ms) {
} }
}; };
cam.exposure = function (exposure, callback) { cam.exposure = function (exposure) {
var obj = { var obj = {
id : uuid(), id : uuid(),
exposure exposure
} };
ipcRenderer.sendSync(cam.id) log.info(`Setting exposure: ${exposure}`);
if (typeof callback !== 'undefined') { ipcRenderer.sendSync(cam.id, obj);
callback();
}
} }
cam.listen = function () { cam.listen = function () {

View File

@ -33,14 +33,9 @@ class Devices {
let devs = []; let devs = [];
let notify = 'Connected to '; let notify = 'Connected to ';
let p; let p;
//@ts-ignore if (arg.camera && arg.camera.exposure) {
yield delay(1000); $('#submit_cam_time').removeClass('hide');
try { $('#cam_time').removeAttr('readonly');
gui.spinner(false);
gui.overlay(false);
}
catch (err) {
log.error(err);
} }
for (let i in arg) { for (let i in arg) {
devs.push(arg[i].arduino); devs.push(arg[i].arduino);
@ -106,6 +101,15 @@ class Devices {
grid.state(0); grid.state(0);
grid.state(1); grid.state(1);
seq.stats(); seq.stats();
//@ts-ignore
yield delay(1000);
try {
gui.spinner(false);
gui.overlay(false);
}
catch (err) {
log.error(err);
}
return event.returnValue = true; return event.returnValue = true;
}); });
} }

File diff suppressed because one or more lines are too long

View File

@ -28,15 +28,12 @@ class Devices {
let devs : any[] = []; let devs : any[] = [];
let notify : string = 'Connected to '; let notify : string = 'Connected to ';
let p : any; let p : any;
//@ts-ignore
await delay(1000);
try { if (arg.camera && arg.camera.exposure) {
gui.spinner(false); $('#submit_cam_time').removeClass('hide');
gui.overlay(false); $('#cam_time').removeAttr('readonly');
} catch (err) {
log.error(err);
} }
for (let i in arg) { for (let i in arg) {
devs.push(arg[i].arduino); devs.push(arg[i].arduino);
if (arg[i].arduino && arg[i].arduino !== '/dev/fake') { if (arg[i].arduino && arg[i].arduino !== '/dev/fake') {
@ -56,7 +53,7 @@ class Devices {
if (notify !== 'Connected to ') { if (notify !== 'Connected to ') {
gui.notify('DEVICES', notify); gui.notify('DEVICES', notify);
} else { } else {
gui.notify('DEVICES', 'Connected to mock devices') gui.notify('DEVICES', 'Connected to mock devices');
} }
if (devs.length > 0) { if (devs.length > 0) {
@ -104,12 +101,22 @@ class Devices {
grid.state(1); grid.state(1);
seq.stats(); seq.stats();
//@ts-ignore
await delay(1000);
try {
gui.spinner(false);
gui.overlay(false);
} catch (err) {
log.error(err);
}
return event.returnValue = true; return event.returnValue = true;
} }
profiles () { profiles () {
const keys : string[] = Object.keys(cfg.profiles); const keys : string[] = Object.keys(cfg.profiles);
const elem : any = $('#profile') const elem : any = $('#profile');
let opt; let opt;
elem.empty(); elem.empty();
for (let key of keys) { for (let key of keys) {

View File

@ -37,7 +37,7 @@ class Arduino {
private known : string[] = KNOWN; private known : string[] = KNOWN;
private alias : any = {}; private alias : any = {};
private serial : any = { connect : {}, projector : {}, camera : {}, light : {} }; private serial : any = { connect : {}, projector : {}, camera : {}, light : {} };
private hasState : any = { projector : false, camera : false, light : false }; private hasState : any = { };
private baud : number = 57600; private baud : number = 57600;
private queue : any = {}; private queue : any = {};
private timer : number = 0; private timer : number = 0;
@ -101,7 +101,7 @@ class Arduino {
**/ **/
async sendAsync (device : string, cmd : string) { async sendAsync (device : string, cmd : string) {
return new Promise ((resolve, reject) => { return new Promise ((resolve, reject) => {
//this.log.info(`${device} -> ${cmd}`) this.log.info(`${device} -> ${cmd}`)
this.queue[cmd] = (ms : number) => { this.queue[cmd] = (ms : number) => {
return resolve(ms) return resolve(ms)
} }
@ -117,8 +117,9 @@ class Arduino {
async send (serial : string, cmd : string) { async send (serial : string, cmd : string) {
const device : any = this.alias[serial] const device : any = this.alias[serial]
let results : any let results : any
//this.log.info(`${cmd} -> ${serial}`) this.log.info(`${cmd} -> ${serial}`)
if (this.locks[serial]) { if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`)
return false return false
} }
this.timer = new Date().getTime() this.timer = new Date().getTime()
@ -185,7 +186,8 @@ class Arduino {
async state (serial : string, confirm : boolean = false) : Promise<string>{ async state (serial : string, confirm : boolean = false) : Promise<string>{
const device : string = confirm ? this.alias['connect'] : this.alias[serial] const device : string = confirm ? this.alias['connect'] : this.alias[serial]
let results : string let results : string
this.log.info(serial)
this.log.info(device)
if (this.locks[serial]) { if (this.locks[serial]) {
return null return null
} }
@ -233,7 +235,7 @@ class Arduino {
eventEmitter.emit('arduino_end', data) eventEmitter.emit('arduino_end', data)
delete this.queue[data] delete this.queue[data]
} else if (data[0] === cfg.arduino.cmd.state) { } else if (data[0] === cfg.arduino.cmd.state) {
complete = this.queue[cfg.arduino.cmd.state](ms) complete = this.queue[cfg.arduino.cmd.state](data)
delete this.queue[cfg.arduino.cmd.state] delete this.queue[cfg.arduino.cmd.state]
return data return data
} else if (data[0] === cfg.arduino.cmd.error) { } else if (data[0] === cfg.arduino.cmd.error) {
@ -291,7 +293,6 @@ class Arduino {
} }
confirmEnd (data : string) { confirmEnd (data : string) {
this.log.info(data)
if ( data === cfg.arduino.cmd.connect if ( data === cfg.arduino.cmd.connect
|| data === cfg.arduino.cmd.projector_identifier || data === cfg.arduino.cmd.projector_identifier
|| data === cfg.arduino.cmd.camera_identifier || data === cfg.arduino.cmd.camera_identifier
@ -322,7 +323,7 @@ class Arduino {
this.confirmExec(null, data) this.confirmExec(null, data)
this.confirmExec = {} this.confirmExec = {}
} else if (data[0] === cfg.arduino.cmd.state) { } else if (data[0] === cfg.arduino.cmd.state) {
this.queue[cfg.arduino.cmd.state](0) this.queue[cfg.arduino.cmd.state](data)
delete this.queue[cfg.arduino.cmd.state] delete this.queue[cfg.arduino.cmd.state]
} }
} }

View File

@ -164,25 +164,41 @@ class Camera {
public async exposure (exposure : number, id : string) { public async exposure (exposure : number, id : string) {
const cmd : string = this.cfg.arduino.cmd.camera_exposure; const cmd : string = this.cfg.arduino.cmd.camera_exposure;
const str : string = `${exposure}`; const str : string = `${exposure}`;
const started : number = +new Date();
let ms : any; let ms : any;
let confirmState : any;
if (this.intval) { if (this.intval) {
return this.intval.setExposure(this.id, exposure, (ms : number) => { return this.intval.setExposure(this.id, exposure, (ms : number) => {
return this.end(cmd, id, ms); return this.end(cmd, id, ms);
}); });
} else if (this.arduino.hasState[id]) { } else if (this.arduino.hasState[this.id]) {
this.log.info(`Sending cmd ${cmd}`);
try { try {
ms = await this.arduino.send(this.id, cmd); ms = this.arduino.send(this.id, cmd);
} catch (err) { } catch (err) {
this.log.error('Error sending camera exposure command', err); this.log.error('Error sending camera exposure command', err);
} }
await delay(1); await delay(1);
this.log.info(`Sending str ${str}`);
try { try {
this.arduino.sendString(this.id, str); ms = await this.arduino.sendString(this.id, str);
} catch (err) { } catch (err) {
this.log.error('Error sending camera exposure string', err); this.log.error('Error sending camera exposure string', err);
} }
await delay(1); this.log.info(`Sent str ${str}`);
await ms; await ms;
this.log.info(`Sent cmd ${cmd}`);
await delay(1);
this.log.info(`Sending state request`);
try {
confirmState = await this.arduino.state(this.id, false);
} catch (err) {
this.log.error(`Error confirming set state`, err);
}
console.dir(confirmState);
ms = (+new Date()) - started;
return await this.end(cmd, id, ms); return await this.end(cmd, id, ms);
} }
return 0; return 0;

View File

@ -151,6 +151,10 @@ class Devices {
this.log.error('Error checking state capability', err) this.log.error('Error checking state capability', err)
} }
if (this.arduino.hasState[device.toString()]) {
this.arduino.hasState[type] = true;
}
return type return type
} }
/** /**
@ -458,11 +462,16 @@ class Devices {
if (!this.connected.projector) { if (!this.connected.projector) {
await this.fakeProjector() await this.fakeProjector()
} else if (this.arduino.hasState['projector']) {
p.state = true
} }
p.arduino = this.connected.projector p.arduino = this.connected.projector
if (!this.connected.camera) { if (!this.connected.camera) {
await this.fakeCamera() await this.fakeCamera()
} else if (this.arduino.hasState['camera']) {
c.state = true
c.exposure = true
} }
c.arduino = this.connected.camera c.arduino = this.connected.camera