Resolves #80 and #81. UI will need a little cleanup. There is some string concatenation happening where it shouldn't.

This commit is contained in:
Matt McWilliams 2023-07-30 22:13:50 -04:00
parent 3b03eb70fb
commit dac720863d
18 changed files with 523 additions and 408 deletions

View File

@ -2531,4 +2531,5 @@ async function init () {
seq.init();
capper.init();
alertObj.init();
timing.init();
};

View File

@ -41,13 +41,13 @@ class Arduino {
this.path = {};
this.known = KNOWN;
this.alias = {};
this.serial = { connect: {}, projector: {}, camera: {}, light: {} };
this.serial = {};
this.hasState = {};
this.baud = 57600;
this.queue = {};
this.timer = 0;
this.lock = false;
this.locks = {};
this.stateStr = {};
this.errorState = errorState;
this.init();
}
@ -105,11 +105,12 @@ class Arduino {
**/
async sendAsync(device, cmd) {
return new Promise((resolve, reject) => {
this.log.info(`sendAsyc ${device} -> ${cmd}`);
this.log.info(`sendAsync ${cmd} -> ${device}`);
this.queue[cmd] = (ms) => {
return resolve(ms);
};
return this.serial[device].write(cmd, (err, results) => {
this.log.info(`Device: ${device}`);
return this.serial[this.alias[device]].write(cmd, (err, results) => {
if (err) {
//this.log.error(err)
return reject(err);
@ -120,46 +121,46 @@ class Arduino {
/**
*
**/
async send(serial, cmd) {
const device = this.alias[serial];
let results;
this.log.info(`send ${cmd} -> ${serial}`);
if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`);
return false;
async send(device, cmd) {
const serial = this.alias[device];
let ms;
this.log.info(`send ${cmd} -> ${device}`);
if (this.isLocked(serial)) {
this.log.warn(`send Serial ${serial} is locked`);
return null;
}
this.timer = new Date().getTime();
this.locks[serial] = true;
this.lock(serial);
await delay_1.delay(cfg.arduino.serialDelay);
try {
results = await this.sendAsync(device, cmd);
ms = await this.sendAsync(device, cmd);
}
catch (e) {
return this.log.error(e);
}
this.locks[serial] = false;
this.unlock(serial);
await eventEmitter.emit('arduino_send', cmd);
return results;
return ms;
}
/**
*
**/
async sendString(serial, str) {
const device = this.alias[serial];
async sendString(device, str) {
let writeSuccess;
await delay_1.delay(cfg.arduino.serialDelay);
if (typeof this.serial[device].fake !== 'undefined'
&& this.serial[device].fake) {
return this.serial[device].string(str);
if (typeof this.serial[this.alias[device]].fake !== 'undefined'
&& this.serial[this.alias[device]].fake) {
return this.serial[this.alias[device]].string(str);
}
else {
this.log.info(`sendString ${device} -> ${str}`);
this.log.info(`sendString ${str} -> ${device}`);
try {
writeSuccess = await this.writeAsync(device, str);
}
catch (e) {
return this.log.error(e);
}
this.unlock(this.alias[device]);
return writeSuccess;
}
}
@ -168,8 +169,10 @@ class Arduino {
**/
async stateAsync(device, confirm = false) {
const cmd = cfg.arduino.cmd.state;
const serial = confirm ? this.alias['connect'] : this.alias[device];
return new Promise((resolve, reject) => {
this.queue[cmd] = (state) => {
this.stateStr[device] = state;
if (confirm) {
this.hasState[device] = true;
this.log.info(`Device ${device} supports state [${state}]`);
@ -186,8 +189,8 @@ class Arduino {
}
}.bind(this), 1000);
}
this.log.info(`stateAsync ${device} -> ${cmd}`);
return this.serial[device].write(cmd, (err, results) => {
this.log.info(`stateAsync ${cmd} -> ${device}`);
return this.serial[serial].write(cmd, (err, results) => {
if (err) {
//this.log.error(err)
return reject(err);
@ -201,25 +204,20 @@ class Arduino {
async state(device, confirm = false) {
const serial = confirm ? this.alias['connect'] : this.alias[device];
let results;
this.log.info(`state device ${device}`);
this.log.info(`state serial ${serial}`);
console.dir(this.locks);
if (typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true) {
this.log.info("Serial is locked");
if (this.isLocked(serial)) {
this.log.warn(`state Serial ${serial} is locked`);
return null;
}
this.timer = new Date().getTime();
this.locks[serial] = true;
this.lock(serial);
await delay_1.delay(cfg.arduino.serialDelay);
if (!confirm)
this.log.info("got here");
try {
results = await this.stateAsync(device, confirm);
}
catch (e) {
return this.log.error(e);
}
this.locks[serial] = false;
this.unlock(serial);
await eventEmitter.emit('arduino_state', cfg.arduino.cmd.state);
return results;
}
@ -233,7 +231,7 @@ class Arduino {
**/
async writeAsync(device, str) {
return new Promise((resolve, reject) => {
this.serial[device].write(str, function (err, results) {
this.serial[this.alias[device]].write(str, function (err, results) {
if (err) {
return reject(err);
}
@ -248,16 +246,16 @@ class Arduino {
const end = new Date().getTime();
const ms = end - this.timer;
let complete;
this.log.info(`end ${serial} -> ${data}`);
//this.log.info(`end ${serial} -> ${data}`)
if (this.queue[data] !== undefined) {
this.locks[serial] = false;
this.unlock(serial);
complete = this.queue[data](ms); //execute callback
eventEmitter.emit('arduino_end', data);
delete this.queue[data];
}
else if (data[0] === cfg.arduino.cmd.state) {
this.log.info(`end serial -> ${serial}`);
this.locks[serial] = false;
//this.log.info(`end serial -> ${serial}`)
this.unlock(serial);
complete = this.queue[cfg.arduino.cmd.state](data);
eventEmitter.emit('arduino_end', data);
delete this.queue[cfg.arduino.cmd.state];
@ -265,7 +263,7 @@ class Arduino {
}
else if (data[0] === cfg.arduino.cmd.error) {
this.log.error(`Received error from device ${serial}`);
this.locks[serial] = false;
this.unlock(serial);
//error state
//stop sequence
//throw error in ui
@ -275,24 +273,24 @@ class Arduino {
}
return ms;
}
aliasSerial(serial, device) {
aliasSerial(device, serial) {
//this.log.info(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device;
this.alias[device] = serial;
}
async connect(serial, device, confirm) {
this.log.info(`connect device ${device}`);
this.log.info(`connect serial ${serial}`);
async connect(device, serial, confirm) {
//this.log.info(`connect device ${device}`)
//this.log.info(`connect serial ${serial}`)
return new Promise(async (resolve, reject) => {
let connectSuccess;
this.path[serial] = device;
this.alias[serial] = device;
this.serial[device] = new SerialPort({
path: this.path[serial],
this.path[device] = serial;
this.aliasSerial(device, serial);
this.serial[serial] = new SerialPort({
path: serial,
autoOpen: false,
baudRate: cfg.arduino.baud,
parser
});
this.locks[device] = false;
this.unlock(serial);
try {
connectSuccess = await this.openArduino(device);
}
@ -300,16 +298,16 @@ class Arduino {
this.log.error('failed to open: ' + e);
return reject(e);
}
this.log.info(`Opened connection with ${this.path[serial]} as ${serial}`);
this.log.info(`Opened connection with ${this.path[device]} as ${device}`);
if (!confirm) {
this.serial[device].on('data', async (data) => {
this.serial[this.alias[device]].on('data', async (data) => {
let d = data.toString('utf8');
d = d.replace(newlineRe, '').replace(returnRe, '');
return this.end(serial, d);
});
}
else {
this.serial[device].on('data', async (data) => {
this.serial[this.alias[device]].on('data', async (data) => {
let d = data.toString('utf8');
d = d.replace(newlineRe, '').replace(returnRe, '');
return await this.confirmEnd(d);
@ -344,15 +342,17 @@ class Arduino {
|| data === cfg.arduino.cmd.camera_capper_projectors_identifier) {
this.confirmExec(null, data);
this.confirmExec = {};
this.unlock(this.alias['connect']);
}
else if (data[0] === cfg.arduino.cmd.state) {
this.queue[cfg.arduino.cmd.state](data);
delete this.queue[cfg.arduino.cmd.state];
this.unlock(this.alias['connect']);
}
}
async verify() {
return new Promise(async (resolve, reject) => {
const device = this.alias['connect'];
const device = 'connect';
let writeSuccess;
this.confirmExec = function (err, data) {
if (data === cfg.arduino.cmd.connect) {
@ -374,7 +374,7 @@ class Arduino {
}
async distinguish() {
return new Promise(async (resolve, reject) => {
const device = this.alias['connect'];
const device = 'connect';
let writeSuccess;
let type;
this.confirmExec = function (err, data) {
@ -442,7 +442,7 @@ class Arduino {
});
}
async close() {
const device = this.alias['connect'];
const device = 'connect';
let closeSuccess;
try {
closeSuccess = await this.closeArduino(device);
@ -452,10 +452,10 @@ class Arduino {
}
return closeSuccess;
}
async fakeConnect(serial) {
const device = '/dev/fake';
this.alias[serial] = device;
this.serial[device] = {
async fakeConnect(device) {
const serial = '/dev/fake';
this.aliasSerial(device, serial);
this.serial[serial] = {
write: async function (cmd, cb) {
const t = {
c: cfg.arduino.cam.time + cfg.arduino.cam.delay,
@ -489,7 +489,7 @@ class Arduino {
**/
async openArduino(device) {
return new Promise((resolve, reject) => {
return this.serial[device].open((err) => {
return this.serial[this.alias[device]].open((err) => {
if (err) {
return reject(err);
}
@ -506,7 +506,7 @@ class Arduino {
**/
async closeArduino(device) {
return new Promise((resolve, reject) => {
return this.serial[device].close((err) => {
return this.serial[this.alias[device]].close((err) => {
if (err) {
return reject(err);
}
@ -514,6 +514,17 @@ class Arduino {
});
});
}
lock(serial) {
//this.log.info(`Locked serial ${serial}`)
this.locks[serial] = true;
}
unlock(serial) {
//this.log.info(`Unlocked serial ${serial}`)
this.locks[serial] = false;
}
isLocked(serial) {
return typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true;
}
}
if (typeof module !== 'undefined' && module.parent) {
module.exports = function (c, ee, errorState) {

File diff suppressed because one or more lines are too long

View File

@ -164,13 +164,15 @@ class Camera {
const started = +new Date();
let ms;
let confirmState;
let parts;
let confirmExposure;
if (this.intval) {
return this.intval.setExposure(this.id, exposure, (ms) => {
this.ui.send('timing', { c: 'c', ms: exposure });
return this.end(cmd, id, ms);
});
}
else if (this.arduino.hasState[this.id]) {
this.log.info(`Sending cmd ${cmd}`);
try {
ms = this.arduino.send(this.id, cmd);
}
@ -178,25 +180,29 @@ class Camera {
this.log.error('Error sending camera exposure command', err);
}
await delay_1.delay(1);
this.log.info(`Sending str ${str}`);
try {
ms = await this.arduino.sendString(this.id, str);
}
catch (err) {
this.log.error('Error sending camera exposure string', err);
}
this.log.info(`Sent str ${str}`);
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);
parts = this.arduino.stateStr[this.id].split('G');
if (parts.length > 1) {
parts = parts[1].split('H');
confirmExposure = parseInt(parts[0]);
if (!isNaN(confirmExposure)) {
this.log.info(`Exposure successfully set to ${confirmExposure}ms`);
this.ui.send('timing', { c: 'c', ms: exposure });
}
}
ms = (+new Date()) - started;
return await this.end(cmd, id, ms);
}

File diff suppressed because one or more lines are too long

View File

@ -56,34 +56,34 @@ class Devices {
*
**/
async enumerate() {
let devices;
let serials;
try {
devices = await this.arduino.enumerate();
serials = await this.arduino.enumerate();
}
catch (err) {
this.log.warn(err, 'SERIAL', false, true);
await delay_1.delay(1000);
return this.all([]);
}
this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true);
devices = this.favor(devices);
return await this.all(devices);
this.log.info(`Found ${serials.length} USB devices`, 'SERIAL', true, true);
serials = this.favor(serials);
return await this.all(serials);
}
/**
*
**/
favor(devices) {
favor(serials) {
const past = this.settings.state.devices.filter((device) => {
if (device.arduino) {
if (device.serial) {
return device;
}
}).map((device) => {
return device.arduino;
return device.serial;
});
if (past.length === 0) {
return devices;
return serials;
}
devices.sort((a, b) => {
serials.sort((a, b) => {
if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) {
return 1;
}
@ -92,17 +92,20 @@ class Devices {
}
return 0;
});
return devices;
return serials;
}
/**
*
**/
async distinguish(device) {
async distinguish(serial) {
let connectSuccess;
let verifySuccess;
let type;
let device;
let exposure;
let parts;
//this.log.info(`distinguish() ${serial}`)
try {
connectSuccess = await this.arduino.connect('connect', device, true);
connectSuccess = await this.arduino.connect('connect', serial, true);
}
catch (err) {
this.log.error('Error connecting', err);
@ -116,28 +119,38 @@ class Devices {
this.log.error('Error verifying device', err);
return null;
}
this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true);
this.log.info(`Verified ${serial} as mcopy device`, 'SERIAL', true, true);
await delay_1.delay(1000);
try {
type = await this.arduino.distinguish();
device = await this.arduino.distinguish();
}
catch (err) {
this.log.error('Error distinguishing device', err);
return null;
}
this.remember('arduino', device, type);
this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true);
this.remember('arduino', device, serial);
this.log.info(`Determined ${device} to be ${device}`, 'SERIAL', true, true);
await delay_1.delay(100);
try {
await this.arduino.state(device.toString(), true);
await this.arduino.state(device, true);
}
catch (err) {
this.log.error('Error checking state capability', err);
}
if (this.arduino.hasState[device.toString()]) {
this.arduino.hasState[type] = true;
if (this.arduino.hasState[device]) {
if (device.indexOf('camera') !== -1) {
parts = this.arduino.stateStr[device].split('G');
if (parts.length > 1) {
parts = parts[1].split('H');
exposure = parseInt(parts[0]);
if (!isNaN(exposure)) {
this.log.info(`Timing for [${device}] = ${exposure}`);
this.ui.send('timing', { c: 'c', ms: exposure });
}
return type;
}
}
}
return device;
}
/**
*
@ -206,7 +219,7 @@ class Devices {
/**
*
**/
async connectDevice(device, type) {
async connectDevice(device, serial) {
let closeSuccess;
let connectSuccess;
try {
@ -216,10 +229,10 @@ class Devices {
this.log.error('Error closing arduino connection', err);
return false;
}
if (type === 'projector') {
this.connected.projector = device;
if (device === 'projector') {
this.connected.projector = serial;
try {
connectSuccess = await this.arduino.connect('projector', device, false);
connectSuccess = await this.arduino.connect('projector', serial, false);
}
catch (err) {
this.log.error('Error connecting to projector', err);
@ -227,10 +240,10 @@ class Devices {
}
this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true);
}
else if (type === 'camera') {
this.connected.camera = device;
else if (device === 'camera') {
this.connected.camera = serial;
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera', err);
@ -238,10 +251,10 @@ class Devices {
}
this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true);
}
else if (type === 'light') {
this.connected.light = device;
else if (device === 'light') {
this.connected.light = serial;
try {
connectSuccess = await this.arduino.connect('light', device, false);
connectSuccess = await this.arduino.connect('light', serial, false);
}
catch (err) {
this.log.error('Error connecting to light', err);
@ -249,12 +262,12 @@ class Devices {
}
this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true);
}
else if (type === 'projector,light') {
this.connected.projector = device;
this.connected.light = device;
this.arduino.aliasSerial('light', device);
else if (device === 'projector,light') {
this.connected.projector = serial;
this.connected.light = serial;
this.arduino.aliasSerial('light', serial);
try {
connectSuccess = await this.arduino.connect('projector', device, false);
connectSuccess = await this.arduino.connect('projector', serial, false);
}
catch (err) {
this.log.error('Error connecting to projector and light', err);
@ -262,14 +275,14 @@ class Devices {
}
this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true);
}
else if (type === 'projector,camera,light') {
this.connected.projector = device;
this.connected.camera = device;
this.connected.light = device;
this.arduino.aliasSerial('camera', device);
this.arduino.aliasSerial('light', device);
else if (device === 'projector,camera,light') {
this.connected.projector = serial;
this.connected.camera = serial;
this.connected.light = serial;
this.arduino.aliasSerial('camera', serial);
this.arduino.aliasSerial('light', serial);
try {
connectSuccess = await this.arduino.connect('projector', device, false);
connectSuccess = await this.arduino.connect('projector', serial, false);
}
catch (err) {
this.log.error('Error connecting to projector, camera and light', err);
@ -277,12 +290,12 @@ class Devices {
}
this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true);
}
else if (type === 'projector,camera') {
this.connected.projector = device;
this.connected.camera = device;
this.arduino.aliasSerial('camera', device);
else if (device === 'projector,camera') {
this.connected.projector = serial;
this.connected.camera = serial;
this.arduino.aliasSerial('camera', serial);
try {
connectSuccess = await this.arduino.connect('projector', device, false);
connectSuccess = await this.arduino.connect('projector', serial, false);
}
catch (err) {
this.log.error('Error connecting to projector and camera', err);
@ -290,10 +303,10 @@ class Devices {
}
this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true);
}
else if (type === 'projector_second') {
this.connected.projector_second = device;
else if (device === 'projector_second') {
this.connected.projector_second = serial;
try {
connectSuccess = await this.arduino.connect('projector_second', device, false);
connectSuccess = await this.arduino.connect('projector_second', serial, false);
}
catch (err) {
this.log.error('Error connecting to secondary projector', err);
@ -301,130 +314,130 @@ class Devices {
}
this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true);
}
else if (type === 'projector,projector_second') {
this.connected.projector = device;
this.connected.projector_second = device;
this.arduino.aliasSerial('projector_second', device);
else if (device === 'projector,projector_second') {
this.connected.projector = serial;
this.connected.projector_second = serial;
this.arduino.aliasSerial('projector_second', serial);
try {
connectSuccess = await this.arduino.connect('projector', device, false);
connectSuccess = await this.arduino.connect('projector', serial, false);
}
catch (err) {
this.log.error('Error connecting to projector and secondary projector', err);
return false;
}
}
else if (type === 'camera_second') {
this.connected.camera_second = device;
else if (device === 'camera_second') {
this.connected.camera_second = serial;
try {
connectSuccess = await this.arduino.connect('camera_second', device, false);
connectSuccess = await this.arduino.connect('camera_second', serial, false);
}
catch (err) {
console.error(err);
return false;
}
}
else if (type === 'camera,camera_second') {
this.connected.camera = device;
this.connected.camera_second = device;
this.arduino.aliasSerial('camera_second', device);
else if (device === 'camera,camera_second') {
this.connected.camera = serial;
this.connected.camera_second = serial;
this.arduino.aliasSerial('camera_second', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, camera_secondary and projector', err);
return false;
}
}
else if (type === 'camera,projector,projector_second') {
this.connected.camera = device;
this.connected.projector = device;
this.connected.projector_second = device;
this.arduino.aliasSerial('projector', device);
this.arduino.aliasSerial('projector_second', device);
else if (device === 'camera,projector,projector_second') {
this.connected.camera = serial;
this.connected.projector = serial;
this.connected.projector_second = serial;
this.arduino.aliasSerial('projector', serial);
this.arduino.aliasSerial('projector_second', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, projector and projector_second', err);
return false;
}
}
else if (type === 'camera,camera_second,projector') {
this.connected.camera = device;
this.connected.camera_second = device;
this.connected.projector = device;
this.arduino.aliasSerial('camera_second', device);
this.arduino.aliasSerial('projector', device);
else if (device === 'camera,camera_second,projector') {
this.connected.camera = serial;
this.connected.camera_second = serial;
this.connected.projector = serial;
this.arduino.aliasSerial('camera_second', serial);
this.arduino.aliasSerial('projector', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, camera_second and projector', err);
return false;
}
}
else if (type === 'camera,camera_second,projector,projector_second') {
this.connected.camera = device;
this.connected.camera_second = device;
this.connected.projector = device;
this.connected.projector_second = device;
this.arduino.aliasSerial('camera_second', device);
this.arduino.aliasSerial('projector', device);
this.arduino.aliasSerial('projector_second', device);
else if (device === 'camera,camera_second,projector,projector_second') {
this.connected.camera = serial;
this.connected.camera_second = serial;
this.connected.projector = serial;
this.connected.projector_second = serial;
this.arduino.aliasSerial('camera_second', serial);
this.arduino.aliasSerial('projector', serial);
this.arduino.aliasSerial('projector_second', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, camera_second, projector and projector_second', err);
return false;
}
}
else if (type === 'capper') {
this.connected.capper = device;
else if (device === 'capper') {
this.connected.capper = serial;
try {
connectSuccess = await this.arduino.connect('capper', device, false);
connectSuccess = await this.arduino.connect('capper', serial, false);
}
catch (err) {
this.log.error('Error connecting capper', err);
return false;
}
}
else if (type === 'camera,capper') {
this.connected.camera = device;
this.connected.capper = device;
this.arduino.aliasSerial('capper', device);
else if (device === 'camera,capper') {
this.connected.camera = serial;
this.connected.capper = serial;
this.arduino.aliasSerial('capper', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera and capper', err);
return false;
}
}
else if (type === 'camera,capper,projector') {
this.connected.camera = device;
this.connected.capper = device;
this.connected.projector = device;
this.arduino.aliasSerial('capper', device);
this.arduino.aliasSerial('projector', device);
else if (device === 'camera,capper,projector') {
this.connected.camera = serial;
this.connected.capper = serial;
this.connected.projector = serial;
this.arduino.aliasSerial('capper', serial);
this.arduino.aliasSerial('projector', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, capper and projector', err);
return false;
}
}
else if (type === 'camera,capper,projector,projector_second') {
this.connected.camera = device;
this.connected.capper = device;
this.connected.projector = device;
this.connected.projector_second = device;
this.arduino.aliasSerial('capper', device);
this.arduino.aliasSerial('projector', device);
this.arduino.aliasSerial('projector_second', device);
else if (device === 'camera,capper,projector,projector_second') {
this.connected.camera = serial;
this.connected.capper = serial;
this.connected.projector = serial;
this.connected.projector_second = serial;
this.arduino.aliasSerial('capper', serial);
this.arduino.aliasSerial('projector', serial);
this.arduino.aliasSerial('projector_second', serial);
try {
connectSuccess = await this.arduino.connect('camera', device, false);
connectSuccess = await this.arduino.connect('camera', serial, false);
}
catch (err) {
this.log.error('Error connecting to camera, capper, projector and projector_second', err);
@ -437,11 +450,11 @@ class Devices {
*
**/
//Cases for 1 or 2 arduinos connected
async all(devices) {
async all(serials) {
let c = {};
let p = {};
let l = {};
let type;
let device;
let d;
let cs = {};
let ps = {};
@ -454,16 +467,16 @@ class Devices {
projector_second: false,
capper: false
};
for (let device of devices) {
for (let serial of serials) {
try {
type = await this.distinguish(device);
device = await this.distinguish(serial);
}
catch (err) {
this.log.error('Error distinguishing device', err);
throw err;
}
try {
await this.connectDevice(device, type);
await this.connectDevice(device, serial);
}
catch (err) {
this.log.error('Error connecting to device', err);
@ -502,23 +515,25 @@ class Devices {
if (this.settings.state.camera && this.settings.state.camera.intval) {
c.intval = this.settings.state.camera.intval;
}
//console.dir(this.arduino.alias);
//console.dir(this.arduino.serial);
return this.ready(p, c, l, cs, ps, capper);
}
/**
*
**/
remember(which, device, type) {
remember(device, serial, type) {
let deviceEntry;
const match = this.settings.state.devices.filter((dev) => {
if (dev[which] && dev[which] === device) {
if (dev[device] && dev[device] === serial) {
return dev;
}
});
if (match.length === 0) {
deviceEntry = {
type
device,
serial
};
deviceEntry[which] = device;
this.settings.state.devices.push(deviceEntry);
this.settings.update('devices', this.settings.state.devices);
this.settings.save();

File diff suppressed because one or more lines are too long

View File

@ -59,6 +59,7 @@ class Projector {
this.log.error(`Error setting ${this.id} direction`, err);
}
}
console.dir(ms);
return await this.end(cmd, id, ms);
}
/**
@ -166,7 +167,7 @@ class Projector {
}
message += ` ${ms}ms`;
this.log.info(message, 'PROJECTOR');
return await this.ui.send(this.id, { cmd: cmd, id: id, ms: ms });
return await this.ui.send(this.id, { cmd, id, ms });
}
}
module.exports = function (arduino, cfg, ui, filmout, second) {

File diff suppressed because one or more lines are too long

View File

@ -33,6 +33,17 @@ class Timing {
'PBPF': 'projs'
};
}
init() {
this.listen();
}
listen() {
ipcRenderer.on('timing', this.timing.bind(this));
}
timing(event, arg) {
if (arg.c) {
this.update(arg.c, parseInt(arg.ms), true);
}
}
reset(profile) {
const keys = Object.keys(profile);
const cmds = Object.keys(cfg.cmd);
@ -74,11 +85,16 @@ class Timing {
this.data = timing;
}
//update with rolling average
update(c, ms) {
update(c, ms, force = false) {
let cmd = this.fromArduino[c];
let id;
if (typeof cmd !== 'undefined' && typeof this.data[cmd] !== 'undefined') {
if (force) {
this.data[cmd] = ms;
}
else {
this.data[cmd] = Math.round((this.data[cmd] + ms) / 2);
}
id = `#${cmd}_time`;
this.updateUI(id, this.data[cmd]);
}

View File

@ -1 +1 @@
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/lib/ui/timing.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,IAAI,MAAe,CAAC;AAMpB,MAAM,MAAM;IAoCX;QAnCO,SAAI,GAAgB,EAE1B,CAAA;QAEO,gBAAW,GAAS;YAC3B,GAAG,EAAG,KAAK;YACR,GAAG,EAAG,MAAM;YACZ,GAAG,EAAG,MAAM;YACZ,GAAG,EAAG,OAAO;YAChB,GAAG,EAAG,MAAM;YACT,GAAG,EAAG,OAAO;YAChB,GAAG,EAAG,OAAO;SACb,CAAA;QAEO,YAAO,GAAU;YACxB,IAAI,EAAG,KAAK;YACZ,IAAI,EAAG,KAAK;YACZ,IAAI,EAAG,OAAO;YACX,IAAI,EAAG,OAAO;YACd,KAAK,EAAE,MAAM;YACb,KAAK,EAAE,MAAM;YACb,KAAK,EAAG,MAAM;YACd,KAAK,EAAG,MAAM;YACd,MAAM,EAAE,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,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,WAAW,EAAE;YACxE,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACtB;QACD,OAAO,CAAC,CAAC;IACV,CAAC;IAEM,KAAK;QACX,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,MAAM,EAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACpD,CAAC;CACD;AAED,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAEtB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}

View File

@ -57,4 +57,5 @@ async function init () {
seq.init();
capper.init();
alertObj.init();
timing.init();
};

View File

@ -7,9 +7,7 @@ interface TimingData {
}
class Timing {
public data : TimingData = {
}
public data : TimingData = {}
private fromArduino : any = {
'c' : 'cam',
@ -46,6 +44,20 @@ class Timing {
}
public init () {
this.listen();
}
private listen () {
ipcRenderer.on('timing', this.timing.bind(this));
}
private timing (event : any, arg : any) {
if (arg.c) {
this.update(arg.c, parseInt(arg.ms), true);
}
}
public reset (profile : any) {
const keys : string[] = Object.keys(profile);
const cmds : string[] = Object.keys(cfg.cmd);
@ -89,11 +101,15 @@ class Timing {
}
//update with rolling average
public update (c : string, ms : number) {
public update (c : string, ms : number, force : boolean = false) {
let cmd : string = this.fromArduino[c];
let id : string;
if (typeof cmd !== 'undefined' && typeof this.data[cmd] !== 'undefined') {
if (force) {
this.data[cmd] = ms;
} else {
this.data[cmd] = Math.round((this.data[cmd] + ms) / 2);
}
id = `#${cmd}_time`;
this.updateUI(id, this.data[cmd]);
}

View File

@ -49,16 +49,17 @@ class Arduino {
private path : any = {};
private known : string[] = KNOWN;
private alias : any = {};
private serial : any = { connect : {}, projector : {}, camera : {}, light : {} };
private serial : any = {};
private hasState : any = {};
private baud : number = 57600;
private queue : any = {};
private timer : number = 0;
private lock : boolean = false;
private locks : any = {};
private confirmExec : any;
private errorState : Function;
public stateStr : any = {};
constructor (errorState : Function) {
this.errorState = errorState;
this.init()
@ -74,7 +75,7 @@ class Arduino {
*
* @returns {Promise} Resolves after enumerating
**/
async enumerate () {
public async enumerate () : Promise<string[]>{
let ports : any[]
let matches : string[] = []
try {
@ -112,13 +113,14 @@ class Arduino {
*
* @returns {Promise} Resolves after sending
**/
async sendAsync (device : string, cmd : string) {
private async sendAsync (device : string, cmd : string) : Promise<number> {
return new Promise ((resolve, reject) => {
this.log.info(`sendAsyc ${device} -> ${cmd}`)
this.log.info(`sendAsync ${cmd} -> ${device}`)
this.queue[cmd] = (ms : number) => {
return resolve(ms)
}
return this.serial[device].write(cmd, (err : any, results : any) => {
this.log.info(`Device: ${device}`)
return this.serial[this.alias[device]].write(cmd, (err : any, results : any) => {
if (err) {
//this.log.error(err)
return reject(err)
@ -130,45 +132,45 @@ class Arduino {
/**
*
**/
async send (serial : string, cmd : string) {
const device : any = this.alias[serial]
let results : any
this.log.info(`send ${cmd} -> ${serial}`)
if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`)
return false
public async send (device : string, cmd : string) : Promise<any> {
const serial : any = this.alias[device]
let ms : number
this.log.info(`send ${cmd} -> ${device}`)
if (this.isLocked(serial)) {
this.log.warn(`send Serial ${serial} is locked`)
return null
}
this.timer = new Date().getTime()
this.locks[serial] = true
this.lock(serial)
await delay(cfg.arduino.serialDelay)
try {
results = await this.sendAsync(device, cmd)
ms = await this.sendAsync(device, cmd)
} catch (e) {
return this.log.error(e)
}
this.locks[serial] = false
this.unlock(serial)
await eventEmitter.emit('arduino_send', cmd)
return results
return ms
}
/**
*
**/
async sendString (serial : string, str : string) : Promise<any> {
const device : any = this.alias[serial]
public async sendString (device : string, str : string) : Promise<any> {
let writeSuccess : any
await delay(cfg.arduino.serialDelay)
if (typeof this.serial[device].fake !== 'undefined'
&& this.serial[device].fake) {
return this.serial[device].string(str)
if (typeof this.serial[this.alias[device]].fake !== 'undefined'
&& this.serial[this.alias[device]].fake) {
return this.serial[this.alias[device]].string(str)
} else {
this.log.info(`sendString ${device} -> ${str}`)
this.log.info(`sendString ${str} -> ${device}`)
try {
writeSuccess = await this.writeAsync(device, str)
} catch (e) {
return this.log.error(e)
}
this.unlock(this.alias[device])
return writeSuccess
}
}
@ -176,10 +178,12 @@ class Arduino {
/**
*
**/
async stateAsync (device : string, confirm : boolean = false) : Promise<string> {
private async stateAsync (device : string, confirm : boolean = false) : Promise<string> {
const cmd : string = cfg.arduino.cmd.state
const serial : string = confirm ? this.alias['connect'] : this.alias[device]
return new Promise ((resolve, reject) => {
this.queue[cmd] = (state : string) => {
this.stateStr[device] = state
if (confirm) {
this.hasState[device] = true
this.log.info(`Device ${device} supports state [${state}]`)
@ -196,8 +200,8 @@ class Arduino {
}
}.bind(this), 1000)
}
this.log.info(`stateAsync ${device} -> ${cmd}`)
return this.serial[device].write(cmd, (err : any, results : any) => {
this.log.info(`stateAsync ${cmd} -> ${device}`)
return this.serial[serial].write(cmd, (err : any, results : any) => {
if (err) {
//this.log.error(err)
return reject(err)
@ -209,26 +213,25 @@ class Arduino {
/**
*
**/
async state (device : string, confirm : boolean = false) : Promise<string>{
public async state (device : string, confirm : boolean = false) : Promise<string>{
const serial : string = confirm ? this.alias['connect'] : this.alias[device]
let results : string
this.log.info(`state device ${device}`)
this.log.info(`state serial ${serial}`)
console.dir(this.locks)
if (typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true) {
this.log.info("Serial is locked")
if (this.isLocked(serial)) {
this.log.warn(`state Serial ${serial} is locked`)
return null
}
this.timer = new Date().getTime()
this.locks[serial] = true
this.lock(serial)
await delay(cfg.arduino.serialDelay)
if (!confirm) this.log.info("got here")
try {
results = await this.stateAsync(device, confirm)
} catch (e) {
return this.log.error(e)
}
this.locks[serial] = false
this.unlock(serial)
await eventEmitter.emit('arduino_state', cfg.arduino.cmd.state)
return results
@ -242,9 +245,9 @@ class Arduino {
*
* @returns {Promise} Resolves after sending
**/
async writeAsync (device : string, str : string) : Promise<any> {
private async writeAsync (device : string, str : string) : Promise<any> {
return new Promise ((resolve, reject) => {
this.serial[device].write(str, function (err : any, results : any) {
this.serial[this.alias[device]].write(str, function (err : any, results : any) {
if (err) {
return reject(err)
}
@ -256,26 +259,26 @@ class Arduino {
/**
*
**/
end (serial : string, data : string) : any {
private end (serial : string, data : string) : any {
const end : number = new Date().getTime()
const ms : number = end - this.timer
let complete : any
this.log.info(`end ${serial} -> ${data}`)
//this.log.info(`end ${serial} -> ${data}`)
if (this.queue[data] !== undefined) {
this.locks[serial] = false
this.unlock(serial)
complete = this.queue[data](ms) //execute callback
eventEmitter.emit('arduino_end', data)
delete this.queue[data]
} else if (data[0] === cfg.arduino.cmd.state) {
this.log.info(`end serial -> ${serial}`)
this.locks[serial] = false
//this.log.info(`end serial -> ${serial}`)
this.unlock(serial)
complete = this.queue[cfg.arduino.cmd.state](data)
eventEmitter.emit('arduino_end', data)
delete this.queue[cfg.arduino.cmd.state]
return data
} else if (data[0] === cfg.arduino.cmd.error) {
this.log.error(`Received error from device ${serial}`)
this.locks[serial] = false
this.unlock(serial)
//error state
//stop sequence
//throw error in ui
@ -285,40 +288,40 @@ class Arduino {
return ms
}
aliasSerial (serial : string, device : string) {
public aliasSerial (device : string, serial : string) {
//this.log.info(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device;
this.alias[device] = serial;
}
async connect (serial : string, device : string, confirm : any) : Promise<any> {
this.log.info(`connect device ${device}`)
this.log.info(`connect serial ${serial}`)
public async connect (device : string, serial : string, confirm : any) : Promise<any> {
//this.log.info(`connect device ${device}`)
//this.log.info(`connect serial ${serial}`)
return new Promise(async (resolve, reject) => {
let connectSuccess : any
this.path[serial] = device
this.alias[serial] = device
this.serial[device] = new SerialPort({
path : this.path[serial],
this.path[device] = serial
this.aliasSerial(device, serial)
this.serial[serial] = new SerialPort({
path : serial,
autoOpen : false,
baudRate: cfg.arduino.baud,
parser
})
this.locks[device] = false
this.unlock(serial)
try {
connectSuccess = await this.openArduino(device)
} catch (e) {
this.log.error('failed to open: ' + e)
return reject(e)
}
this.log.info(`Opened connection with ${this.path[serial]} as ${serial}`)
this.log.info(`Opened connection with ${this.path[device]} as ${device}`)
if (!confirm) {
this.serial[device].on('data', async (data : Buffer) => {
this.serial[this.alias[device]].on('data', async (data : Buffer) => {
let d = data.toString('utf8')
d = d.replace(newlineRe, '').replace(returnRe, '')
return this.end(serial, d)
})
} else {
this.serial[device].on('data', async (data : Buffer) => {
this.serial[this.alias[device]].on('data', async (data : Buffer) => {
let d = data.toString('utf8')
d = d.replace(newlineRe, '').replace(returnRe, '')
return await this.confirmEnd(d)
@ -329,7 +332,7 @@ class Arduino {
})
}
confirmEnd (data : string) {
private confirmEnd (data : string) {
if ( data === cfg.arduino.cmd.connect
|| data === cfg.arduino.cmd.projector_identifier
|| data === cfg.arduino.cmd.camera_identifier
@ -359,15 +362,17 @@ class Arduino {
this.confirmExec(null, data)
this.confirmExec = {}
this.unlock(this.alias['connect'])
} else if (data[0] === cfg.arduino.cmd.state) {
this.queue[cfg.arduino.cmd.state](data)
delete this.queue[cfg.arduino.cmd.state]
this.unlock(this.alias['connect'])
}
}
async verify () {
public async verify () {
return new Promise(async (resolve, reject) => {
const device : any = this.alias['connect']
const device : string = 'connect'
let writeSuccess : any
this.confirmExec = function (err : any, data : string) {
if (data === cfg.arduino.cmd.connect) {
@ -388,9 +393,9 @@ class Arduino {
})
}
async distinguish () {
public async distinguish () {
return new Promise(async (resolve, reject) => {
const device : any = this.alias['connect']
const device : string = 'connect'
let writeSuccess : any
let type : string
this.confirmExec = function (err : any, data : string) {
@ -443,9 +448,9 @@ class Arduino {
})
}
async close () {
const device = this.alias['connect']
let closeSuccess
public async close () {
const device : string = 'connect'
let closeSuccess : boolean
try {
closeSuccess = await this.closeArduino(device)
} catch (e) {
@ -454,10 +459,10 @@ class Arduino {
return closeSuccess
}
async fakeConnect (serial : string) {
const device : string = '/dev/fake'
this.alias[serial] = device
this.serial[device] = {
public async fakeConnect (device : string) {
const serial : string = '/dev/fake'
this.aliasSerial(device, serial)
this.serial[serial] = {
write : async function (cmd : string, cb : any) {
const t : any = {
c : cfg.arduino.cam.time + cfg.arduino.cam.delay,
@ -492,9 +497,9 @@ class Arduino {
*
* @returns {Promise} Resolves after opening
**/
async openArduino (device : string) {
private async openArduino (device : string) : Promise<boolean> {
return new Promise((resolve, reject) => {
return this.serial[device].open((err : any) => {
return this.serial[this.alias[device]].open((err : any) => {
if (err) {
return reject(err)
}
@ -510,9 +515,9 @@ class Arduino {
*
* @returns {Promise} Resolves after closing
**/
async closeArduino (device : string) {
private async closeArduino (device : string) : Promise<boolean> {
return new Promise((resolve : any, reject : any) => {
return this.serial[device].close((err : any) => {
return this.serial[this.alias[device]].close((err : any) => {
if (err) {
return reject(err)
}
@ -520,6 +525,20 @@ class Arduino {
})
})
}
private lock (serial : string) {
//this.log.info(`Locked serial ${serial}`)
this.locks[serial] = true
}
private unlock (serial : string) {
//this.log.info(`Unlocked serial ${serial}`)
this.locks[serial] = false
}
private isLocked (serial : string) {
return typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true
}
}
if (typeof module !== 'undefined' && module.parent) {

View File

@ -167,13 +167,15 @@ class Camera {
const started : number = +new Date();
let ms : any;
let confirmState : any;
let parts : string[];
let confirmExposure : number;
if (this.intval) {
return this.intval.setExposure(this.id, exposure, (ms : number) => {
this.ui.send('timing', { c : 'c', ms : exposure });
return this.end(cmd, id, ms);
});
} else if (this.arduino.hasState[this.id]) {
this.log.info(`Sending cmd ${cmd}`);
try {
ms = this.arduino.send(this.id, cmd);
} catch (err) {
@ -181,23 +183,31 @@ class Camera {
}
await delay(1);
this.log.info(`Sending str ${str}`);
try {
ms = await this.arduino.sendString(this.id, str);
} catch (err) {
this.log.error('Error sending camera exposure string', err);
}
this.log.info(`Sent str ${str}`);
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);
parts = this.arduino.stateStr[this.id].split('G')
if (parts.length > 1) {
parts = parts[1].split('H')
confirmExposure = parseInt(parts[0])
if (!isNaN(confirmExposure)) {
this.log.info(`Exposure successfully set to ${confirmExposure}ms`)
this.ui.send('timing', { c : 'c', ms : exposure })
}
}
ms = (+new Date()) - started;
return await this.end(cmd, id, ms);
}

View File

@ -68,33 +68,33 @@ class Devices {
*
**/
public async enumerate () {
let devices : Device[];
let serials : string[];
try{
devices = await this.arduino.enumerate();
serials = await this.arduino.enumerate();
} catch (err) {
this.log.warn(err, 'SERIAL', false, true);
await delay(1000);
return this.all([]);
}
this.log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true);
devices = this.favor(devices);
return await this.all(devices);
this.log.info(`Found ${serials.length} USB devices`, 'SERIAL', true, true);
serials = this.favor(serials);
return await this.all(serials);
}
/**
*
**/
private favor (devices : Device[]) {
private favor (serials : string[]) {
const past = this.settings.state.devices.filter((device : Device) => {
if (device.arduino) {
if (device.serial) {
return device;
}
}).map((device : Device) => {
return device.arduino;
return device.serial;
})
if (past.length === 0) {
return devices;
return serials;
}
devices.sort((a : any, b : any) => {
serials.sort((a : any, b : any) => {
if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) {
return 1;
} else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) {
@ -102,18 +102,20 @@ class Devices {
}
return 0;
})
return devices;
return serials;
}
/**
*
**/
private async distinguish (device : Device) {
let connectSuccess : any;
let verifySuccess : any;
let type : any;
private async distinguish (serial : string) {
let connectSuccess : any
let verifySuccess : any
let device : any
let exposure : number
let parts : string[]
//this.log.info(`distinguish() ${serial}`)
try {
connectSuccess = await this.arduino.connect('connect', device, true)
connectSuccess = await this.arduino.connect('connect', serial, true)
} catch (err) {
this.log.error('Error connecting', err)
return null
@ -128,34 +130,44 @@ class Devices {
return null
}
this.log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true)
this.log.info(`Verified ${serial} as mcopy device`, 'SERIAL', true, true)
await delay(1000)
try {
type = await this.arduino.distinguish()
device = await this.arduino.distinguish()
} catch (err) {
this.log.error('Error distinguishing device', err)
return null
}
this.remember('arduino', device, type)
this.log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true)
this.remember('arduino', device, serial)
this.log.info(`Determined ${device} to be ${device}`, 'SERIAL', true, true)
await delay(100)
try {
await this.arduino.state(device.toString(), true)
await this.arduino.state(device, true)
} catch (err) {
this.log.error('Error checking state capability', err)
}
if (this.arduino.hasState[device.toString()]) {
this.arduino.hasState[type] = true;
if (this.arduino.hasState[device]) {
if (device.indexOf('camera') !== -1) {
parts = this.arduino.stateStr[device].split('G')
if (parts.length > 1) {
parts = parts[1].split('H')
exposure = parseInt(parts[0])
if (!isNaN(exposure)) {
this.log.info(`Timing for [${device}] = ${exposure}`)
this.ui.send('timing', { c : 'c', ms : exposure })
}
}
}
}
return type
return device
}
/**
*
@ -221,7 +233,7 @@ class Devices {
/**
*
**/
private async connectDevice (device : Device, type : any) {
private async connectDevice (device : string, serial : string) {
let closeSuccess : any;
let connectSuccess : any;
try {
@ -230,188 +242,188 @@ class Devices {
this.log.error('Error closing arduino connection', err)
return false
}
if (type === 'projector') {
this.connected.projector = device
if (device === 'projector') {
this.connected.projector = serial
try {
connectSuccess = await this.arduino.connect('projector', device, false)
connectSuccess = await this.arduino.connect('projector', serial, false)
} catch (err) {
this.log.error('Error connecting to projector', err)
return false
}
this.log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true)
} else if (type === 'camera') {
this.connected.camera = device
} else if (device === 'camera') {
this.connected.camera = serial
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera', err)
return false
}
this.log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true)
} else if (type === 'light') {
this.connected.light = device
} else if (device === 'light') {
this.connected.light = serial
try {
connectSuccess = await this.arduino.connect('light', device, false)
connectSuccess = await this.arduino.connect('light', serial, false)
} catch (err) {
this.log.error('Error connecting to light', err)
return false
}
this.log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true)
} else if (type === 'projector,light') {
this.connected.projector = device
this.connected.light = device
this.arduino.aliasSerial('light', device)
} else if (device === 'projector,light') {
this.connected.projector = serial
this.connected.light = serial
this.arduino.aliasSerial('light', serial)
try{
connectSuccess = await this.arduino.connect('projector', device, false)
connectSuccess = await this.arduino.connect('projector', serial, false)
} catch (err) {
this.log.error('Error connecting to projector and light', err)
return false
}
this.log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true)
} else if (type === 'projector,camera,light') {
this.connected.projector = device
this.connected.camera = device
this.connected.light = device
this.arduino.aliasSerial('camera', device)
this.arduino.aliasSerial('light', device)
} else if (device === 'projector,camera,light') {
this.connected.projector = serial
this.connected.camera = serial
this.connected.light = serial
this.arduino.aliasSerial('camera', serial)
this.arduino.aliasSerial('light', serial)
try {
connectSuccess = await this.arduino.connect('projector', device, false)
connectSuccess = await this.arduino.connect('projector', serial, false)
} catch (err) {
this.log.error('Error connecting to projector, camera and light', err)
return false
}
this.log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true)
} else if (type === 'projector,camera') {
this.connected.projector = device
this.connected.camera = device
this.arduino.aliasSerial('camera', device)
} else if (device === 'projector,camera') {
this.connected.projector = serial
this.connected.camera = serial
this.arduino.aliasSerial('camera', serial)
try {
connectSuccess = await this.arduino.connect('projector', device, false)
connectSuccess = await this.arduino.connect('projector', serial, false)
} catch (err) {
this.log.error('Error connecting to projector and camera', err)
return false
}
this.log.info(`Connected to ${device} as PROJECTOR + CAMERA`, 'SERIAL', true, true)
} else if (type === 'projector_second') {
this.connected.projector_second = device
} else if (device === 'projector_second') {
this.connected.projector_second = serial
try {
connectSuccess = await this.arduino.connect('projector_second', device, false)
connectSuccess = await this.arduino.connect('projector_second', serial, false)
} catch (err) {
this.log.error('Error connecting to secondary projector', err)
return false
}
this.log.info(`Connected to ${device} as PROJECTOR_SECOND`, 'SERIAL', true, true)
} else if (type === 'projector,projector_second') {
this.connected.projector = device
this.connected.projector_second = device
this.arduino.aliasSerial('projector_second', device)
} else if (device === 'projector,projector_second') {
this.connected.projector = serial
this.connected.projector_second = serial
this.arduino.aliasSerial('projector_second', serial)
try {
connectSuccess = await this.arduino.connect('projector', device, false)
connectSuccess = await this.arduino.connect('projector', serial, false)
} catch (err) {
this.log.error('Error connecting to projector and secondary projector', err)
return false
}
} else if (type === 'camera_second') {
this.connected.camera_second = device
} else if (device === 'camera_second') {
this.connected.camera_second = serial
try {
connectSuccess = await this.arduino.connect('camera_second', device, false)
connectSuccess = await this.arduino.connect('camera_second', serial, false)
} catch (err) {
console.error(err)
return false
}
} else if (type === 'camera,camera_second') {
this.connected.camera = device
this.connected.camera_second = device
this.arduino.aliasSerial('camera_second', device)
} else if (device === 'camera,camera_second') {
this.connected.camera = serial
this.connected.camera_second = serial
this.arduino.aliasSerial('camera_second', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, camera_secondary and projector', err)
return false
}
} else if (type === 'camera,projector,projector_second') {
this.connected.camera = device
this.connected.projector = device
this.connected.projector_second = device
this.arduino.aliasSerial('projector', device)
this.arduino.aliasSerial('projector_second', device)
} else if (device === 'camera,projector,projector_second') {
this.connected.camera = serial
this.connected.projector = serial
this.connected.projector_second = serial
this.arduino.aliasSerial('projector', serial)
this.arduino.aliasSerial('projector_second', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, projector and projector_second', err)
return false
}
} else if (type === 'camera,camera_second,projector') {
this.connected.camera = device
this.connected.camera_second = device
this.connected.projector = device
this.arduino.aliasSerial('camera_second', device)
this.arduino.aliasSerial('projector', device)
} else if (device === 'camera,camera_second,projector') {
this.connected.camera = serial
this.connected.camera_second = serial
this.connected.projector = serial
this.arduino.aliasSerial('camera_second', serial)
this.arduino.aliasSerial('projector', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, camera_second and projector', err)
return false
}
} else if (type === 'camera,camera_second,projector,projector_second') {
this.connected.camera = device
this.connected.camera_second = device
this.connected.projector = device
this.connected.projector_second = device
this.arduino.aliasSerial('camera_second', device)
this.arduino.aliasSerial('projector', device)
this.arduino.aliasSerial('projector_second', device)
} else if (device === 'camera,camera_second,projector,projector_second') {
this.connected.camera = serial
this.connected.camera_second = serial
this.connected.projector = serial
this.connected.projector_second = serial
this.arduino.aliasSerial('camera_second', serial)
this.arduino.aliasSerial('projector', serial)
this.arduino.aliasSerial('projector_second', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, camera_second, projector and projector_second', err)
return false
}
} else if (type === 'capper') {
this.connected.capper = device
} else if (device === 'capper') {
this.connected.capper = serial
try {
connectSuccess = await this.arduino.connect('capper', device, false)
connectSuccess = await this.arduino.connect('capper', serial, false)
} catch (err) {
this.log.error('Error connecting capper', err)
return false
}
} else if (type === 'camera,capper') {
this.connected.camera = device
this.connected.capper = device
this.arduino.aliasSerial('capper', device)
} else if (device === 'camera,capper') {
this.connected.camera = serial
this.connected.capper = serial
this.arduino.aliasSerial('capper', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera and capper', err)
return false
}
} else if (type === 'camera,capper,projector') {
this.connected.camera = device
this.connected.capper = device
this.connected.projector = device
this.arduino.aliasSerial('capper', device)
this.arduino.aliasSerial('projector', device)
} else if (device === 'camera,capper,projector') {
this.connected.camera = serial
this.connected.capper = serial
this.connected.projector = serial
this.arduino.aliasSerial('capper', serial)
this.arduino.aliasSerial('projector', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, capper and projector', err)
return false
}
} else if (type === 'camera,capper,projector,projector_second') {
this.connected.camera = device
this.connected.capper = device
this.connected.projector = device
this.connected.projector_second = device
this.arduino.aliasSerial('capper', device)
this.arduino.aliasSerial('projector', device)
this.arduino.aliasSerial('projector_second', device)
} else if (device === 'camera,capper,projector,projector_second') {
this.connected.camera = serial
this.connected.capper = serial
this.connected.projector = serial
this.connected.projector_second = serial
this.arduino.aliasSerial('capper', serial)
this.arduino.aliasSerial('projector', serial)
this.arduino.aliasSerial('projector_second', serial)
try {
connectSuccess = await this.arduino.connect('camera', device, false)
connectSuccess = await this.arduino.connect('camera', serial, false)
} catch (err) {
this.log.error('Error connecting to camera, capper, projector and projector_second', err)
return false
@ -423,11 +435,11 @@ class Devices {
*
**/
//Cases for 1 or 2 arduinos connected
private async all (devices : Device[]) {
private async all (serials : string[]) {
let c : any = {}
let p : any = {}
let l : any = {}
let type : string;
let device : string;
let d : any
let cs : any = {}
let ps : any = {}
@ -442,16 +454,16 @@ class Devices {
capper : false
}
for (let device of devices) {
for (let serial of serials) {
try {
type = await this.distinguish(device)
device = await this.distinguish(serial)
} catch (err) {
this.log.error('Error distinguishing device', err)
throw err
}
try {
await this.connectDevice(device, type)
await this.connectDevice(device, serial)
} catch (err) {
this.log.error('Error connecting to device', err)
throw err
@ -496,23 +508,25 @@ class Devices {
c.intval = this.settings.state.camera.intval
}
//console.dir(this.arduino.alias);
//console.dir(this.arduino.serial);
return this.ready(p, c, l, cs, ps, capper)
}
/**
*
**/
private remember (which : string, device : any, type : string) {
private remember (device: string, serial : string, type : string) {
let deviceEntry : any;
const match = this.settings.state.devices.filter((dev : any) => {
if (dev[which] && dev[which] === device) {
if (dev[device] && dev[device] === serial) {
return dev
}
})
if (match.length === 0) {
deviceEntry = {
type
device,
serial
}
deviceEntry[which] = device
this.settings.state.devices.push(deviceEntry)
this.settings.update('devices', this.settings.state.devices)
this.settings.save()

10
src/globals.d.ts vendored
View File

@ -15,20 +15,24 @@ declare module 'winston';
declare module 'frame';
interface Device {
arduino : string;
serial : string;
device : string;
}
interface Arduino {
hasState : any;
alias : any;
serial : any;
stateStr : any;
send (id : string, cmd : string) : number;
sendString (id : string, str : string) : any;
enumerate () : any;
connect (id : string, device : Device, state : boolean) : any;
connect (device : string, serial : string, state : boolean) : any;
verify () : any;
distinguish () : any;
fakeConnect ( id : string) : any;
stateAsync (device : string, confirm: boolean) : any;
state (serial: string, confirm: boolean) : number;
close () : any;
aliasSerial ( id : string, device : Device) : any;
aliasSerial ( device : string, serial : string) : any;
}

View File

@ -64,6 +64,7 @@ class Projector {
this.log.error(`Error setting ${this.id} direction`, err)
}
}
console.dir(ms)
return await this.end(cmd, id, ms)
}
@ -129,7 +130,7 @@ class Projector {
*
**/
async end (cmd : string, id : string, ms : number) {
let message : string = '';
let message : string = ''
if (cmd === this.cfg.arduino.cmd.projector_forward) {
message = 'Projector set to FORWARD'
} else if (cmd === this.cfg.arduino.cmd.projector_backward) {
@ -159,7 +160,7 @@ class Projector {
}
message += ` ${ms}ms`
this.log.info(message, 'PROJECTOR')
return await this.ui.send(this.id, {cmd: cmd, id : id, ms: ms})
return await this.ui.send(this.id, { cmd, id, ms })
}
}