Skip to content

Commit

Permalink
Merge pull request sphero-inc#60 from orbotix/bugfix/calibration-led
Browse files Browse the repository at this point in the history
LGTM. Merged.
  • Loading branch information
dportalesr committed Jan 27, 2016
2 parents c5a50ed + 9f51b0b commit 6a07ceb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/devices/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,17 @@ module.exports = function custom(device) {
* @return {void}
*/
device.startCalibration = function(callback) {
device.setBackLed(127);
device.setStabilization(0, callback);
device.originalColor = 0;
device.getColor(function(err, data) {
if (err) {
callback(err, null);
}

device.originalColor = data.color;
device.setRgbLed(0);
device.setBackLed(127);
device.setStabilization(0, callback);
});
};

/**
Expand All @@ -281,6 +290,7 @@ module.exports = function custom(device) {
device.finishCalibration = function(callback) {
device.setHeading(0);
device.setBackLed(0);
device.setRgbLed(device.originalColor);
device.setStabilization(1, callback);
};

Expand Down
10 changes: 10 additions & 0 deletions spec/lib/devices/custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe("Custom Device Functions", function() {
beforeEach(function() {
device.setStabilization = spy();
device.setBackLed = stub();
device.getColor = stub().yields(null, {color: 0xff00ff});

device.startCalibration();
});
Expand All @@ -159,13 +160,18 @@ 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() {
beforeEach(function() {
device.setStabilization = spy();
device.setHeading = spy();
device.setBackLed = stub();
device.setRgbLed = stub();

device.finishCalibration();
});
Expand All @@ -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() {
Expand Down

0 comments on commit 6a07ceb

Please sign in to comment.