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

Fix for #1499 #1503

Merged
merged 1 commit into from
Sep 18, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ Collection.installMethodForwarding(
*/
Servos.prototype[Animation.normalize] = function(keyFrameSet) {
return keyFrameSet.map(function(keyFrames, index) {
if (keyFrames !== null) {
if (keyFrames !== null && Array.isArray(keyFrames)) {
var servo = this[index];

// If servo is a servoArray then user servo[0] for default values
Expand All @@ -642,9 +642,13 @@ Servos.prototype[Animation.normalize] = function(keyFrameSet) {
};
}
}

return this[index][Animation.normalize](keyFrames);
}

if (keyFrames && typeof keyFrames.degrees === "number") {
keyFrames.value = keyFrames.degrees;
delete keyFrames.degrees;
}
return keyFrames;
}, this);
};
Expand Down
10 changes: 5 additions & 5 deletions test/extended/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ exports["Servo"] = {

this.servo.on("move:complete", function() {
test.equal(this.servo.position, 0);
test.ok(this.servoWrite.callCount === 101);
test.ok(this.servoWrite.callCount === 101, "Expected 101 calls to servoWrite. Saw " + this.servoWrite.callCount);
test.done();
}.bind(this));
},
Expand Down Expand Up @@ -144,7 +144,7 @@ exports["Servo"] = {

this.servo.on("move:complete", function() {
test.equal(this.servo.position, 0);
test.ok(this.servoWrite.callCount === 101);
test.ok(this.servoWrite.callCount === 101, "Expected 101 calls to servoWrite. Saw " + this.servoWrite.callCount);
test.done();
}.bind(this));
},
Expand All @@ -163,7 +163,7 @@ exports["Servo"] = {

this.servo.on("move:complete", function() {
test.equal(this.servo.position, 180);
test.ok(this.servoWrite.callCount === 101);
test.ok(this.servoWrite.callCount === 101, "Expected 101 calls to servoWrite. Saw " + this.servoWrite.callCount);
test.done();
}.bind(this));
},
Expand Down Expand Up @@ -217,7 +217,7 @@ exports["Servo"] = {

this.servo.on("move:complete", function() {
test.equal(this.servo.value, 80);
test.equal(this.servoWrite.lastCall.args[1], 70);
test.equal(this.servoWrite.lastCall.args[1], 1300);
test.done();
}.bind(this));

Expand All @@ -237,7 +237,7 @@ exports["Servo"] = {

this.servo.on("move:complete", function() {
test.equal(this.servo.value, 80);
test.equal(this.servoWrite.lastCall.args[1], 110);
test.equal(this.servoWrite.lastCall.args[1], 1700);
test.done();
}.bind(this));

Expand Down
53 changes: 53 additions & 0 deletions test/servo.collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ exports["Servo.Collection"] = {
pin: 9,
board: this.board
});

this.d = new Servo({
pin: 11,
board: this.board
});

this.spies = [
"to", "stop"
Expand Down Expand Up @@ -127,6 +132,54 @@ exports["Servo.Collection"] = {
test.done();
},

"Animation.normalize-nested": function(test) {
test.expect(1);

var group1 = new Servos([
this.a, this.b
]);

var group2 = new Servos([
this.c, this.d
]);

var bothGroups = new Servos([
group1, group2
]);

var normalized = bothGroups[Animation.normalize]([
[
[
null,
10,
]
],
[
[
null,
20,
]
]
]);

test.deepEqual(normalized, [
[
[
{ value: 90, easing: "linear" },
{ step: 10, easing: "linear" }
]
],
[
[
{ value: 90, easing: "linear" },
{ step: 20, easing: "linear" }
]
]
]);

test.done();
},

"Animation.normalize": function(test) {
test.expect(3);

Expand Down
48 changes: 48 additions & 0 deletions test/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,54 @@ exports["Servo"] = {
test.done();
},

"Animation.normalize (degrees instead of value)": function(test) {
test.expect(1);

this.servo = new Servo({
board: this.board,
pin: 11,
});

var normalized = this.servo[Animation.normalize]([
null,
{degrees: 0},
]);

test.equal(normalized[1].value, 0);

test.done();
},

"Animation.normalize (nested degrees instead of value)": function(test) {
test.expect(2);

this.servos = new Servos([
{
board: this.board,
pin: 11,
}, {
board: this.board,
pin: 12,
}
]);

var normalized = this.servos[Animation.normalize]([
[
null,
{degrees: 0}
],
[
null,
{degrees: 180}
],
]);

test.equal(normalized[0][1].value, 0);
test.equal(normalized[1][1].value, 180);

test.done();
},

"Animation.render": function(test) {
test.expect(2);

Expand Down