Remove console logging from arduino lib. Reject or throw to log errors

This commit is contained in:
mmcwilliams 2019-03-21 15:59:50 -04:00
parent 6a31eda3c4
commit ea91ea5ff5
7 changed files with 15 additions and 31 deletions

View File

@ -137,7 +137,6 @@ class Arduino {
if (err) { if (err) {
return reject(err); return reject(err);
} }
//console.log('sent: ' + str)
return resolve(results); return resolve(results);
}); });
}); });
@ -148,7 +147,6 @@ class Arduino {
let complete; let complete;
if (this.queue[data] !== undefined) { if (this.queue[data] !== undefined) {
this.locks[serial] = false; this.locks[serial] = false;
//console.log('Command ' + data + ' took ' + ms + 'ms');
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];
@ -159,7 +157,7 @@ class Arduino {
return complete; return complete;
} }
aliasSerial(serial, device) { aliasSerial(serial, device) {
console.log(`Making "${serial}" an alias of ${device}`); //console.log(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device; this.alias[serial] = device;
} }
async connect(serial, device, confirm) { async connect(serial, device, confirm) {
@ -180,7 +178,7 @@ class Arduino {
console.error('failed to open: ' + e); console.error('failed to open: ' + e);
return reject(e); return reject(e);
} }
console.log(`Opened connection with ${this.path[serial]} as ${serial}`); //console.log(`Opened connection with ${this.path[serial]} as ${serial}`);
if (!confirm) { if (!confirm) {
this.serial[device].on('data', async (data) => { this.serial[device].on('data', async (data) => {
let d = data.toString('utf8'); let d = data.toString('utf8');
@ -291,7 +289,6 @@ class Arduino {
writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier); writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier);
} }
catch (e) { catch (e) {
console.error(e);
return reject(e); return reject(e);
} }
}); });
@ -303,13 +300,12 @@ class Arduino {
closeSuccess = await this.closeArduino(device); closeSuccess = await this.closeArduino(device);
} }
catch (e) { catch (e) {
return console.error(e); throw e;
} }
return closeSuccess; return closeSuccess;
} }
; ;
async fakeConnect(serial) { async fakeConnect(serial) {
//console.log('Connecting to fake arduino...');
const device = '/dev/fake'; const device = '/dev/fake';
this.alias[serial] = device; this.alias[serial] = device;
this.serial[device] = { this.serial[device] = {

File diff suppressed because one or more lines are too long

View File

@ -137,7 +137,6 @@ class Arduino {
if (err) { if (err) {
return reject(err); return reject(err);
} }
//console.log('sent: ' + str)
return resolve(results); return resolve(results);
}); });
}); });
@ -148,7 +147,6 @@ class Arduino {
let complete; let complete;
if (this.queue[data] !== undefined) { if (this.queue[data] !== undefined) {
this.locks[serial] = false; this.locks[serial] = false;
//console.log('Command ' + data + ' took ' + ms + 'ms');
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];
@ -159,7 +157,7 @@ class Arduino {
return complete; return complete;
} }
aliasSerial(serial, device) { aliasSerial(serial, device) {
console.log(`Making "${serial}" an alias of ${device}`); //console.log(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device; this.alias[serial] = device;
} }
async connect(serial, device, confirm) { async connect(serial, device, confirm) {
@ -180,7 +178,7 @@ class Arduino {
console.error('failed to open: ' + e); console.error('failed to open: ' + e);
return reject(e); return reject(e);
} }
console.log(`Opened connection with ${this.path[serial]} as ${serial}`); //console.log(`Opened connection with ${this.path[serial]} as ${serial}`);
if (!confirm) { if (!confirm) {
this.serial[device].on('data', async (data) => { this.serial[device].on('data', async (data) => {
let d = data.toString('utf8'); let d = data.toString('utf8');
@ -291,7 +289,6 @@ class Arduino {
writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier); writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier);
} }
catch (e) { catch (e) {
console.error(e);
return reject(e); return reject(e);
} }
}); });
@ -303,13 +300,12 @@ class Arduino {
closeSuccess = await this.closeArduino(device); closeSuccess = await this.closeArduino(device);
} }
catch (e) { catch (e) {
return console.error(e); throw e;
} }
return closeSuccess; return closeSuccess;
} }
; ;
async fakeConnect(serial) { async fakeConnect(serial) {
//console.log('Connecting to fake arduino...');
const device = '/dev/fake'; const device = '/dev/fake';
this.alias[serial] = device; this.alias[serial] = device;
this.serial[device] = { this.serial[device] = {

File diff suppressed because one or more lines are too long

View File

@ -137,7 +137,6 @@ class Arduino {
if (err) { if (err) {
return reject(err); return reject(err);
} }
//console.log('sent: ' + str)
return resolve(results); return resolve(results);
}); });
}); });
@ -148,7 +147,6 @@ class Arduino {
let complete; let complete;
if (this.queue[data] !== undefined) { if (this.queue[data] !== undefined) {
this.locks[serial] = false; this.locks[serial] = false;
//console.log('Command ' + data + ' took ' + ms + 'ms');
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];
@ -159,7 +157,7 @@ class Arduino {
return complete; return complete;
} }
aliasSerial(serial, device) { aliasSerial(serial, device) {
console.log(`Making "${serial}" an alias of ${device}`); //console.log(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device; this.alias[serial] = device;
} }
async connect(serial, device, confirm) { async connect(serial, device, confirm) {
@ -180,7 +178,7 @@ class Arduino {
console.error('failed to open: ' + e); console.error('failed to open: ' + e);
return reject(e); return reject(e);
} }
console.log(`Opened connection with ${this.path[serial]} as ${serial}`); //console.log(`Opened connection with ${this.path[serial]} as ${serial}`);
if (!confirm) { if (!confirm) {
this.serial[device].on('data', async (data) => { this.serial[device].on('data', async (data) => {
let d = data.toString('utf8'); let d = data.toString('utf8');
@ -291,7 +289,6 @@ class Arduino {
writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier); writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier);
} }
catch (e) { catch (e) {
console.error(e);
return reject(e); return reject(e);
} }
}); });
@ -303,13 +300,12 @@ class Arduino {
closeSuccess = await this.closeArduino(device); closeSuccess = await this.closeArduino(device);
} }
catch (e) { catch (e) {
return console.error(e); throw e;
} }
return closeSuccess; return closeSuccess;
} }
; ;
async fakeConnect(serial) { async fakeConnect(serial) {
//console.log('Connecting to fake arduino...');
const device = '/dev/fake'; const device = '/dev/fake';
this.alias[serial] = device; this.alias[serial] = device;
this.serial[device] = { this.serial[device] = {

File diff suppressed because one or more lines are too long

View File

@ -144,7 +144,6 @@ class Arduino {
if (err) { if (err) {
return reject(err) return reject(err)
} }
//console.log('sent: ' + str)
return resolve(results) return resolve(results)
}) })
}) })
@ -156,7 +155,6 @@ class Arduino {
let complete let complete
if (this.queue[data] !== undefined) { if (this.queue[data] !== undefined) {
this.locks[serial] = false; this.locks[serial] = false;
//console.log('Command ' + data + ' took ' + ms + 'ms');
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]
@ -167,7 +165,7 @@ class Arduino {
} }
aliasSerial (serial : string, device : string) { aliasSerial (serial : string, device : string) {
console.log(`Making "${serial}" an alias of ${device}`) //console.log(`Making "${serial}" an alias of ${device}`)
this.alias[serial] = device this.alias[serial] = device
} }
@ -188,7 +186,7 @@ class Arduino {
console.error('failed to open: ' + e) console.error('failed to open: ' + e)
return reject(e) return reject(e)
} }
console.log(`Opened connection with ${this.path[serial]} as ${serial}`); //console.log(`Opened connection with ${this.path[serial]} as ${serial}`);
if (!confirm) { if (!confirm) {
this.serial[device].on('data', async (data : Buffer) => { this.serial[device].on('data', async (data : Buffer) => {
let d = data.toString('utf8') let d = data.toString('utf8')
@ -294,7 +292,6 @@ class Arduino {
try { try {
writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier) writeSuccess = await this.sendAsync(device, cfg.arduino.cmd.mcopy_identifier)
} catch (e) { } catch (e) {
console.error(e)
return reject(e) return reject(e)
} }
}) })
@ -306,13 +303,12 @@ class Arduino {
try { try {
closeSuccess = await this.closeArduino(device) closeSuccess = await this.closeArduino(device)
} catch (e) { } catch (e) {
return console.error(e) throw e;
} }
return closeSuccess return closeSuccess
}; };
async fakeConnect (serial : string) { async fakeConnect (serial : string) {
//console.log('Connecting to fake arduino...');
const device : string = '/dev/fake' const device : string = '/dev/fake'
this.alias[serial] = device this.alias[serial] = device
this.serial[device] = { this.serial[device] = {