ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

Dependencies:   mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P

Revision:
34:d73e95bbdbed
Parent:
33:5d86c111d9bc
Child:
41:9ed924a1f2e0
--- a/main.cpp	Wed Apr 25 15:39:03 2018 +0000
+++ b/main.cpp	Fri Apr 27 22:01:10 2018 +0000
@@ -1,3 +1,4 @@
+#include "uLCD_4DGL.h"
 #include "mbed.h"
 #include "rtos.h"
 
@@ -5,7 +6,6 @@
 #include "Speaker.h"
 #include "HUD.h"
 #include "nRF24L01P.h"
-#include "uLCD_4DGL.h"
 
 #include "CircularBuf.h"
 #include "CircularBuf.cpp" // Hack to get templates to work
@@ -18,7 +18,7 @@
 #define SAMPLE_PERIOD   1/16000.0
 
 
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
 DigitalOut myled1(LED1); // Mic data sent over RF
 DigitalOut myled2(LED2); // Speaker data recieved over RF
 DigitalOut myled3(LED3); // Sampled mic / played the speaker
@@ -27,7 +27,7 @@
 Speaker spkr(p18);
 Microphone mic(p16);
 
-//uLCD_4DGL uLCD(p28, p27, p29);                      // 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 );
@@ -73,8 +73,7 @@
 // Callback interrupt from the button to shift into receive mode
 void enterRecieveMode() {
     mode = RECEIVE;
-    //TODO: Add this back in
-    //rxbuf.clear();
+    rxbuff.clear();
 }
 
 // Called every SAMPLE_PERIOD ms to sample the mic or output data into the speaker
@@ -105,7 +104,6 @@
 // Communicates to the other MBED using RF
 void commThread()
 {
-    pc.printf("Enter commThread\n\r");
     // We want this in it's own thread so we don't have to worry about the
     // timings screwing anything else up
     // It can't be in an interrupt because of that
@@ -123,7 +121,6 @@
                 // Only place into the buffer the number of bytes received
                 rxbuff.push(spkrPacket, min(DATA_PACKET_SIZE, numReceived));
                 
-                pc.printf("Receiviing....\n\r");
                 myled2 = !myled2;
             }
         } else { // mode == TRANSMIT
@@ -132,19 +129,13 @@
                 
                 // 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);
+             //   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 );
-                
-                //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;
             }
         }
@@ -158,18 +149,16 @@
 // Displays the current info to the LCD display
 void lcdThread()
 {
-    pc.printf("Enter lcdThread\n\r");
     while (1) {
-        /*
-        uLCD.locate(64, 20);
+        uLCD.locate(0, 0);
         uLCD.printf("Frequency: %d MHz", rfFreq);
-        uLCD.locate(64, 40);
+        uLCD.locate(0, 2);
         uLCD.printf("Data Rate: %d kbps", dataRate);
-        uLCD.locate(64, 60);
+        uLCD.locate(0, 4);
         uLCD.printf("TX Address: 0x%010llX", txAddr);
-        uLCD.locate(64, 80);
+        uLCD.locate(0, 6);
         uLCD.printf("RX Address: 0x%010llX", rxAddr);
-        uLCD.locate(64, 100);
+        uLCD.locate(0, 8);
         
         switch (mode) {
             case RECEIVE:
@@ -179,7 +168,7 @@
                 uLCD.printf("Mode: Transmitting");
                 break;
         }
-        */
+        
         // Maybe add some graphics too idk
         Thread::wait(500);
     }
@@ -190,9 +179,8 @@
     Thread lcd;
     Thread comm;    
     
-    pc.printf("Starting setup....\n\r");
-    
     // Set up the nrf24l01p
+    my_nrf24l01p.setAirDataRate(2000);
     rfFreq = my_nrf24l01p.getRfFrequency();
     dataRate = my_nrf24l01p.getAirDataRate();
     rxAddr = my_nrf24l01p.getRxAddress();
@@ -203,13 +191,11 @@
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
     
-    pc.printf("Finished starting up....\n\r");
-    
     mode = RECEIVE;
     
     // Initialize the uLCD
-    //uLCD.baudrate(3000000);
-    //uLCD.background_color(BLACK);
+    uLCD.baudrate(3000000);
+    uLCD.background_color(BLACK);
     
     // Spawn threads
     lcd.start(lcdThread);
@@ -224,7 +210,6 @@
     // Setup sampler to sample at a specific frequency
     sampler.attach(&sampleData, SAMPLE_PERIOD);
     
-    pc.printf("Enter Heartbeat\n\r");
     // Heartbeat thread
     while (1) {
         myled4 = !myled4;