From d5a3e79c665f29bca7940b2889773f0165accc55 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Fri, 8 Jul 2011 22:15:37 -0700 Subject: [PATCH] astyle -A1 -s2 --- .gitignore | 1 + examples/led_remote/led_remote.pde | 74 ++++++++-------- examples/pingpair/pingpair.pde | 56 ++++++------ examples/pingpair_irq/pingpair_irq.pde | 34 ++++---- examples/pingpair_pl/pingpair_pl.pde | 46 +++++----- examples/pingpair_sleepy/pingpair_sleepy.pde | 89 ++++++++++---------- examples/scanner/scanner.pde | 16 ++-- examples/starping/starping.pde | 66 +++++++-------- 8 files changed, 192 insertions(+), 190 deletions(-) diff --git a/.gitignore b/.gitignore index 5dae4ce..bac8ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.o .*.swp +*.orig docs/ output/ ojam/ diff --git a/examples/led_remote/led_remote.pde b/examples/led_remote/led_remote.pde index 53fc68b..7550a90 100644 --- a/examples/led_remote/led_remote.pde +++ b/examples/led_remote/led_remote.pde @@ -1,22 +1,22 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ /** - * Example LED Remote + * Example LED Remote * * This is an example of how to use the RF24 class to control a remote * bank of LED's using buttons on a remote control. * - * On the 'remote', connect any number of buttons or switches from + * On the 'remote', connect any number of buttons or switches from * an arduino pin to ground. Update 'button_pins' to reflect the * pins used. * - * On the 'led' board, connect the same number of LED's from an + * On the 'led' board, connect the same number of LED's from an * arduino pin to a resistor to ground. Update 'led_pins' to reflect * the pins used. Also connect a separate pin to ground and change * the 'role_pin'. This tells the sketch it's running on the LED board. @@ -24,7 +24,7 @@ * Every time the buttons change on the remote, the entire state of * buttons is send to the led board, which displays the state. */ - + #include #include "nRF24L01.h" #include "RF24.h" @@ -38,15 +38,15 @@ RF24 radio(8,9); -// sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver -// Leave open to be the 'remote' transmitter +// sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver +// Leave open to be the 'remote' transmitter const int role_pin = A4; // Pins on the remote for buttons const uint8_t button_pins[] = { 2,3,4,5,6,7 }; const uint8_t num_button_pins = sizeof(button_pins); -// Pins on the LED board for LED's +// Pins on the LED board for LED's const uint8_t led_pins[] = { 2,3,4,5,6,7 }; const uint8_t num_led_pins = sizeof(led_pins); @@ -84,7 +84,7 @@ uint8_t button_states[num_button_pins]; uint8_t led_states[num_led_pins]; // -// Setup +// Setup // void setup(void) @@ -92,12 +92,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_remote; @@ -107,7 +107,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/led_remote/\n\r"); @@ -116,16 +116,16 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); - + // // Open pipes to other nodes for communication // - + // 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. - + if ( role == role_remote ) { radio.openWritingPipe(pipe); @@ -138,14 +138,14 @@ void setup(void) // // Start listening // - + if ( role == role_led ) radio.startListening(); // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); // @@ -178,7 +178,7 @@ void setup(void) } // -// Loop +// Loop // void loop(void) @@ -187,7 +187,7 @@ void loop(void) // Remote role. If the state of any button has changed, send the whole state of // all buttons. // - + if ( role == role_remote ) { // Get the current state of buttons, and @@ -199,8 +199,8 @@ void loop(void) uint8_t state = ! digitalRead(button_pins[i]); if ( state != button_states[i] ) { - different = true; - button_states[i] = state; + different = true; + button_states[i] = state; } } @@ -210,19 +210,19 @@ void loop(void) printf("Now sending..."); bool ok = radio.write( button_states, num_button_pins ); if (ok) - printf("ok\n\r"); + printf("ok\n\r"); else - printf("failed\n\r"); + printf("failed\n\r"); } // Try again in a short while delay(20); } - + // // LED role. Receive the state of all buttons, and reflect that in the LEDs // - + if ( role == role_led ) { // if there is data ready @@ -234,20 +234,20 @@ void loop(void) { // Fetch the payload, and see if this was the last one. done = radio.read( button_states, num_button_pins ); - + // Spew it printf("Got buttons\n\r"); - // For each button, if the button now on, then toggle the LED - int i = num_led_pins; - while(i--) - { - if ( button_states[i] ) - { - led_states[i] ^= HIGH; - digitalWrite(led_pins[i],led_states[i]); - } - } + // For each button, if the button now on, then toggle the LED + int i = num_led_pins; + while(i--) + { + if ( button_states[i] ) + { + led_states[i] ^= HIGH; + digitalWrite(led_pins[i],led_states[i]); + } + } } } } diff --git a/examples/pingpair/pingpair.pde b/examples/pingpair/pingpair.pde index 1f0429f..c0d5480 100644 --- a/examples/pingpair/pingpair.pde +++ b/examples/pingpair/pingpair.pde @@ -1,6 +1,6 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -14,7 +14,7 @@ * which responds by sending the value back. The ping node can then see how long the whole cycle * took. */ - + #include #include "nRF24L01.h" #include "RF24.h" @@ -29,7 +29,7 @@ RF24 radio(8,9); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter +// Leave open to be the 'ping' transmitter const int role_pin = 7; // @@ -63,12 +63,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_ping_out; @@ -78,7 +78,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/pingpair/\n\r"); @@ -87,11 +87,11 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); + radio.setRetries(15,15); // optionally, use a high channel to avoid WiFi chatter radio.setChannel(110); @@ -102,12 +102,12 @@ void setup(void) // // Open pipes to other nodes for communication // - + // This simple sketch opens two pipes for these two nodes to communicate // back and forth. // Open 'our' pipe for writing // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - + if ( role == role_ping_out ) { radio.openWritingPipe(pipes[0]); @@ -122,13 +122,13 @@ void setup(void) // // Start listening // - + radio.startListening(); - + // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); } @@ -137,27 +137,27 @@ void loop(void) // // Ping out role. Repeatedly send the current time // - + if (role == role_ping_out) { // First, stop listening so we can talk. radio.stopListening(); - + // Take the time, and send it. This will block until complete unsigned long time = millis(); printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - + radio.write( &time, sizeof(unsigned long) ); + // Now, continue listening radio.startListening(); - + // Wait here until we get a response, or timeout (250ms) unsigned long started_waiting_at = millis(); bool timeout = false; while ( ! radio.available() && ! timeout ) if (millis() - started_waiting_at > 250 ) timeout = true; - + // Describe the results if ( timeout ) { @@ -168,19 +168,19 @@ void loop(void) // Grab the response, compare, and send to debugging spew unsigned long got_time; radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); } - + // Try again 1s later delay(1000); } - + // // Pong back role. Receive each packet, dump it out, and send it back // - + if ( role == role_pong_back ) { // if there is data ready @@ -193,18 +193,18 @@ void loop(void) { // Fetch the payload, and see if this was the last one. done = radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got payload %lu...",got_time); } - + // First, stop listening so we can talk radio.stopListening(); - + // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); + radio.write( &got_time, sizeof(unsigned long) ); printf("Sent response.\n\r"); - + // Now, resume listening so we catch the next packets. radio.startListening(); } diff --git a/examples/pingpair_irq/pingpair_irq.pde b/examples/pingpair_irq/pingpair_irq.pde index 9052719..e8c5396 100644 --- a/examples/pingpair_irq/pingpair_irq.pde +++ b/examples/pingpair_irq/pingpair_irq.pde @@ -1,6 +1,6 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -12,7 +12,7 @@ * This is an example of how to user interrupts to interact with the radio. * It builds on the pingpair_pl example, and uses ack payloads. */ - + #include #include "nRF24L01.h" #include "RF24.h" @@ -27,7 +27,7 @@ RF24 radio(8,9); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter +// Leave open to be the 'ping' transmitter const short role_pin = 7; // @@ -64,12 +64,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_sender; @@ -79,7 +79,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/pingpair_irq/\n\r"); @@ -88,9 +88,9 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); - + // We will be using the Ack Payload feature, so please enable it radio.enableAckPayload(); @@ -103,10 +103,10 @@ void setup(void) // // Open pipes to other nodes for communication // - + // This simple sketch opens a single pipe for these two nodes to communicate // back and forth. One listens on it, the other talks to it. - + if ( role == role_sender ) { radio.openWritingPipe(pipe); @@ -119,16 +119,16 @@ void setup(void) // // Start listening // - + if ( role == role_receiver ) radio.startListening(); // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); - + // // Attach interrupt handler to interrupt #0 (using pin 2) // on BOTH the sender and receiver @@ -144,15 +144,15 @@ void loop(void) // // Sender role. Repeatedly send the current time // - + if (role == role_sender) { // Take the time, and send it. unsigned long time = millis(); printf("Now sending %lu\n\r",time); radio.startWrite( &time, sizeof(unsigned long) ); - - // Try again soon + + // Try again soon delay(2000); } @@ -206,7 +206,7 @@ void check_radio(void) // If we're the receiver, we've received a time message if ( role == role_receiver ) { - // Get this payload and dump it + // Get this payload and dump it static unsigned long got_time; radio.read( &got_time, sizeof(got_time) ); printf("Got payload %lu\n\r",got_time); diff --git a/examples/pingpair_pl/pingpair_pl.pde b/examples/pingpair_pl/pingpair_pl.pde index b014e9b..da1dc36 100644 --- a/examples/pingpair_pl/pingpair_pl.pde +++ b/examples/pingpair_pl/pingpair_pl.pde @@ -1,6 +1,6 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -9,12 +9,12 @@ /** * Example of using Ack Payloads * - * This is an example of how to do two-way communication without changing - * transmit/receive modes. Here, a payload is set to the transmitter within + * This is an example of how to do two-way communication without changing + * transmit/receive modes. Here, a payload is set to the transmitter within * the Ack packet of each transmission. Note that the payload is set BEFORE * the sender's message arrives. */ - + #include #include "nRF24L01.h" #include "RF24.h" @@ -29,7 +29,7 @@ RF24 radio(8,9); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter +// Leave open to be the 'ping' transmitter const short role_pin = 7; // @@ -63,12 +63,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_sender; @@ -78,7 +78,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/pingpair_pl/\n\r"); @@ -87,19 +87,19 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); - + // We will be using the Ack Payload feature, so please enable it radio.enableAckPayload(); // // Open pipes to other nodes for communication // - + // 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. - + if ( role == role_sender ) { radio.openWritingPipe(pipe); @@ -112,25 +112,25 @@ void setup(void) // // Start listening // - + if ( role == role_receiver ) radio.startListening(); // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); } void loop(void) { static uint32_t message_count = 0; - + // // Sender role. Repeatedly send the current time // - + if (role == role_sender) { // Take the time, and send it. This will block until complete @@ -142,17 +142,17 @@ void loop(void) { radio.read(&message_count,sizeof(message_count)); printf("Ack: [%lu] ",message_count); - } + } printf("OK\n\r"); - - // Try again soon + + // Try again soon delay(2000); } - + // // Receiver role. Receive each packet, dump it out, add ack payload for next time // - + if ( role == role_receiver ) { // if there is data ready @@ -165,11 +165,11 @@ void loop(void) { // Fetch the payload, and see if this was the last one. done = radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got payload %lu\n",got_time); } - + // Add an ack packet for the next time around. This is a simple // packet counter radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); diff --git a/examples/pingpair_sleepy/pingpair_sleepy.pde b/examples/pingpair_sleepy/pingpair_sleepy.pde index c8edc6b..7ef0db2 100644 --- a/examples/pingpair_sleepy/pingpair_sleepy.pde +++ b/examples/pingpair_sleepy/pingpair_sleepy.pde @@ -1,6 +1,6 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -15,11 +15,11 @@ * ping/pong cycle. * * As with the pingpair.pde example, write this sketch to two different nodes, - * connect the role_pin to ground on one. The ping node sends the current + * connect the role_pin to ground on one. The ping node sends the current * time to the pong node, which responds by sending the value back. The ping * node can then see how long the whole cycle took. */ - + #include #include #include @@ -36,7 +36,7 @@ RF24 radio(8,9); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter +// Leave open to be the 'ping' transmitter const int role_pin = 7; // @@ -86,12 +86,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_ping_out; @@ -101,7 +101,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/pingpair_sleepy/\n\r"); @@ -118,18 +118,18 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); // // Open pipes to other nodes for communication // - + // This simple sketch opens two pipes for these two nodes to communicate // back and forth. // Open 'our' pipe for writing // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - + if ( role == role_ping_out ) { radio.openWritingPipe(pipes[0]); @@ -144,13 +144,13 @@ void setup(void) // // Start listening // - + radio.startListening(); - + // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); } @@ -159,27 +159,27 @@ void loop(void) // // Ping out role. Repeatedly send the current time // - + if (role == role_ping_out) { // First, stop listening so we can talk. radio.stopListening(); - + // Take the time, and send it. This will block until complete unsigned long time = millis(); printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - + radio.write( &time, sizeof(unsigned long) ); + // Now, continue listening radio.startListening(); - + // Wait here until we get a response, or timeout (250ms) unsigned long started_waiting_at = millis(); bool timeout = false; while ( ! radio.available() && ! timeout ) if (millis() - started_waiting_at > 250 ) timeout = true; - + // Describe the results if ( timeout ) { @@ -190,11 +190,11 @@ void loop(void) // Grab the response, compare, and send to debugging spew unsigned long got_time; radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); } - + // // Shut down the system // @@ -210,16 +210,16 @@ void loop(void) // continue execution here. while( sleep_cycles_remaining ) do_sleep(); - + sleep_cycles_remaining = sleep_cycles_per_transmission; } - + // // Pong back role. Receive each packet, dump it out, and send it back // // This is untouched from the pingpair example. // - + if ( role == role_pong_back ) { // if there is data ready @@ -232,19 +232,19 @@ void loop(void) { // Fetch the payload, and see if this was the last one. done = radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it. Include our time, because the ping_out millis counter is unreliable - // due to it sleeping + // due to it sleeping printf("Got payload %lu @ %lu...",got_time,millis()); } - + // First, stop listening so we can talk radio.stopListening(); - + // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); + radio.write( &got_time, sizeof(unsigned long) ); printf("Sent response.\n\r"); - + // Now, resume listening so we catch the next packets. radio.startListening(); } @@ -252,36 +252,37 @@ void loop(void) } // -// Sleep helpers +// Sleep helpers // // 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec -void setup_watchdog(uint8_t prescalar) +void setup_watchdog(uint8_t prescalar) { - prescalar = min(9,prescalar); - uint8_t wdtcsr = prescalar & 7; - if ( prescalar & 8 ) - wdtcsr |= _BV(WDP3); + prescalar = min(9,prescalar); + uint8_t wdtcsr = prescalar & 7; + if ( prescalar & 8 ) + wdtcsr |= _BV(WDP3); - MCUSR &= ~_BV(WDRF); - WDTCSR = _BV(WDCE) | _BV(WDE); - WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); + MCUSR &= ~_BV(WDRF); + WDTCSR = _BV(WDCE) | _BV(WDE); + WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); } -ISR(WDT_vect) { +ISR(WDT_vect) +{ --sleep_cycles_remaining; } void do_sleep(void) { - set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here - sleep_enable(); + set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here + sleep_enable(); - sleep_mode(); // System sleeps here + sleep_mode(); // System sleeps here - sleep_disable(); // System continues execution here when watchdog timed out + sleep_disable(); // System continues execution here when watchdog timed out } // vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/scanner/scanner.pde b/examples/scanner/scanner.pde index efefa17..f8beaf9 100644 --- a/examples/scanner/scanner.pde +++ b/examples/scanner/scanner.pde @@ -1,7 +1,7 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -47,15 +47,15 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/scanner/\n\r"); - + // // Setup and configure rf radio // - + radio.begin(); radio.setAutoAck(false); @@ -63,7 +63,7 @@ void setup(void) radio.startListening(); radio.stopListening(); - // Print out header, high then low digit + // Print out header, high then low digit int i = 0; while ( i < num_channels ) { @@ -88,7 +88,7 @@ const short num_reps = 100; void loop(void) { - // Clear measurement values + // Clear measurement values memset(values,0,num_channels); // Scan all channels num_reps times @@ -108,11 +108,11 @@ void loop(void) // Did we get a carrier? if ( radio.testCarrier() ) - ++values[i]; + ++values[i]; } } - // Print out channel measurements, clamped to a single hex digit + // Print out channel measurements, clamped to a single hex digit int i = 0; while ( i < num_channels ) { diff --git a/examples/starping/starping.pde b/examples/starping/starping.pde index 1d02bcd..28470c1 100644 --- a/examples/starping/starping.pde +++ b/examples/starping/starping.pde @@ -1,18 +1,18 @@ /* Copyright (C) 2011 James Coliz, Jr. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ /** - * Example RF Radio Ping Star Group + * Example RF Radio Ping Star Group * - * This sketch is a more complex example of using the RF24 library for Arduino. - * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the + * This sketch is a more complex example of using the RF24 library for Arduino. + * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the * role_pin low, and the others will be 'ping transmit' units. The ping units - * unit will send out the value of millis() once a second. The pong unit will + * unit will send out the value of millis() once a second. The pong unit will * respond back with a copy of the value. Each ping unit can get that response * back, and determine how long the whole cycle took. * @@ -20,7 +20,7 @@ * The pong receiver is identified by having its role_pin tied to ground. * The ping senders are further differentiated by a byte in eeprom. */ - + #include #include #include "nRF24L01.h" @@ -88,12 +88,12 @@ void setup(void) // // Role // - + // set up the role pin pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20); // Just to get a solid reading on the role pin - + // read the address pin, establish our role if ( digitalRead(role_pin) ) role = role_ping_out; @@ -115,7 +115,7 @@ void setup(void) // address. if ( reading >= 2 && reading <= 6 ) node_address = reading; - + // Otherwise, it is invalid, so set our address AND ROLE to 'invalid' else { @@ -127,7 +127,7 @@ void setup(void) // // Print preamble // - + Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/starping/\n\r"); @@ -137,7 +137,7 @@ void setup(void) // // Setup and configure rf radio // - + radio.begin(); // @@ -154,27 +154,27 @@ void setup(void) radio.openReadingPipe(4,talking_pipes[3]); radio.openReadingPipe(5,talking_pipes[4]); } - - // Each ping node has a talking pipe that it will ping into, and a listening - // pipe that it will listen for the pong. + + // Each ping node has a talking pipe that it will ping into, and a listening + // pipe that it will listen for the pong. if ( role == role_ping_out ) { // Write on our talking pipe radio.openWritingPipe(talking_pipes[node_address-2]); - // Listen on our listening pipe + // Listen on our listening pipe radio.openReadingPipe(1,listening_pipes[node_address-2]); } // // Start listening // - + radio.startListening(); - + // // Dump the configuration of the rf unit for debugging // - + radio.printDetails(); // @@ -192,27 +192,27 @@ void loop(void) // // Ping out role. Repeatedly send the current time // - + if (role == role_ping_out) { // First, stop listening so we can talk. radio.stopListening(); - + // Take the time, and send it. This will block until complete unsigned long time = millis(); printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - + radio.write( &time, sizeof(unsigned long) ); + // Now, continue listening radio.startListening(); - + // Wait here until we get a response, or timeout (250ms) unsigned long started_waiting_at = millis(); bool timeout = false; while ( ! radio.available() && ! timeout ) if (millis() - started_waiting_at > 250 ) timeout = true; - + // Describe the results if ( timeout ) { @@ -223,19 +223,19 @@ void loop(void) // Grab the response, compare, and send to debugging spew unsigned long got_time; radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); } - + // Try again 1s later delay(1000); } - + // // Pong back role. Receive each packet, dump it out, and send it back // - + if ( role == role_pong_back ) { // if there is data ready @@ -249,11 +249,11 @@ void loop(void) { // Fetch the payload, and see if this was the last one. done = radio.read( &got_time, sizeof(unsigned long) ); - + // Spew it printf("Got payload %lu from node %i...",got_time,pipe_num+1); } - + // First, stop listening so we can talk radio.stopListening(); @@ -262,11 +262,11 @@ void loop(void) // Retain the low 2 bytes to identify the pipe for the spew uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff; - + // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); + radio.write( &got_time, sizeof(unsigned long) ); printf("Sent response to %04x.\n\r",pipe_id); - + // Now, resume listening so we catch the next packets. radio.startListening(); }