in d mix

Dependencies:   xtoff2 RF24Network mbed

Fork of RF24Network_Receive by Akash Vibhute

Revision:
14:3e69c8a9c730
Parent:
13:f54dfb74247e
--- a/main.cpp	Wed Mar 21 16:22:28 2018 +0000
+++ b/main.cpp	Thu Jul 12 08:56:54 2018 +0000
@@ -22,7 +22,7 @@
      ---- -----
 */
 //uncommend #define PRINT_ENABLE to see informational prints
-//#define PRINT_ENABLE
+#define PRINT_ENABLE
 
 #include "mbed.h"
 #include "Ontvanger.h"
@@ -58,37 +58,51 @@
 
 int main()
 {
-    IF_PRINT_ENABLE( pc.printf("\r\nOntvanger: \r\n");
-                     pc.printf("testing Radio... %d\r\n", receive.isValid());
+    IF_PRINT_ENABLE( pc.printf("\r\nVOntvanger: \r\n");
+                     pc.printf("Vtesting Radio... %d\r\n", receive.isValid());
                    );
 
     while(1) {
         receive.update();
         switch (current_state) {
             case init_state:
-                IF_PRINT_ENABLE(pc.printf("Init State\n\r"););
+                IF_PRINT_ENABLE(pc.printf("XInit State\n\r"););
                 pc.baud(9600);
                 t.start();
                 state_Packet packet;
                 payload_t payload;
-                setCurrentState(receive_state);
+                setCurrentState(testConnection_state);
+                break;
+                
+            case testConnection_state:
+                IF_PRINT_ENABLE(pc.printf("XTesting State\n\r"););
+                packet.setState = 't';
+                
+                if (receive.write(packet)){
+                    pc.printf("VConnection test passed.\n\r");
+                    setCurrentState(receive_state);
+                    }
+                else
+                    IF_PRINT_ENABLE(pc.printf("VConnection failed, trying again...\n\r"););
+                    
+                wait_ms(500);
                 break;
 
             case send_state:
-                IF_PRINT_ENABLE(pc.printf("Send State\n\r"););
+                IF_PRINT_ENABLE(pc.printf("SSend State\n\r"););
                 if(c == 's') {
-                    IF_PRINT_ENABLE(pc.printf("Send state: Tare\n\r"););
+                    IF_PRINT_ENABLE(pc.printf("VSend state: Tare\n\r"););
                     packet.setState = 's';
                 }
                 if (c == 'c') {
-                    IF_PRINT_ENABLE(pc.printf("Send state: Calibrate\n\r"););
+                    IF_PRINT_ENABLE(pc.printf("VSend state: Calibrate\n\r"););
                     packet.setState = 'c';
                 }
                 bool ok = receive.write(packet);
                 if (ok)
-                    IF_PRINT_ENABLE(pc.printf("ok.\n\r"););
+                    IF_PRINT_ENABLE(pc.printf("Vok.\n\r"););
                 else
-                    IF_PRINT_ENABLE(pc.printf("failed.\n\r"););
+                    IF_PRINT_ENABLE(pc.printf("Vfailed.\n\r"););
                 wait(0.1);
                 setCurrentState(receive_state);
                 break;