Skip to content

Commit

Permalink
Pin: add isHigh, isLow properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Oct 5, 2015
1 parent deeef15 commit 90c58d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ function Pin(opts) {
if (this.mode === 0 || this.mode === 2) {
read(this);
}

if (type === "digital") {
Object.defineProperties(this, {
isHigh: {
get: function() {
return !!state.value;
}
},
isLow: {
get: function() {
return !state.value;
}
},
});
}
}


Expand Down
6 changes: 4 additions & 2 deletions test/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ exports["Pin"] = {
},

high: function(test) {
test.expect(2);
test.expect(3);

this.digital.high();
test.ok(this.digitalWrite.calledWith(11, 1));
test.equal(this.digital.isHigh, true);

this.analog.high();
test.ok(this.analogWrite.calledWith(1, 255));
Expand All @@ -175,10 +176,11 @@ exports["Pin"] = {
},

low: function(test) {
test.expect(2);
test.expect(3);

this.digital.low();
test.ok(this.digitalWrite.calledWith(11, 0));
test.equal(this.digital.isLow, true);

this.analog.low();
test.ok(this.analogWrite.calledWith(1, 0));
Expand Down

0 comments on commit 90c58d2

Please sign in to comment.