Skip to content

bump to master #3

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

Merged
merged 4 commits into from
May 28, 2014
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
2 changes: 1 addition & 1 deletion examples/RF24-pingpair.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var tessel = require('tessel'),
NRF24 = require("../"),
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0D2],
role = 'pong'; // swap this to pong if you want to wait for receive
role = 'ping'; // swap this to pong if you want to wait for receive

var nrf = NRF24.channel(0x4c) // set the RF channel to 76. Frequency = 2400 + RF_CH [MHz] = 2476MHz
.transmitPower('PA_MAX') // set the transmit power to max
Expand Down
58 changes: 58 additions & 0 deletions examples/nrf24.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* tessel to tessel
* requires 2 nrf24 modules (and ideally two tessels)
* put one tessel+nrf on "ping" mode and another one on "pong" mode
*/

var tessel = require('tessel'),
NRF24 = require("../"),
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0D2],
role = 'ping'; // swap this to pong if you want to wait for receive

var nrf = NRF24.channel(0x4c) // set the RF channel to 76. Frequency = 2400 + RF_CH [MHz] = 2476MHz
.transmitPower('PA_MAX') // set the transmit power to max
.dataRate('1Mbps')
.crcBytes(2) // 2 byte CRC
.autoRetransmit({count:15, delay:4000})
.use(tessel.port['A']);

nrf._debug = false;

nrf.on('ready', function () {
setTimeout(function(){
nrf.printDetails();
}, 5000);

if (role === 'ping') {
console.log("PING out");

var tx = nrf.openPipe('tx', pipes[0], {autoAck: false}), // transmit address F0F0F0F0D2
rx = nrf.openPipe('rx', pipes[1], {size: 4}); // receive address F0F0F0F0D2
tx.on('ready', function () {
var n = 0;
setInterval(function () {
var b = new Buffer(4); // set buff len of 8 for compat with maniac bug's RF24 lib
b.fill(0);
b.writeUInt32BE(n++);
console.log("Sending", n);
tx.write(b);
}, 5e3); // transmit every 5 seconds
});
rx.on('data', function (d) {
console.log("Got response back:", d);
});
} else {
console.log("PONG back");
var rx = nrf.openPipe('rx', pipes[0], {size: 4});
tx = nrf.openPipe('tx', pipes[1], {autoAck: false});
rx.on('data', function (d) {
console.log("Got data, will respond", d);
tx.write(d);
});
tx.on('error', function (e) {
console.warn("Error sending reply.", e);
});
}
});

// hold this process open
process.ref();
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "nRF24L01 driver library",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tinytap -e 'tessel run {}' test/*.js"
},
"repository": {
"type": "git",
Expand All @@ -28,9 +28,11 @@
"queue-async": "~1.0.4",
"pi-pins": "^1.0.0"
},
// prevent tessel from including pi files
"hardware": {
"pi-spi": false,
"pi-pins": false
},
"devDependencies": {
"tinytap": "~0.0.2"
}
}
69 changes: 69 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* tessel to tessel
* requires 2 nrf24 modules (and ideally two tessels)
* put one tessel+nrf on "ping" mode and another one on "pong" mode
*/

var tessel = require('tessel'),
NRF24 = require("../"),
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0D2];

console.log('1..3');

function go (port, role) {
var nrf = NRF24.channel(0x4c) // set the RF channel to 76. Frequency = 2400 + RF_CH [MHz] = 2476MHz
.transmitPower('PA_MAX') // set the transmit power to max
.dataRate('1Mbps')
.crcBytes(2) // 2 byte CRC
.autoRetransmit({count:15, delay:4000})
.use(port);

nrf._debug = false;

var sendack = false, resack = false;
nrf.on('ready', function () {
if (role === 'ping') {
console.log("# PING out");

var tx = nrf.openPipe('tx', pipes[0], {autoAck: false}), // transmit address F0F0F0F0D2
rx = nrf.openPipe('rx', pipes[1], {size: 4}); // receive address F0F0F0F0D2
tx.on('ready', function () {
var n = 0;
setImmediate(function loop () {
var b = new Buffer(4); // set buff len of 8 for compat with maniac bug's RF24 lib
b.fill(0);
b.writeUInt32BE(n++);
console.log("# sending", n);
!sendack && console.log('ok - sending');
sendack = true;
tx.write(b);
setTimeout(loop, 5e3)
}); // transmit every 5 seconds
});
rx.on('data', function (d) {
console.log("# got response back:", d);
console.log('ok - responded');
process.exit(0);
});
} else {
console.log("# PONG back");
var rx = nrf.openPipe('rx', pipes[0], {size: 4});
tx = nrf.openPipe('tx', pipes[1], {autoAck: false});
rx.on('data', function (d) {
console.log("# got data, will respond", d);
!resack && console.log('ok - responding');
resack = true;
tx.write(d);
});
tx.on('error', function (e) {
console.log("not ok - Error sending reply.", e);
process.exit(1);
});
}
});
}

// hold this process open
process.ref();

go(tessel.port['B'], 'ping');
go(tessel.port['GPIO'], 'pong');