Skip to content

Commit

Permalink
Adds testcase and npm test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcr committed May 23, 2014
1 parent 32d78af commit 7eabb54
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.DS_Store
*.log

6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var MAX_SIGNAL_DURATION = 200;

var Infrared = function(hardware, callback) {

this.chipSelect = hardware.gpio(1);
this.reset = hardware.gpio(2);
this.irq = hardware.gpio(3);
this.chipSelect = hardware.digital[1];
this.reset = hardware.digital[2];
this.irq = hardware.digital[3];
this.spi = hardware.SPI({clockSpeed : 1000, mode:2, chipSelect:this.chipSelect});
this.transmitting = false;
this.listening = false;
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./testsuite.js"
},
"hardware": {
"./examples": false,
"./firmware" : false
"./firmware" : false,
"tape": false,
"tap": false,
"shelljs": false
},
"devDependencies": {
"tape": "~2.3.2",
"tap": "git+https://github.com/tcr/node-tap.git#3cb76e",
"shelljs": "~0.3.0"
},
"author": "",
"license": "MIT/Apache 2.0"
Expand Down
47 changes: 47 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var tessel = require('tessel');

var portname1 = process.argv[2] || 'A';
var infrared1 = require('../index').use(tessel.port[portname1]);

var portname2 = process.argv[3] || 'B';
var infrared2 = require('../index').use(tessel.port[portname2]);

console.log('1..2')

// Receive on IR 1
infrared1.on('data', function (data) {
console.log('# received RX Data:', data);
console.log('ok');
process.exit(0);
});

// Send on IR 2
var sendack = false;
infrared2.on('ready', function(err) {
if (err) { return console.error(err); }

setImmediate(function sendSignal () {
// Make a buffer off on/off durations (each duration is 16 bits)
var powerBuffer = new Buffer([
0, 178, 255, 168, 0, 12, 255, 246, 0, 13, 255, 225, 0, 13, 255, 224,
0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 247,
0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 247, 0, 13, 255, 224,
0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246,
0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 225,
0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247,
0, 13, 255, 247, 0, 13, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246,
0, 12, 255, 246, 0, 12, 255, 224, 0, 13, 255, 224, 0, 12, 255, 224,
0, 12, 255, 224, 0, 12
]);

// Send the signal at 38 kHz
infrared2.sendRawSignal(38, powerBuffer, function (err) {
if (err) { return console.log("Unable to send signal: ", err); }

console.log('# signal sent!');
!sendack && console.log('ok');
sendack = true;
setImmediate(sendSignal);
});
});
});
11 changes: 11 additions & 0 deletions testsuite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

require('shelljs/global');

var port1 = process.env.IR_PORT1 || 'A';
var port2 = process.env.IR_PORT2 || 'B';
var cmd = './node_modules/.bin/tap -e "tessel run {} ' + port1 + ' ' + port2 + '" test/*.js';

// execute
cd(__dirname)
process.exit(exec(cmd).code);

0 comments on commit 7eabb54

Please sign in to comment.