Skip to content

Commit

Permalink
Make symbols more obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jan 15, 2019
1 parent d0e7a31 commit 85e4c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 13 additions & 14 deletions packages/firmata-io/lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ const SYSTEM_RESET = 0xFF;

const MAX_PIN_COUNT = 128;


const sendOneWireSearch = Symbol("sendOneWireSearch");
const sendOneWireRequest = Symbol("sendOneWireRequest");
const SYM_sendOneWireSearch = Symbol("sendOneWireSearch");
const SYM_sendOneWireRequest = Symbol("sendOneWireRequest");

/**
* MIDI_RESPONSE contains functions to be called when we receive a MIDI message from the arduino.
Expand Down Expand Up @@ -1486,7 +1485,7 @@ class Firmata extends Emitter {
*/

sendOneWireSearch(pin, callback) {
this[sendOneWireSearch](
this[SYM_sendOneWireSearch](
ONEWIRE_SEARCH_REQUEST,
`1-wire-search-reply-${pin}`,
pin,
Expand All @@ -1502,15 +1501,15 @@ class Firmata extends Emitter {
*/

sendOneWireAlarmsSearch(pin, callback) {
this[sendOneWireSearch](
this[SYM_sendOneWireSearch](
ONEWIRE_SEARCH_ALARMS_REQUEST,
`1-wire-search-alarms-reply-${pin}`,
pin,
callback
);
}

[sendOneWireSearch](type, event, pin, callback) {
[SYM_sendOneWireSearch](type, event, pin, callback) {
writeToTransport(this, [
START_SYSEX,
ONEWIRE_DATA,
Expand Down Expand Up @@ -1546,7 +1545,7 @@ class Firmata extends Emitter {
/* istanbul ignore next */
callback(new Error("1-Wire device read timeout - are you running ConfigurableFirmata?"));
}, 5000);
this[sendOneWireRequest](
this[SYM_sendOneWireRequest](
pin,
ONEWIRE_READ_REQUEST_BIT,
device,
Expand All @@ -1568,7 +1567,7 @@ class Firmata extends Emitter {
*/

sendOneWireReset(pin) {
this[sendOneWireRequest](
this[SYM_sendOneWireRequest](
pin,
ONEWIRE_RESET_REQUEST_BIT
);
Expand All @@ -1585,7 +1584,7 @@ class Firmata extends Emitter {
*/

sendOneWireWrite(pin, device, data) {
this[sendOneWireRequest](
this[SYM_sendOneWireRequest](
pin,
ONEWIRE_WRITE_REQUEST_BIT,
device,
Expand All @@ -1603,7 +1602,7 @@ class Firmata extends Emitter {
*/

sendOneWireDelay(pin, delay) {
this[sendOneWireRequest](
this[SYM_sendOneWireRequest](
pin,
ONEWIRE_DELAY_REQUEST_BIT,
null,
Expand Down Expand Up @@ -1632,7 +1631,7 @@ class Firmata extends Emitter {
/* istanbul ignore next */
callback(new Error("1-Wire device read timeout - are you running ConfigurableFirmata?"));
}, 5000);
this[sendOneWireRequest](
this[SYM_sendOneWireRequest](
pin,
ONEWIRE_WRITE_REQUEST_BIT | ONEWIRE_READ_REQUEST_BIT,
device,
Expand All @@ -1649,7 +1648,7 @@ class Firmata extends Emitter {
}

// see http://firmata.org/wiki/Proposals#OneWire_Proposal
[sendOneWireRequest](pin, subcommand, device, numBytesToRead, correlationId, delay, dataToWrite, event, callback) {
[SYM_sendOneWireRequest](pin, subcommand, device, numBytesToRead, correlationId, delay, dataToWrite, event, callback) {
const bytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

if (device || numBytesToRead || correlationId || delay || dataToWrite) {
Expand Down Expand Up @@ -2670,8 +2669,8 @@ if (process.env.IS_TEST_MODE) {
writeToTransport,

symbols: {
sendOneWireRequest,
sendOneWireSearch,
SYM_sendOneWireRequest,
SYM_sendOneWireSearch,
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/firmata.js/test/unit/firmata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2480,10 +2480,10 @@ describe("Board: lifecycle", function() {
transport.emit("data", [START_SYSEX, PULSE_OUT, ONEWIRE_SEARCH_ALARMS_REPLY, ONEWIRE_RESET_REQUEST_BIT, 0x28, 0x36, 0x3F, 0x0F, 0x52, 0x00, 0x00, 0x00, 0x5D, 0x00, END_SYSEX]);
});
it("must be able to send a 1-wire write read", done => {
sandbox.spy(board, Board.test.symbols.sendOneWireRequest);
sandbox.spy(board, Board.test.symbols.SYM_sendOneWireRequest);
board.sendOneWireRead(1, 1, 1, () => {});

board[Board.test.symbols.sendOneWireRequest].lastCall.args[8]();
board[Board.test.symbols.SYM_sendOneWireRequest].lastCall.args[8]();
done();
});
it("must be able to send a 1-wire reset request", done => {
Expand Down

0 comments on commit 85e4c7d

Please sign in to comment.