diff --git a/lib/animation.js b/lib/animation.js index 90ef1c00c..847b36040 100644 --- a/lib/animation.js +++ b/lib/animation.js @@ -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 */ @@ -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) { @@ -483,6 +483,8 @@ Animation.prototype.tweenedValue = function(indices, progress) { return result; }; +Animation.prototype + // Make sure our keyframes conform to a standard Animation.prototype.normalizeKeyframes = function() { diff --git a/lib/servo.js b/lib/servo.js index 7ef405d38..d8149f3e5 100644 --- a/lib/servo.js +++ b/lib/servo.js @@ -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 @@ -645,7 +645,14 @@ Servos.prototype[Animation.normalize] = function(keyFrameSet) { return this[index][Animation.normalize](keyFrames); } + + if (typeof keyFrames.degrees === "number") { + keyFrames.value = keyFrames.degrees; + delete keyFrames.degrees; + } + return keyFrames; + }, this); }; diff --git a/test/extended/servo.js b/test/extended/servo.js index 328ed972a..a52b466d0 100644 --- a/test/extended/servo.js +++ b/test/extended/servo.js @@ -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)); }, @@ -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)); }, @@ -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)); @@ -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)); diff --git a/test/servo.collection.js b/test/servo.collection.js index 8a29c9d27..0ba2039ff 100644 --- a/test/servo.collection.js +++ b/test/servo.collection.js @@ -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" @@ -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);