From 347291486490962638f04ef4d6ea32e0947e6578 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 27 Jan 2016 10:40:58 -0800 Subject: [PATCH 1/2] Turn on/off main LED during calibration operations --- lib/devices/custom.js | 10 ++++++++-- spec/lib/devices/custom.spec.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/devices/custom.js b/lib/devices/custom.js index c6f5182..47432dc 100644 --- a/lib/devices/custom.js +++ b/lib/devices/custom.js @@ -264,8 +264,13 @@ module.exports = function custom(device) { * @return {void} */ device.startCalibration = function(callback) { - device.setBackLed(127); - device.setStabilization(0, callback); + device.originalColor = 0; + device.getColor(function(data) { + device.originalColor = data.color; + device.setRgbLed(0); + device.setBackLed(127); + device.setStabilization(0, callback); + }); }; /** @@ -281,6 +286,7 @@ module.exports = function custom(device) { device.finishCalibration = function(callback) { device.setHeading(0); device.setBackLed(0); + device.setRgbLed(device.originalColor); device.setStabilization(1, callback); }; diff --git a/spec/lib/devices/custom.spec.js b/spec/lib/devices/custom.spec.js index 5cb847e..315c44a 100644 --- a/spec/lib/devices/custom.spec.js +++ b/spec/lib/devices/custom.spec.js @@ -148,6 +148,7 @@ describe("Custom Device Functions", function() { beforeEach(function() { device.setStabilization = spy(); device.setBackLed = stub(); + device.getColor = stub().yields({color: 0xff00ff}); device.startCalibration(); }); @@ -159,6 +160,10 @@ describe("Custom Device Functions", function() { it("turns on the back LED", function() { expect(device.setBackLed).to.be.calledWith(127); }); + + it("turns off the main LED", function() { + expect(device.setRgbLed).to.be.calledWith(0); + }); }); describe("#finishCalibration", function() { @@ -166,6 +171,7 @@ describe("Custom Device Functions", function() { device.setStabilization = spy(); device.setHeading = spy(); device.setBackLed = stub(); + device.setRgbLed = stub(); device.finishCalibration(); }); @@ -181,6 +187,10 @@ describe("Custom Device Functions", function() { it("turns off the back LED", function() { expect(device.setBackLed).to.be.calledWith(0); }); + + it("turns on the main LED again using original color", function() { + expect(device.setRgbLed).to.be.calledWith(0xff00ff); + }); }); describe("#streamData", function() { From 9f51b0ba4963f4ba8aebc3f275adcb632bec341b Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 27 Jan 2016 11:08:36 -0800 Subject: [PATCH 2/2] Handle error case when calibrating --- lib/devices/custom.js | 6 +++++- spec/lib/devices/custom.spec.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/devices/custom.js b/lib/devices/custom.js index 47432dc..96189c2 100644 --- a/lib/devices/custom.js +++ b/lib/devices/custom.js @@ -265,7 +265,11 @@ module.exports = function custom(device) { */ device.startCalibration = function(callback) { device.originalColor = 0; - device.getColor(function(data) { + device.getColor(function(err, data) { + if (err) { + callback(err, null); + } + device.originalColor = data.color; device.setRgbLed(0); device.setBackLed(127); diff --git a/spec/lib/devices/custom.spec.js b/spec/lib/devices/custom.spec.js index 315c44a..30a5ab5 100644 --- a/spec/lib/devices/custom.spec.js +++ b/spec/lib/devices/custom.spec.js @@ -148,7 +148,7 @@ describe("Custom Device Functions", function() { beforeEach(function() { device.setStabilization = spy(); device.setBackLed = stub(); - device.getColor = stub().yields({color: 0xff00ff}); + device.getColor = stub().yields(null, {color: 0xff00ff}); device.startCalibration(); });