Skip to content

Commit

Permalink
Board.prototype.RESOLUTION.PWM = 255;
Browse files Browse the repository at this point in the history
This was missing and broke Johnny-Five's Led writes.
  • Loading branch information
rwaldron committed Jul 17, 2019
1 parent 8479708 commit 2b1df96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ class Pin extends Emitter {

servoConfig(min, max) {
const state = priv.get(this);

if (SERVO_PINS.includes(state.index)) {
this.mode = MODES.SERVO;
state.servoMin = min / (1e6 / SERVO_FREQUENCY);
state.servoMax = max / (1e6 / SERVO_FREQUENCY);
}

}

write(value) {
Expand Down Expand Up @@ -668,6 +668,7 @@ class Board extends Emitter {
get RESOLUTION() {
return {
ADC: ADC_RESOLUTION >> 2,
PWM: 255,
};
}

Expand Down Expand Up @@ -779,41 +780,41 @@ class Board extends Emitter {

servoConfig(pin, min, max) {
const state = priv.get(this);

if (typeof pin === "object" && pin !== null) {
let temp = pin;
pin = temp.pin;
min = temp.min;
max = temp.max;
}

if (typeof pin === "undefined") {
throw new Error("servoConfig: pin must be specified");
}

if (typeof min === "undefined") {
throw new Error("servoConfig: min must be specified");
}

if (typeof max === "undefined") {
throw new Error("servoConfig: max must be specified");
}

const index = ToPinIndex(pin);
this.pins[index].servoConfig(min, max);

}

servoWrite(pin, value) {
const state = priv.get(this);
const index = ToPinIndex(pin);

if (value < 544) {
value = scale(constrain(value, 0, 180), 0, 180, this.pins[index].servoMin, this.pins[index].servoMax);
} else {
value = constrain(value / (1e6 / SERVO_FREQUENCY), this.pins[index].servoMin, this.pins[index].servoMax);
}

// All but the last pin, which is a high frequency DAC
/* istanbul ignore else */
if (SERVO_PINS.includes(index)) {
Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ exports["Board.prototype"] = {
test.done();
},
resolution(test) {
test.expect(1);
test.expect(2);
test.equal(Board.prototype.RESOLUTION.ADC, 1024);
test.equal(Board.prototype.RESOLUTION.PWM, 255);
test.done();
},
};
Expand Down

0 comments on commit 2b1df96

Please sign in to comment.