canon_ble #82
|
@ -43,6 +43,7 @@
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
font-size: 21px;
|
font-size: 21px;
|
||||||
min-width: 300px;
|
min-width: 300px;
|
||||||
|
max-width: 300px;
|
||||||
&.active{
|
&.active{
|
||||||
border-color: @SELECTED;
|
border-color: @SELECTED;
|
||||||
color: @SELECTED;
|
color: @SELECTED;
|
||||||
|
|
|
@ -108,7 +108,7 @@ 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(`send ${cmd} -> ${serial}`);
|
||||||
if (this.locks[serial]) {
|
if (this.locks[serial]) {
|
||||||
this.log.warning(`Serial ${serial} is locked`);
|
this.log.warning(`Serial ${serial} is locked`);
|
||||||
return false;
|
return false;
|
||||||
|
@ -173,17 +173,21 @@ class Arduino {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async state(serial, confirm = false) {
|
async state(device, confirm = false) {
|
||||||
const device = confirm ? this.alias['connect'] : this.alias[serial];
|
const serial = confirm ? this.alias['connect'] : this.alias[device];
|
||||||
let results;
|
let results;
|
||||||
this.log.info(serial);
|
this.log.info(serial);
|
||||||
this.log.info(device);
|
this.log.info(device);
|
||||||
if (this.locks[serial]) {
|
console.dir(this.locks);
|
||||||
|
if (typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true) {
|
||||||
|
this.log.info("Serial is locked");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.timer = new Date().getTime();
|
this.timer = new Date().getTime();
|
||||||
this.locks[serial] = true;
|
this.locks[serial] = true;
|
||||||
await delay_1.delay(cfg.arduino.serialDelay);
|
await delay_1.delay(cfg.arduino.serialDelay);
|
||||||
|
if (!confirm)
|
||||||
|
this.log.info("got here");
|
||||||
try {
|
try {
|
||||||
results = await this.stateAsync(device, confirm);
|
results = await this.stateAsync(device, confirm);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +220,7 @@ class Arduino {
|
||||||
const end = new Date().getTime();
|
const end = new Date().getTime();
|
||||||
const ms = end - this.timer;
|
const ms = end - this.timer;
|
||||||
let complete;
|
let complete;
|
||||||
this.log.info(`${serial} -> ${data}`);
|
this.log.info(`end ${serial} -> ${data}`);
|
||||||
if (this.queue[data] !== undefined) {
|
if (this.queue[data] !== undefined) {
|
||||||
this.locks[serial] = false;
|
this.locks[serial] = false;
|
||||||
complete = this.queue[data](ms); //execute callback
|
complete = this.queue[data](ms); //execute callback
|
||||||
|
@ -224,12 +228,15 @@ 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) {
|
||||||
|
this.locks[serial] = false;
|
||||||
complete = this.queue[cfg.arduino.cmd.state](data);
|
complete = this.queue[cfg.arduino.cmd.state](data);
|
||||||
|
eventEmitter.emit('arduino_end', 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) {
|
||||||
this.log.error(`Received error from device ${serial}`);
|
this.log.error(`Received error from device ${serial}`);
|
||||||
|
this.locks[serial] = false;
|
||||||
//error state
|
//error state
|
||||||
//stop sequence
|
//stop sequence
|
||||||
//throw error in ui
|
//throw error in ui
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -117,7 +117,7 @@ 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(`send ${cmd} -> ${serial}`)
|
||||||
if (this.locks[serial]) {
|
if (this.locks[serial]) {
|
||||||
this.log.warning(`Serial ${serial} is locked`)
|
this.log.warning(`Serial ${serial} is locked`)
|
||||||
return false
|
return false
|
||||||
|
@ -183,18 +183,20 @@ class Arduino {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async state (serial : string, confirm : boolean = false) : Promise<string>{
|
async state (device : string, confirm : boolean = false) : Promise<string>{
|
||||||
const device : string = confirm ? this.alias['connect'] : this.alias[serial]
|
const serial : string = confirm ? this.alias['connect'] : this.alias[device]
|
||||||
let results : string
|
let results : string
|
||||||
this.log.info(serial)
|
this.log.info(serial)
|
||||||
this.log.info(device)
|
this.log.info(device)
|
||||||
if (this.locks[serial]) {
|
console.dir(this.locks)
|
||||||
|
if (typeof this.locks[serial] !== 'undefined' && this.locks[serial] === true) {
|
||||||
|
this.log.info("Serial is locked")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
this.timer = new Date().getTime()
|
this.timer = new Date().getTime()
|
||||||
this.locks[serial] = true
|
this.locks[serial] = true
|
||||||
await delay(cfg.arduino.serialDelay)
|
await delay(cfg.arduino.serialDelay)
|
||||||
this.log.info("got here")
|
if (!confirm) this.log.info("got here")
|
||||||
try {
|
try {
|
||||||
results = await this.stateAsync(device, confirm)
|
results = await this.stateAsync(device, confirm)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -229,19 +231,21 @@ class Arduino {
|
||||||
const end : number = new Date().getTime()
|
const end : number = new Date().getTime()
|
||||||
const ms : number = end - this.timer
|
const ms : number = end - this.timer
|
||||||
let complete : any
|
let complete : any
|
||||||
this.log.info(`${serial} -> ${data}`)
|
this.log.info(`end ${serial} -> ${data}`)
|
||||||
if (this.queue[data] !== undefined) {
|
if (this.queue[data] !== undefined) {
|
||||||
this.locks[serial] = false
|
this.locks[serial] = false
|
||||||
complete = this.queue[data](ms) //execute callback
|
complete = this.queue[data](ms) //execute callback
|
||||||
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) {
|
||||||
|
this.locks[serial] = false
|
||||||
complete = this.queue[cfg.arduino.cmd.state](data)
|
complete = this.queue[cfg.arduino.cmd.state](data)
|
||||||
|
eventEmitter.emit('arduino_end', 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) {
|
||||||
this.log.error(`Received error from device ${serial}`)
|
this.log.error(`Received error from device ${serial}`)
|
||||||
|
this.locks[serial] = false
|
||||||
//error state
|
//error state
|
||||||
//stop sequence
|
//stop sequence
|
||||||
//throw error in ui
|
//throw error in ui
|
||||||
|
|
Loading…
Reference in New Issue