Skip to content

Commit

Permalink
Normalize pin values on components that use expanders
Browse files Browse the repository at this point in the history
Re: [this
comment](#943 (comment)
52048671)

We need something like this. It is incomplete (it doesn’t handle pin
arrays). Thoughts?
  • Loading branch information
dtex committed Oct 29, 2015
1 parent 94eb633 commit c80958c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 deletions.
2 changes: 2 additions & 0 deletions lib/esc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var Controllers = {
pwmRange: this.pwmRange,
frequency: 50, // Hz
});

this.pin = state.expander.normalize(opts.pin);
}
},
write: {
Expand Down
22 changes: 0 additions & 22 deletions lib/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,34 +661,17 @@ var Controllers = {
},
digitalWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

this.pwmWrite(pin, value ? 255 : 0);
}
},
analogWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

this.pwmWrite(pin, value);
}
},
servoWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

value = Board.constrain(value, 0, 180);

var off = __.map(value, 0, 180, this.pwmRange[0] / 4, this.pwmRange[1] / 4);
Expand All @@ -703,11 +686,6 @@ var Controllers = {
pwmWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

if (this.pins[pin] === undefined) {
throw new RangeError("Invalid PCA9685 pin: " + pin);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/led/led.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var Controllers = {

this.pin = typeof opts.pin === "undefined" ? 0 : opts.pin;

this.pin = state.expander.normalize(opts.pin);

state.mode = this.io.MODES.PWM;
}
},
Expand Down
2 changes: 2 additions & 0 deletions lib/led/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var Controllers = {

this.pin = typeof opts.pin === "undefined" ? 0 : opts.pin;

this.pin = state.expander.normalize(opts.pin);

state.mode = this.io.MODES.PWM;
}
},
Expand Down
2 changes: 2 additions & 0 deletions lib/motor.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ var Controllers = {
pwmRange: this.pwmRange,
frequency: 50, // Hz
});

this.pin = state.expander.normalize(opts.pin);
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions lib/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var Controllers = {
pwmRange: this.pwmRange,
frequency: 50, // Hz
});

this.pin = state.expander.normalize(opts.pin);
}
},
servoWrite: {
Expand Down

0 comments on commit c80958c

Please sign in to comment.