Skip to content

Commit

Permalink
Add Board.clearSysexResponse(commandByte).
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodd authored and rwaldron committed Aug 24, 2018
1 parent 2bc9e5e commit d08665e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,19 @@ Board.prototype.sysexResponse = function(commandByte, handler) {
return this;
};

/*
* Allow user to remove sysex response handlers.
*
* @param {number} commandByte The commandByte to disassociate with a handler
* previously set via `sysexResponse( commandByte, handler)`.
*/

Board.prototype.clearSysexResponse = function(commandByte) {
if (Board.SYSEX_RESPONSE[commandByte]) {
delete Board.SYSEX_RESPONSE[commandByte];
}
};

/**
* Allow user code to send arbitrary sysex messages
*
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ accelStepper support 2, 3, and 4 wire configurations as well as step + direction
- Use `Board.encode(data)` to encode data values into an array of 7-bit byte pairs.
- `board.clearSysexResponse(commandByte)`
Allow user to remove sysex response handler such as one previously set through board.sysexResponse(commandByte, handler).
### Encode/Decode
Expand Down
10 changes: 10 additions & 0 deletions test/unit/firmata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3638,6 +3638,16 @@ describe("Board: lifecycle", function() {
done();
});

it("allows clearing handler for SYSEX_RESPONSE command byte", function(done) {
Board.SYSEX_RESPONSE[0xFF] = function() {};

board.clearSysexResponse(0xFF);

assert.doesNotThrow(function() {
board.sysexResponse(0xFF);
});
done();
});
});

describe("parser", function() {
Expand Down

0 comments on commit d08665e

Please sign in to comment.