Cleaned up comments, variables names, enums

This commit is contained in:
maniacbug 2011-05-10 14:40:42 -07:00
parent ffc7d099ed
commit f3356f31a2
1 changed files with 23 additions and 23 deletions

View File

@ -7,12 +7,12 @@
*/ */
/** /**
* Example RF Radio Ping Pair * Example of using Ack Payloads
* *
* This is an example of how to use the RF24 class. Write this sketch to two different nodes, * This is an example of how to do two-way communication without changing
* connect the role_pin to ground on one. The ping node sends the current time to the pong node, * transmit/receive modes. Here, a payload is set to the transmitter within
* which responds by sending the value back. The ping node can then see how long the whole cycle * the Ack packet of each transmission. Note that the payload is set BEFORE
* took. * the sender's message arrives.
*/ */
#include <SPI.h> #include <SPI.h>
@ -36,24 +36,24 @@ const short role_pin = 7;
// Topology // Topology
// //
// Radio pipe address for the 2 nodes to communicate. // Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL; const uint64_t pipe = 0xE8E8F0F0E1LL;
// //
// Role management // Role management
// //
// Set up role. This sketch uses the same software for all the nodes // Set up role. This sketch uses the same software for all the nodes in this
// in this system. Doing so greatly simplifies testing. The hardware itself specifies // system. Doing so greatly simplifies testing. The hardware itself specifies
// which node it is. // which node it is.
// //
// This is done through the role_pin // This is done through the role_pin
// //
// The various roles supported by this sketch // The various roles supported by this sketch
typedef enum { role_ping_out = 1, role_pong_back } role_e; typedef enum { role_sender = 1, role_receiver } role_e;
// The debug-friendly names of those roles // The debug-friendly names of those roles
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"};
// The role of the current running sketch // The role of the current running sketch
role_e role; role_e role;
@ -71,9 +71,9 @@ void setup(void)
// read the address pin, establish our role // read the address pin, establish our role
if ( digitalRead(role_pin) ) if ( digitalRead(role_pin) )
role = role_ping_out; role = role_sender;
else else
role = role_pong_back; role = role_receiver;
// //
// Print preamble // Print preamble
@ -100,7 +100,7 @@ void setup(void)
// This simple sketch opens a single pipes for these two nodes to communicate // This simple sketch opens a single pipes for these two nodes to communicate
// back and forth. One listens on it, the other talks to it. // back and forth. One listens on it, the other talks to it.
if ( role == role_ping_out ) if ( role == role_sender )
{ {
radio.openWritingPipe(pipe); radio.openWritingPipe(pipe);
} }
@ -113,7 +113,7 @@ void setup(void)
// Start listening // Start listening
// //
if ( role == role_pong_back ) if ( role == role_receiver )
radio.startListening(); radio.startListening();
// //
@ -125,13 +125,13 @@ void setup(void)
void loop(void) void loop(void)
{ {
static uint32_t id = 0; static uint32_t message_count = 0;
// //
// Ping out role. Repeatedly send the current time // Sender role. Repeatedly send the current time
// //
if (role == role_ping_out) if (role == role_sender)
{ {
// Take the time, and send it. This will block until complete // Take the time, and send it. This will block until complete
unsigned long time = millis(); unsigned long time = millis();
@ -140,8 +140,8 @@ void loop(void)
if ( radio.isAckPayloadAvailable() ) if ( radio.isAckPayloadAvailable() )
{ {
radio.read(&id,sizeof(id)); radio.read(&message_count,sizeof(message_count));
printf("Ack: [%lu] ",id); printf("Ack: [%lu] ",message_count);
} }
printf("OK\n\r"); printf("OK\n\r");
@ -150,10 +150,10 @@ void loop(void)
} }
// //
// Pong back role. Receive each packet, dump it out, add ack payload for next time // Receiver role. Receive each packet, dump it out, add ack payload for next time
// //
if ( role == role_pong_back ) if ( role == role_receiver )
{ {
// if there is data ready // if there is data ready
if ( radio.available() ) if ( radio.available() )
@ -172,8 +172,8 @@ void loop(void)
// Add an ack packet for the next time around. This is a simple // Add an ack packet for the next time around. This is a simple
// packet counter // packet counter
radio.writeAckPayload( 1, &id, sizeof(id) ); radio.writeAckPayload( 1, &message_count, sizeof(message_count) );
++id; ++message_count;
} }
} }
} }