Skip to content

Commit

Permalink
RangeError: apply where appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <[email protected]>
  • Loading branch information
rwaldron committed Mar 25, 2016
1 parent 28ca7f7 commit 630da70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions node/tessel-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ Tessel.I2C = function(params) {
// Can actually go up to 4mhz without clk modification
if (value !== 1e5 && value !== 4e5) {
// http://asf.atmel.com/docs/3.15.0/samd21/html/group__asfdoc__sam0__sercom__i2c__group.html#gace1e0023f2eee92565496a2e30006548
throw new Error('I2C frequency must be 100kHz or 400kHz');
throw new RangeError('I2C frequency must be 100kHz or 400kHz');
}

frequency = value;
Expand Down Expand Up @@ -740,8 +740,8 @@ Tessel.SPI = function(params, port) {
this.clockSpeed = params.clockSpeed ? params.clockSpeed : 2e6;

// if speed is slower than 93750 then we need a clock divisor
if (this.clockSpeed > 24e6 || this.clockSpeed < 368) {
throw new Error('SPI Clock needs to be between 24e6 and 368Hz.');
if (this.clockSpeed < 368 || this.clockSpeed > 24e6) {
throw new RangeError('SPI clock must be between 368Hz and 24MHz');
}

this._clockReg = Math.floor(48e6 / (2 * this.clockSpeed) - 1);
Expand Down
22 changes: 20 additions & 2 deletions node/test/unit/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1520,14 +1520,14 @@ exports['Tessel.I2C'] = {
freq: 4e5 + 1,
port: this.port,
});
});
}, RangeError);
test.throws(() => {
new Tessel.I2C({
addr: 0x04,
freq: 1e5 - 1,
port: this.port,
});
});
}, RangeError);

test.done();
},
Expand Down Expand Up @@ -1850,6 +1850,24 @@ exports['Tessel.SPI'] = {
test.done();
},

clockSpeedRangeError: function(test) {
test.expect(2);

test.throws(() => {
new this.port.SPI({
clockSpeed: 368 - 1
});
}, RangeError);

test.throws(() => {
new this.port.SPI({
clockSpeed: 24e6 + 1
});
}, RangeError);

test.done();
},

oneSPIAtATime: function(test) {
test.expect(4);

Expand Down

0 comments on commit 630da70

Please sign in to comment.