Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jshint all the things and add grunt

  • Loading branch information...
commit fb011708a604ef7b0ec83d0c54171d7a96e66d20 1 parent ab79738
@jgautier authored
View
14 examples/blink.js
@@ -10,8 +10,8 @@ var ledPin = 13;
var firmata = require('../lib/firmata');
var board = new firmata.Board('/dev/tty.usbmodemfd121', function(err) {
if (err) {
- console.log(err);
- return;
+ console.log(err);
+ return;
}
console.log('connected');
@@ -23,16 +23,16 @@ var board = new firmata.Board('/dev/tty.usbmodemfd121', function(err) {
setInterval(function(){
if (ledOn) {
- console.log('+');
- board.digitalWrite(ledPin, board.HIGH);
+ console.log('+');
+ board.digitalWrite(ledPin, board.HIGH);
}
else {
- console.log('-');
- board.digitalWrite(ledPin, board.LOW);
+ console.log('-');
+ board.digitalWrite(ledPin, board.LOW);
}
ledOn = !ledOn;
- },500)
+ },500);
});
View
4 examples/k22.js
@@ -16,11 +16,11 @@ var board = new Board('/dev/tty.usbmodemfa131',function(){
ppms = ppms << 8;
ppms |= data[2] & 0xFF;
var checksum = data[0] + data[1] + data[2];
- if(checksum == data[3]){
+ if(checksum === data[3]){
console.log('Current PPMs: '+ppms);
} else {
console.log('Checksum failure');
}
});
},2000);
-});
+});
View
4 examples/servosweep.js
@@ -13,5 +13,5 @@ var board = new Board('/dev/tty.usbmodemfa131', function() {
}
degrees += incrementer;
board.servoWrite(9,degrees);
- },500)
-});
+ },500);
+});
View
116 lib/firmata.js
@@ -92,7 +92,7 @@ MIDI_RESPONSE[DIGITAL_MESSAGE] = function(board) {
for (var i = 0; i < 8; i++) {
var pinNumber = 8 * port + i;
var pin = board.pins[pinNumber];
- if (pin && (pin.mode == board.MODES.INPUT)) {
+ if (pin && (pin.mode === board.MODES.INPUT)) {
pin.value = (portValue >> (i & 0x07)) & 0x01;
board.emit('digital-read-' + pinNumber, pin.value);
board.emit('digital-read', {
@@ -140,15 +140,17 @@ SYSEX_RESPONSE[QUERY_FIRMWARE] = function(board) {
SYSEX_RESPONSE[CAPABILITY_RESPONSE] = function(board) {
var supportedModes = 0;
- var modesArray;
+
+ function pushModes(modesArray, mode) {
+ if (supportedModes & (1 << board.MODES[mode])) {
+ modesArray.push(board.MODES[mode]);
+ }
+ }
+
for (var i = 2, n = 0; i < board.currentBuffer.length - 1; i++) {
- if (board.currentBuffer[i] == 127) {
- modesArray = [];
- Object.keys(board.MODES).forEach(function(mode) {
- if (supportedModes & (1 << board.MODES[mode])) {
- modesArray.push(board.MODES[mode]);
- }
- });
+ if (board.currentBuffer[i] === 127) {
+ var modesArray = [];
+ Object.keys(board.MODES).forEach(pushModes.bind(null, modesArray));
board.pins.push({
supportedModes: modesArray,
mode: board.MODES.OUTPUT,
@@ -197,7 +199,7 @@ SYSEX_RESPONSE[ANALOG_MAPPING_RESPONSE] = function(board) {
for (var i = 2; i < board.currentBuffer.length - 1; i++) {
currentValue = board.currentBuffer[i];
board.pins[pin].analogChannel = currentValue;
- if (currentValue != 127) {
+ if (currentValue !== 127) {
board.analogPins.push(pin);
}
pin++;
@@ -237,15 +239,15 @@ SYSEX_RESPONSE[STRING_DATA] = function(board) {
SYSEX_RESPONSE[PULSE_IN] = function(board){
var pin = (board.currentBuffer[2] & 0x7F) | ((board.currentBuffer[3] & 0x7F) << 7);
var durationBuffer = [
- (board.currentBuffer[4] & 0x7F) | ((board.currentBuffer[5] & 0x7F) << 7)
- ,(board.currentBuffer[6] & 0x7F) | ((board.currentBuffer[7] & 0x7F) << 7)
- ,(board.currentBuffer[8] & 0x7F) | ((board.currentBuffer[9] & 0x7F) << 7)
- ,(board.currentBuffer[10] & 0x7F) | ((board.currentBuffer[11] & 0x7F) << 7)
+ (board.currentBuffer[4] & 0x7F) | ((board.currentBuffer[5] & 0x7F) << 7),
+ (board.currentBuffer[6] & 0x7F) | ((board.currentBuffer[7] & 0x7F) << 7),
+ (board.currentBuffer[8] & 0x7F) | ((board.currentBuffer[9] & 0x7F) << 7),
+ (board.currentBuffer[10] & 0x7F) | ((board.currentBuffer[11] & 0x7F) << 7)
];
- var duration = ( (durationBuffer[0] << 24)
- + (durationBuffer[1] << 16)
- + (durationBuffer[2] << 8)
- + (durationBuffer[3] ) );
+ var duration = ( (durationBuffer[0] << 24) +
+ (durationBuffer[1] << 16) +
+ (durationBuffer[2] << 8) +
+ (durationBuffer[3] ) );
board.emit('pulse-in-'+pin,duration);
};
/**
@@ -318,8 +320,8 @@ var Board = function(port, callback) {
board.currentBuffer.push(byt);
// [START_SYSEX, ... END_SYSEX]
- if (board.currentBuffer[0] == START_SYSEX &&
- board.currentBuffer[board.currentBuffer.length - 1] == END_SYSEX) {
+ if (board.currentBuffer[0] === START_SYSEX &&
+ board.currentBuffer[board.currentBuffer.length - 1] === END_SYSEX) {
SYSEX_RESPONSE[board.currentBuffer[1]](board);
board.currentBuffer.length = 0;
@@ -327,7 +329,7 @@ var Board = function(port, callback) {
// There are 3 bytes in the buffer and the first is not START_SYSEX:
// Might have a MIDI Command
- if (board.currentBuffer.length == 3 && board.currentBuffer[0] != START_SYSEX) {
+ if (board.currentBuffer.length === 3 && board.currentBuffer[0] !== START_SYSEX) {
//commands under 0xF0 we have a multi byte command
if (board.currentBuffer[0] < 240) {
cmd = board.currentBuffer[0] & 0xF0;
@@ -426,7 +428,9 @@ Board.prototype.digitalWrite = function(pin, value) {
var portValue = 0;
this.pins[pin].value = value;
for (var i = 0; i < 8; i++) {
- if (this.pins[8 * port + i].value) portValue |= (1 << i);
+ if (this.pins[8 * port + i].value) {
+ portValue |= (1 << i);
+ }
}
this.sp.write([DIGITAL_MESSAGE | port, portValue & 0x7F, (portValue >> 7) & 0x7F]);
};
@@ -478,7 +482,7 @@ Board.prototype.queryPinState = function(pin, callback) {
* @param {number} delay in microseconds to set for I2C Read
*/
Board.prototype.sendI2CConfig=function(delay){
- var delay = delay || 0;
+ delay = delay || 0;
this.sp.write([START_SYSEX,I2C_CONFIG,(delay & 0xFF),((delay >> 8) & 0xFF),END_SYSEX]);
};
@@ -488,9 +492,9 @@ Board.prototype.sendI2CConfig=function(delay){
* @param {Array} bytes The bytes to send to the device
*/
-Board.prototype.sendI2CWriteRequest = function(slaveAddress, bytes) {
- var bytes = bytes || [];
+Board.prototype.sendI2CWriteRequest = function(slaveAddress, bytes) {
var data = [];
+ bytes = bytes || [];
data.push(START_SYSEX);
data.push(I2C_REQUEST);
data.push(slaveAddress);
@@ -524,38 +528,40 @@ Board.prototype.pulseIn = function(opts, callback){
var pulseOut = opts.pulseOut || 0;
var timeout = opts.timeout || 1000000;
var pulseOutArray = [
- ((pulseOut >> 24) & 0xFF) ,
- ((pulseOut >> 16) & 0xFF) ,
- ((pulseOut >> 8) & 0XFF) ,
+ ((pulseOut >> 24) & 0xFF),
+ ((pulseOut >> 16) & 0xFF),
+ ((pulseOut >> 8) & 0XFF),
((pulseOut & 0xFF))
- ]
+ ];
var timeoutArray = [
- ((timeout >> 24) & 0xFF) ,
- ((timeout >> 16) & 0xFF) ,
- ((timeout >> 8) & 0XFF) ,
+ ((timeout >> 24) & 0xFF),
+ ((timeout >> 16) & 0xFF),
+ ((timeout >> 8) & 0XFF),
((timeout & 0xFF))
- ]
- var data = [START_SYSEX
- , PULSE_IN
- , pin
- , value
- , pulseOutArray[0] & 0x7F
- , (pulseOutArray[0] >> 7) & 0x7F
- , pulseOutArray[1] & 0x7F
- , (pulseOutArray[1] >> 7) & 0x7F
- , pulseOutArray[2] & 0x7F
- , (pulseOutArray[2] >> 7) & 0x7F
- , pulseOutArray[3] & 0x7F
- , (pulseOutArray[3] >> 7) & 0x7F
- , timeoutArray[0] & 0x7F
- , (timeoutArray[0] >> 7) & 0x7F
- , timeoutArray[1] & 0x7F
- , (timeoutArray[1] >> 7) & 0x7F
- , timeoutArray[2] & 0x7F
- , (timeoutArray[2] >> 7) & 0x7F
- , timeoutArray[3] & 0x7F
- , (timeoutArray[3] >> 7) & 0x7F
- , END_SYSEX];
+ ];
+ var data = [
+ START_SYSEX,
+ PULSE_IN,
+ pin,
+ value,
+ pulseOutArray[0] & 0x7F,
+ (pulseOutArray[0] >> 7) & 0x7F,
+ pulseOutArray[1] & 0x7F,
+ (pulseOutArray[1] >> 7) & 0x7F,
+ pulseOutArray[2] & 0x7F,
+ (pulseOutArray[2] >> 7) & 0x7F,
+ pulseOutArray[3] & 0x7F,
+ (pulseOutArray[3] >> 7) & 0x7F,
+ timeoutArray[0] & 0x7F,
+ (timeoutArray[0] >> 7) & 0x7F,
+ timeoutArray[1] & 0x7F,
+ (timeoutArray[1] >> 7) & 0x7F,
+ timeoutArray[2] & 0x7F,
+ (timeoutArray[2] >> 7) & 0x7F,
+ timeoutArray[3] & 0x7F,
+ (timeoutArray[3] >> 7) & 0x7F,
+ END_SYSEX
+ ];
this.sp.write(data);
this.once('pulse-in-'+pin,callback);
};
@@ -567,4 +573,4 @@ Board.prototype.reset = function(){
};
module.exports = {
Board: Board
-};
+};
View
5 package.json
@@ -14,7 +14,10 @@
},
"devDependencies": {
"mocha": ">=0.13.x",
- "should": ">=0.5.x"
+ "should": ">=0.5.x",
+ "grunt": "~0.4.1",
+ "grunt-contrib-jshint": "~0.4.3",
+ "grunt-mocha-test": "~0.2.2"
},
"dependencies": {
"serialport": ">=0.7.5"
View
3  test/MockSerialPort.js
@@ -1,5 +1,4 @@
-var util = require('util')
- ,events = require('events')
+var util = require('util'), events = require('events');
var MockSerialPort = function(path){
this.isClosed = false;
};
View
30 test/firmata.js
@@ -1,6 +1,4 @@
-var firmata = process.env.FIRMATA_COV
- ? require('../lib-cov/firmata')
- : require('../lib/firmata');
+var firmata = process.env.FIRMATA_COV ? require('../lib-cov/firmata') : require('../lib/firmata');
var SerialPort = require('./MockSerialPort').SerialPort;
var should = require('should');
describe('board',function(){
@@ -10,8 +8,8 @@ describe('board',function(){
'test error'.should.equal(err);
});
serialPort.emit('error','test error');
- var serialPort = new SerialPort('/path/to/fake/usb');
- var board = new firmata.Board(serialPort,function(err){
+ serialPort = new SerialPort('/path/to/fake/usb');
+ board = new firmata.Board(serialPort,function(err){
boardStarted = true;
(typeof err).should.equal('undefined');
});
@@ -156,7 +154,7 @@ describe('board',function(){
}
serialPort.once('data',function(){
board.pins[14].analogChannel.should.equal(0);
- board.pins[15].analogChannel.should.equal(1)
+ board.pins[15].analogChannel.should.equal(1);
board.pins[16].analogChannel.should.equal(2);
board.pins[17].analogChannel.should.equal(3);
board.pins[18].analogChannel.should.equal(4);
@@ -174,7 +172,7 @@ describe('board',function(){
});
it('should now be started',function(){
boardStarted.should.equal(true);
- })
+ });
it('should be able to set pin mode on digital pin',function(done){
board.pinMode(2,board.MODES.INPUT);
serialPort.lastWrite[0].should.equal(0xF4);
@@ -188,7 +186,7 @@ describe('board',function(){
var order = [1, 0, 1, 0];
board.digitalRead(2,function(value){
if (value === 1) {
- counter++
+ counter++;
}
if (value === 0) {
counter++;
@@ -226,7 +224,7 @@ describe('board',function(){
var order = [1023, 0, 1023, 0];
board.analogRead(1,function(value){
if (value === 1023) {
- counter++
+ counter++;
}
if (value === 0) {
counter++;
@@ -242,11 +240,11 @@ describe('board',function(){
// Single Byte
serialPort.emit('data',[0xE0 | (1 & 0xF)]);
serialPort.emit('data',[1023%128]);
- serialPort.emit('data',[1023>>7])
+ serialPort.emit('data',[1023>>7]);
serialPort.emit('data',[0xE0 | (1 & 0xF)]);
serialPort.emit('data',[0%128]);
- serialPort.emit('data',[0>>7])
+ serialPort.emit('data',[0>>7]);
// Multi Byte
serialPort.emit('data',[0xE0 | (1 & 0xF), 1023%128, 1023>>7]);
@@ -307,7 +305,7 @@ describe('board',function(){
data[3].should.equal(4);
done();
});
- serialPort.lastWrite[0].should.equal(0xF0)
+ serialPort.lastWrite[0].should.equal(0xF0);
serialPort.lastWrite[1].should.equal(0x76);
serialPort.lastWrite[2].should.equal(0x68);
serialPort.lastWrite[3].should.equal(1<<3);
@@ -424,7 +422,7 @@ describe('board',function(){
serialPort.lastWrite[17].should.equal(0);
serialPort.lastWrite[18].should.equal(64);
serialPort.lastWrite[19].should.equal(0);
- serialPort.lastWrite[20].should.equal(0xF7)
+ serialPort.lastWrite[20].should.equal(0xF7);
serialPort.emit('data',[0xF0]);
serialPort.emit('data',[0x74]);
serialPort.emit('data',[3]);
@@ -464,7 +462,7 @@ describe('board',function(){
serialPort.lastWrite[17].should.equal(0);
serialPort.lastWrite[18].should.equal(64);
serialPort.lastWrite[19].should.equal(0);
- serialPort.lastWrite[20].should.equal(0xF7)
+ serialPort.lastWrite[20].should.equal(0xF7);
serialPort.emit('data',[0xF0]);
serialPort.emit('data',[0x74]);
serialPort.emit('data',[3]);
@@ -504,7 +502,7 @@ describe('board',function(){
serialPort.lastWrite[17].should.equal(0);
serialPort.lastWrite[18].should.equal(64);
serialPort.lastWrite[19].should.equal(0);
- serialPort.lastWrite[20].should.equal(0xF7)
+ serialPort.lastWrite[20].should.equal(0xF7);
serialPort.emit('data',[0xF0]);
serialPort.emit('data',[0x74]);
serialPort.emit('data',[3]);
@@ -519,4 +517,4 @@ describe('board',function(){
serialPort.emit('data',[0]);
serialPort.emit('data',[0xF7]);
});
-});
+});
Please sign in to comment.
Something went wrong with that request. Please try again.