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

Make baud property settable. #1082

Merged
merged 1 commit into from
Apr 8, 2016
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: 5 additions & 3 deletions lib/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ var Chips = {

DEFAULT: {
baud: {
value: 9600
value: 9600,
writable: true
},
configure: {
value: function(callback) {
Expand All @@ -53,7 +54,8 @@ var Chips = {
*/
MT3339: {
baud: {
value: 9600
value: 9600,
writable: true
},
configure: {
value: function(callback) {
Expand Down Expand Up @@ -189,7 +191,7 @@ function GPS(opts) {

// If necessary set default property values
this.fixed = opts.fixed || 6;
this.baud = opts.baud || breakout.baud || chip.baud;
this.baud = opts.baud || this.baud;

// Create a "state" entry for privately
// storing the state of the instance
Expand Down
88 changes: 66 additions & 22 deletions test/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,13 @@ function restore(target) {
}
}

exports["Chip -- MT3339"] = {

exports["general"] = {
setUp: function(done) {
this.board = newBoard();
this.clock = sinon.useFakeTimers();
this.serialConfig = sinon.spy(MockFirmata.prototype, "serialConfig");
this.serialWrite = sinon.spy(MockFirmata.prototype, "serialWrite");
this.serialRead = sinon.spy(MockFirmata.prototype, "serialRead");

this.gps = new GPS({
chip: "MT3339",
pins: {
tx: 10,
rx: 11
},
board: this.board
});

this.proto = [{
name: "configure"
}, {
name: "restart"
}, {
name: "initialize"
}, {
Expand All @@ -74,8 +59,6 @@ exports["Chip -- MT3339"] = {

this.instance = [{
name: "baud"
}, {
name: "frequency"
}, {
name: "fixed"
}, {
Expand All @@ -102,17 +85,78 @@ exports["Chip -- MT3339"] = {
shape: function(test) {
test.expect(this.proto.length + this.instance.length);

var gps = new GPS({
pins: {
tx: 10,
rx: 11
},
board: this.board
});

this.proto.forEach(function(method) {
test.equal(typeof this.gps[method.name], "function");
}, this);
test.equal(typeof gps[method.name], "function");
});

this.instance.forEach(function(property) {
test.notEqual(typeof this.gps[property.name], "undefined");
}, this);
test.notEqual(typeof gps[property.name], "undefined");
});

test.done();
},

useCustomBaud: function(test) {
test.expect(1);

var gps = new GPS({
pins: {
tx: 10,
rx: 11
},
baud: 4800,
board: this.board
});

test.deepEqual(this.serialConfig.args[0][0], {
portId: 8,
baud: 4800,
rxPin: 11,
txPin: 10
});

gps = null;
this.serialConfig.reset();
test.done();
}

};

exports["Chip -- MT3339"] = {

setUp: function(done) {
this.board = newBoard();
this.clock = sinon.useFakeTimers();
this.serialConfig = sinon.spy(MockFirmata.prototype, "serialConfig");
this.serialWrite = sinon.spy(MockFirmata.prototype, "serialWrite");
this.serialRead = sinon.spy(MockFirmata.prototype, "serialRead");

this.gps = new GPS({
chip: "MT3339",
pins: {
tx: 10,
rx: 11
},
board: this.board
});

done();
},

tearDown: function(done) {
Board.purge();
restore(this);
done();
},

useDefaultPort: function(test) {
test.expect(1);

Expand Down