Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Branch:
- RF24_library_test_tx
- Revision:
- 12:cf6cbf1d1ebf
- Parent:
- 11:1b56bb8ccd04
- Child:
- 13:f0f9a5586e45
--- a/main.cpp Sun Nov 25 12:39:01 2018 +0000
+++ b/main.cpp Sun Nov 25 16:58:22 2018 +0000
@@ -4,8 +4,9 @@
#define PING 1
#define PONG 2
+#define PC 3
-#define ROLE PONG
+#define ROLE PC
#define ID 0
#define nrf_CE D2
@@ -48,13 +49,18 @@
char rxData[TRANSFER_SIZE];
int rxDataCnt = 0;
+
+ int inByteCnt = 0;
+ char buf[TRANSFER_SIZE+3];
+
beepStart();
pc.baud(115200);
initNRF(role);
dumpRFInfo();
while(1) {
- if(role == PING) {
+ switch(role) {
+ case PING:
int id = 1;
int lspeed=-40;
int rspeed=50;
@@ -65,8 +71,8 @@
pc.printf("PING:%s\r\n", txData);
nrf.write(NRF24L01P_PIPE_P0, txData, TRANSFER_SIZE);
wait(0.2);
- }
- else if(role == PONG) {
+ break;
+ case PONG:
if ( nrf.readable() ) {
rxDataCnt = nrf.read( NRF24L01P_PIPE_P0, rxData, TRANSFER_SIZE);
printf("%s\r\n", rxData);
@@ -79,6 +85,24 @@
turnWheel(rspd, lspd);
printf("%d, %d\r\n", rspd,lspd);
}
+ break;
+ case PC:
+ while(pc.readable()) {
+ char inByte = pc.getc();
+ if(inByteCnt > TRANSFER_SIZE+2) {
+ printf("Data size overflow!\r\n");
+ inByteCnt = 0;
+ break;
+ } else if(inByte == '\n') {
+ buf[inByteCnt] = '\0';
+ printf("Command: %s\r\n", buf);
+ nrf.write(NRF24L01P_PIPE_P0, buf, TRANSFER_SIZE);
+ inByteCnt=0;
+ } else {
+ buf[inByteCnt++] = inByte;
+ }
+ }
+ break;
}
}
}
@@ -114,7 +138,7 @@
void initNRF(int role)
{
- if(role == PING) {
+ if(role == PING || role == PC) {
nrf.setTxAddress(0xDEADBEEF0F);
nrf.powerUp();
nrf.setTransferSize( TRANSFER_SIZE );