Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DigitalWrite with tests #33931

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/src/lib/kits/maker/MicroBitBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export default class MicroBitBoard extends EventEmitter {
this.boardClient_.setPinMode(pin, modeConstant);
}

// TODO
digitalWrite(pin, value) {}
digitalWrite(pin, value) {
this.boardClient_.digitalWrite(pin, value);
}

// TODO
digitalRead(pin, callback) {
Expand Down
7 changes: 6 additions & 1 deletion apps/src/third-party/maker/MBFirmataClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,12 @@ class MicrobitFirmataClient {

if ((pinNum < 0) || (pinNum > 20)) return;
this.myPort.write([this.SET_PIN_MODE, pinNum, this.DIGITAL_OUTPUT]);
this.myPort.write([this.SET_DIGITAL_PIN, pinNum, (turnOn ? 1 : 0)]);
this.digitalWrite(pinNum, (turnOn ? 1 : 0));
}

digitalWrite(pin, value){
if ((pin < 0) || (pin > 20)) return;
this.myPort.write([this.SET_DIGITAL_PIN, pin, value]);
}

setAnalogOutput(pinNum, level) {
Expand Down
12 changes: 12 additions & 0 deletions apps/test/unit/lib/kits/maker/MicroBitBoardTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ describe('MicroBitBoard', () => {
});
});

describe(`digitalWrite(pin, value)`, () => {
it('forwards the call to firmata', () => {
return board.connect().then(() => {
let digitalWriteSpy = sinon.spy(board.boardClient_, 'digitalWrite');
const pin = 11;
const arg2 = 1023;
board.digitalWrite(pin, arg2);
expect(digitalWriteSpy).to.have.been.calledWith(pin, arg2);
});
});
});

describe(`reset()`, () => {
it('triggers a component cleanup', () => {
return board.connect().then(() => {
Expand Down
2 changes: 2 additions & 0 deletions apps/test/unit/lib/kits/maker/makeStubBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class MicrobitStubBoard {

setPinMode(pinNum, mode) {}

digitalWrite(pinNum, value) {}

displayPlot() {}

displayClear() {}
Expand Down