canon_ble #82

Merged
mattmcw merged 149 commits from canon_ble into main 2023-08-01 03:38:52 +00:00
4 changed files with 25 additions and 13 deletions
Showing only changes of commit fb51716e3a - Show all commits
app
src/arduino

View File

@ -43,6 +43,7 @@
padding: 6px 12px;
font-size: 21px;
min-width: 300px;
max-width: 300px;
&.active{
border-color: @SELECTED;
color: @SELECTED;

View File

@ -108,7 +108,7 @@ class Arduino {
async send(serial, cmd) {
const device = this.alias[serial];
let results;
this.log.info(`${cmd} -> ${serial}`);
this.log.info(`send ${cmd} -> ${serial}`);
if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`);
return false;
@ -173,17 +173,21 @@ class Arduino {
});
});
}
async state(serial, confirm = false) {
const device = confirm ? this.alias['connect'] : this.alias[serial];
async state(device, confirm = false) {
const serial = confirm ? this.alias['connect'] : this.alias[device];
let results;
this.log.info(serial);
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;
}
this.timer = new Date().getTime();
this.locks[serial] = true;
await delay_1.delay(cfg.arduino.serialDelay);
if (!confirm)
this.log.info("got here");
try {
results = await this.stateAsync(device, confirm);
}
@ -216,7 +220,7 @@ class Arduino {
const end = new Date().getTime();
const ms = end - this.timer;
let complete;
this.log.info(`${serial} -> ${data}`);
this.log.info(`end ${serial} -> ${data}`);
if (this.queue[data] !== undefined) {
this.locks[serial] = false;
complete = this.queue[data](ms); //execute callback
@ -224,12 +228,15 @@ class Arduino {
delete this.queue[data];
}
else if (data[0] === cfg.arduino.cmd.state) {
this.locks[serial] = false;
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;
//error state
//stop sequence
//throw error in ui

File diff suppressed because one or more lines are too long

View File

@ -117,7 +117,7 @@ class Arduino {
async send (serial : string, cmd : string) {
const device : any = this.alias[serial]
let results : any
this.log.info(`${cmd} -> ${serial}`)
this.log.info(`send ${cmd} -> ${serial}`)
if (this.locks[serial]) {
this.log.warning(`Serial ${serial} is locked`)
return false
@ -183,18 +183,20 @@ class Arduino {
})
}
async state (serial : string, confirm : boolean = false) : Promise<string>{
const device : string = confirm ? this.alias['connect'] : this.alias[serial]
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(serial)
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
}
this.timer = new Date().getTime()
this.locks[serial] = true
await delay(cfg.arduino.serialDelay)
this.log.info("got here")
if (!confirm) this.log.info("got here")
try {
results = await this.stateAsync(device, confirm)
} catch (e) {
@ -229,19 +231,21 @@ class Arduino {
const end : number = new Date().getTime()
const ms : number = end - this.timer
let complete : any
this.log.info(`${serial} -> ${data}`)
this.log.info(`end ${serial} -> ${data}`)
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[0] === cfg.arduino.cmd.state) {
this.locks[serial] = false
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
//error state
//stop sequence
//throw error in ui