Skip to content

Commit

Permalink
Fix start stop handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stoprocent committed Oct 9, 2023
1 parent cfb3cfc commit b63db06
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/uart.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ BluetoothHciSocket.prototype.bindUser = function(devId, params) {

// Serial Port Parser
this._parser = this._serialDevice.pipe(new HciSerialParser());
this._parser.on('data', (data) => this.emit('data', data));
this._parser.on('raw', this.waitForReset.bind(this));

// Serial Port Event Listeners
Expand Down Expand Up @@ -119,11 +118,11 @@ BluetoothHciSocket.prototype.isDevUp = function() {
};

BluetoothHciSocket.prototype.start = function() {

this._parser.on('data', (data) => this.emit('data', data));
};

BluetoothHciSocket.prototype.stop = function() {

this._parser.removeAllListeners('data');
};

BluetoothHciSocket.prototype.write = function(data) {
Expand All @@ -136,10 +135,6 @@ BluetoothHciSocket.prototype.write = function(data) {

BluetoothHciSocket.prototype.waitForReset = function (data) { //
if (this._mode === 'raw' && data.length === 7 && ('040e0401030c00' === data.toString('hex') || '040e0402030c00' === data.toString('hex'))) {
// Cleanup

this._parser.removeListener('raw', this.waitForReset.bind(this));

debug('reset complete');
this._queue.resume();
this._isUp = true;
Expand All @@ -156,7 +151,7 @@ BluetoothHciSocket.prototype.reset = function() {
// length
cmd.writeUInt8(0x00, 3);

debug('reset');
debug('reset:', cmd.toString("hex"));
this._serialDevice.write(cmd);
};

Expand Down

0 comments on commit b63db06

Please sign in to comment.