ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

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

Revision:
44:a4f81588fcd5
Parent:
41:9ed924a1f2e0
Child:
45:805f92c68d55
--- a/main.cpp	Sun Apr 29 15:38:00 2018 +0000
+++ b/main.cpp	Sun Apr 29 16:32:23 2018 +0000
@@ -41,6 +41,7 @@
 int dataRate;
 unsigned long long rxAddr, txAddr;
 int pipe = 0;
+int channelNum = 0;
 
 enum operatingMode {
     RECEIVE = 0,
@@ -58,55 +59,74 @@
 // by changing RX/TX pipes
 // TODO: Make sure we don't have to restart the device or anything to change this
 void setChannel() {
-    int oldPipe = pipe;
-    int width = 5;
+    int oldChannel = channelNum;
+    //int oldPipe = pipe;
+    //int width = 5;
     switch (channel) {
         case 0:      // Channel 0
-            rxAddr = txAddr = 0xC2C2C2C2C0;
-            pipe = NRF24L01P_PIPE_P0;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C0;
+            //pipe = NRF24L01P_PIPE_P0;
+            channelNum = 0;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         case 1:      // Channel 1
-            rxAddr = txAddr = 0xC2C2C2C2C1;
-            pipe = NRF24L01P_PIPE_P1;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C1;
+            //pipe = NRF24L01P_PIPE_P1;
+            channelNum = 1;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         case 2:      // Channel 2
-            rxAddr = txAddr = 0xC2C2C2C2C2;
-            pipe = NRF24L01P_PIPE_P2;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C2;
+            //pipe = NRF24L01P_PIPE_P2;
+            channelNum = 2;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         case 4:      // Channel 3
-            rxAddr = txAddr = 0xC2C2C2C2C3;
-            pipe = NRF24L01P_PIPE_P3;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C3;
+            //pipe = NRF24L01P_PIPE_P3;
+            channelNum = 3;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         case 8:      // Channel 4
-            rxAddr = txAddr = 0xC2C2C2C2C4;
-            pipe = NRF24L01P_PIPE_P4;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C4;
+            //pipe = NRF24L01P_PIPE_P4;
+            channelNum = 4;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         case 16:     // Channel 5
-            rxAddr = txAddr = 0xC2C2C2C2C5;
-            pipe = NRF24L01P_PIPE_P5;
-            if (pipe != oldPipe) {
-                my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
-                my_nrf24l01p.setTxAddress(txAddr, width);
+            //rxAddr = txAddr = 0xC2C2C2C2C5;
+            //pipe = NRF24L01P_PIPE_P5;
+            channelNum = 5;
+            if (channelNum != oldChannel) {
+                //my_nrf24l01p.setRxAddress(rxAddr, width, pipe);
+                //my_nrf24l01p.setTxAddress(txAddr, width);
+                rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY;
+                my_nrf24l01p.setRfFrequency(rfFreq);
             }
             break;
         default:
@@ -205,7 +225,7 @@
 }
 
 // Displays the current info to the LCD display
-void lcdThread()
+/*void lcdThread()
 {
     while (1) {
         uLCD.locate(0, 0);
@@ -213,28 +233,30 @@
         uLCD.locate(0, 2);
         uLCD.printf("Rate: %d kbps", dataRate);
         uLCD.locate(0, 4);
-        uLCD.printf("TX: 0x%010llX", txAddr);
+        uLCD.printf("Addr: 0x%010llX", txAddr);
         uLCD.locate(0, 6);
-        uLCD.printf("RX: 0x%010llX", rxAddr);
-        uLCD.locate(0, 8);
+        //uLCD.printf("RX: 0x%010llX", rxAddr);
+        uLCD.printf("Channel: %d", channelNum);
+        uLCD.locate(0, 10);
         
         switch (mode) {
             case RECEIVE:
                 uLCD.printf("Mode:    Receiving");
                 break;
             case TRANSMIT:
+                uLCD.line(0, 8, 127, 8, BLACK);
                 uLCD.printf("Mode: Transmitting");
                 break;
         }
         
         // Maybe add some graphics too idk
-        Thread::wait(500);
+        Thread::wait(1000);
     }
-}
+}*/
 
 int main()
 {
-    Thread lcd;
+    //Thread lcd;
     Thread comm;    
     
     // Set up the nrf24l01p
@@ -264,7 +286,7 @@
     uLCD.background_color(BLACK);
     
     // Spawn threads
-    lcd.start(lcdThread);
+    //lcd.start(lcdThread);
     comm.start(commThread);
     
     // Setup the button to enter transmit mode when pushed down