Skip to content

Commit

Permalink
Merge d4f1554 into d796366
Browse files Browse the repository at this point in the history
  • Loading branch information
dtex committed Sep 16, 2018
2 parents d796366 + d4f1554 commit 2af1935
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Animation.prototype.tweenedValue = function(indices, progress) {
// Find our progress for the current tween
tween.duration = this.cuePoints[memberIndices.right] - this.cuePoints[memberIndices.left];
tween.progress = (progress - this.cuePoints[memberIndices.left]) / tween.duration;

// Catch divide by zero
if (!Number.isFinite(tween.progress)) {
/* istanbul ignore next */
Expand All @@ -459,7 +459,7 @@ Animation.prototype.tweenedValue = function(indices, progress) {

// Calculate this tween value
var calcValue;

if (right.position) {
// This is a tuple
calcValue = right.position.map(function(value, index) {
Expand Down
12 changes: 10 additions & 2 deletions lib/servo.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Servo.prototype[Animation.normalize] = function(keyFrames) {
step: value,
};
} else {
if (typeof frame.degrees === "number") {
if (typeof frame.degrees === "number") {
frame.value = frame.degrees;
delete frame.degrees;
}
Expand Down 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 @@ -644,8 +644,16 @@ 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 - 100 <= 1);
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 - 100 <= 1);
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

0 comments on commit 2af1935

Please sign in to comment.