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.
Dependencies: mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P
Diff: main.cpp
- Revision:
- 33:5d86c111d9bc
- Parent:
- 32:c40d581f50af
- Child:
- 34:d73e95bbdbed
- Child:
- 40:4f7d95c68d29
diff -r c40d581f50af -r 5d86c111d9bc main.cpp --- a/main.cpp Mon Apr 23 16:05:32 2018 +0000 +++ b/main.cpp Wed Apr 25 15:39:03 2018 +0000 @@ -11,11 +11,11 @@ #include "CircularBuf.cpp" // Hack to get templates to work // How many times larger the buffer should be -#define FIFO_BUFFER_SCALE 4 +#define FIFO_BUFFER_SCALE 250 // How maybe bytes to send over RF #define DATA_PACKET_SIZE 32 // How quickly to sample the mic / play the speaker -#define SAMPLE_PERIOD 0.1 +#define SAMPLE_PERIOD 1/16000.0 Serial pc(USBTX, USBRX); @@ -27,7 +27,7 @@ Speaker spkr(p18); Microphone mic(p16); -//uLCD_4DGL uLCD(p27, p28, p30); // serial tx, serial rx, reset pin; +//uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin; nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq CircularBuf<uint8_t> txbuff( FIFO_BUFFER_SCALE * DATA_PACKET_SIZE ); @@ -67,11 +67,14 @@ // Callback interrupt from the button to shift into transmit mode void enterTransmitMode() { mode = TRANSMIT; + txbuff.clear(); } // Callback interrupt from the button to shift into receive mode void enterRecieveMode() { mode = RECEIVE; + //TODO: Add this back in + //rxbuf.clear(); } // Called every SAMPLE_PERIOD ms to sample the mic or output data into the speaker @@ -88,7 +91,7 @@ spkr.write(speakerSample); } else { // Get mic sample and place into buffer - uint8_t micSample = 0;//mic.getData(); + uint8_t micSample = mic.getData(); txbuff.push(&micSample, 1); // Make sure the speaker is actually off @@ -129,20 +132,26 @@ // Pull an entire packet of data from the mic sample buffer int numPopped = txbuff.pop(micPacket, DATA_PACKET_SIZE); + rxbuff.push(micPacket, DATA_PACKET_SIZE); // Send the entire buffer to the other device // TODO: We just assume that DATA_PACKET_SIZE bytes were popped, this may // not be the case my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*) micPacket, DATA_PACKET_SIZE ); - pc.printf("Transmitting....\n\r"); + //for (int i = 0; i < DATA_PACKET_SIZE; i++) { + // pc.printf("%x", micPacket[i]); + //} + //pc.printf("\n\r"); + + //pc.printf("Transmitting....\n\r"); myled1 = !myled1; } } - pc.printf("TX Size %d RX Size%d Mode %d\n\r", txbuff.size(), rxbuff.size(), mode); + //pc.printf("TX Size %d RX Size%d Mode %d\n\r", txbuff.size(), rxbuff.size(), mode); Thread::yield(); - Thread::wait(100); + //Thread::wait(10); } } @@ -172,7 +181,7 @@ } */ // Maybe add some graphics too idk - Thread::wait(50); + Thread::wait(500); } } @@ -181,6 +190,8 @@ Thread lcd; Thread comm; + pc.printf("Starting setup....\n\r"); + // Set up the nrf24l01p rfFreq = my_nrf24l01p.getRfFrequency(); dataRate = my_nrf24l01p.getAirDataRate();