Update examples, minimize code size
- Updated some example files and tests - Small changes to minimize code size
This commit is contained in:
@@ -27,11 +27,11 @@ public: RF24Test(int a, int b): RF24(a,b) {}
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 8 & 9
|
||||
|
||||
RF24Test radio(8,9);
|
||||
RF24Test radio(48,49);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const int role_pin = 7;
|
||||
const int role_pin = 5;
|
||||
|
||||
//
|
||||
// Topology
|
||||
@@ -230,28 +230,28 @@ void loop(void)
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
while (radio.available())
|
||||
{
|
||||
// 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);
|
||||
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
}
|
||||
// Delay just a little bit to let the other unit
|
||||
// make the transition to receiver
|
||||
delay(20);
|
||||
}
|
||||
//delay(20);
|
||||
//}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu...",got_time);
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -270,4 +270,4 @@ void loop(void)
|
||||
printf("FAIL\n\r\n\r");
|
||||
}
|
||||
}
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
@@ -29,11 +29,11 @@
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 8 & 9
|
||||
|
||||
RF24 radio(8,9);
|
||||
RF24 radio(7,8);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const short role_pin = 7;
|
||||
const short role_pin = 5;
|
||||
|
||||
//
|
||||
// Topology
|
||||
@@ -254,7 +254,7 @@ void setup(void)
|
||||
//
|
||||
|
||||
attachInterrupt(0, check_radio, FALLING);
|
||||
|
||||
delay(50);
|
||||
if ( role == role_receiver )
|
||||
printf("\n\r+OK ");
|
||||
}
|
||||
@@ -294,7 +294,7 @@ void loop(void)
|
||||
|
||||
// Send it. This will block until complete
|
||||
printf("\n\rNow sending length %i...",next_payload_size);
|
||||
radio.startWrite( send_payload, next_payload_size );
|
||||
radio.startWrite( send_payload, next_payload_size,0 );
|
||||
|
||||
// Update size for next time.
|
||||
next_payload_size += payload_size_increments_by;
|
||||
@@ -374,10 +374,9 @@ void check_radio(void)
|
||||
prbuf_in += sprintf(prbuf_in,"Ack Payload:Failed\n\r");
|
||||
}
|
||||
|
||||
// Transmitter can power down for now, because
|
||||
// the transmission is done.
|
||||
if ( ( tx || fail ) && ( role == role_sender ) )
|
||||
radio.powerDown();
|
||||
// Not powering down since radio is in standby mode
|
||||
//if ( ( tx || fail ) && ( role == role_sender ) )
|
||||
//radio.powerDown();
|
||||
|
||||
// Did we receive a message?
|
||||
if ( rx )
|
||||
@@ -387,7 +386,7 @@ void check_radio(void)
|
||||
{
|
||||
radio.read(&message_count,sizeof(message_count));
|
||||
prbuf_in += sprintf(prbuf_in,"Ack:%lu ",message_count);
|
||||
|
||||
|
||||
// is this ack what we were expecting? to account
|
||||
// for failures, we simply want to make sure we get a
|
||||
// DIFFERENT ack every time.
|
||||
@@ -411,10 +410,11 @@ void check_radio(void)
|
||||
size_t len = max_payload_size;
|
||||
memset(receive_payload,0,max_payload_size);
|
||||
|
||||
if ( configuration == '3' )
|
||||
if ( configuration == '3' ){
|
||||
len = next_payload_size;
|
||||
else
|
||||
}else{
|
||||
len = radio.getDynamicPayloadSize();
|
||||
}
|
||||
|
||||
radio.read( receive_payload, len );
|
||||
|
||||
@@ -427,9 +427,9 @@ void check_radio(void)
|
||||
// Add an ack packet for the next time around.
|
||||
// Here we will report back how many bytes we got this time.
|
||||
radio.writeAckPayload( pipe_number, &len, sizeof(len) );
|
||||
|
||||
++message_count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
|
||||
Reference in New Issue
Block a user