From 2b1df96fe10458ef89af5ec2b820db823ea75666 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 17 Jul 2019 14:31:39 -0400 Subject: [PATCH] Board.prototype.RESOLUTION.PWM = 255; This was missing and broke Johnny-Five's Led writes. --- lib/index.js | 21 +++++++++++---------- test/index.js | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/index.js b/lib/index.js index a8e8539..d015f80 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { @@ -668,6 +668,7 @@ class Board extends Emitter { get RESOLUTION() { return { ADC: ADC_RESOLUTION >> 2, + PWM: 255, }; } @@ -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)) { diff --git a/test/index.js b/test/index.js index 92cc7c4..1ff1e9e 100644 --- a/test/index.js +++ b/test/index.js @@ -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(); }, };