Skip to content

Commit

Permalink
Merge pull request #1082 from dtex/baud-rate
Browse files Browse the repository at this point in the history
Make baud property writable.
  • Loading branch information
dtex committed Apr 8, 2016
2 parents fe1f211 + a4108a5 commit 83ddd86
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 25 deletions.
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

0 comments on commit 83ddd86

Please sign in to comment.