football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
63:efba30dea1f0
Parent:
62:9b34dc1b265d
Child:
66:18c214707b0c
--- a/main.cpp	Mon Jan 18 08:51:31 2016 +0000
+++ b/main.cpp	Tue Jan 19 03:03:02 2016 +0000
@@ -72,12 +72,6 @@
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
-#ifdef MASTER
-bool is_master = true;
-#else
-bool is_master = false;
-#endif
-
 void loop();
 void setup();
 void getRadioInput(char *ibuffer, int size);
@@ -138,6 +132,11 @@
 static DigitalOut led1( P0_21, 0 );           // TA New Baseboard  High=On  (OK on Nano: NC)
 DigitalOut led2( P0_22, 1 );                  // TA New Baseboard  High=On  (OK on Nano: NC)
 
+// DigitalOut led1( P0_3,  0 );                  // TA Baseboard  High=On  (OK on Nano: Alt RxD)
+// DigitalOut led1( (trSwp ? P0_4 : P0_3), 0 );  // TA Baseboard  High=On  (And don't use P0_4 on Nano)
+ 
+// DigitalOut buzz( P0_20, 1 );                  // TA New Baseboard  Low=On  (OK on Nano: NC)
+ 
 int tickTock = 0;  // Counter used by periodicCallback().
 
 class ChgChg : public InterruptIn
@@ -214,6 +213,12 @@
 extern void radio_init();
 extern void radio_loop(int mac);
 
+#ifdef MASTER
+bool is_master = true;
+#else
+bool is_master = false;
+#endif
+
 void setAdvData()
 {
     ble.accumulateAdvertisingPayload( GapAdvertisingData::BREDR_NOT_SUPPORTED |
@@ -307,6 +312,11 @@
                          const Gap::address_t peerAddr, const Gap::ConnectionParams_t *connParams )
 {
     connected = true;
+
+    // DEBUG( "Connected!\n\r" );
+ 
+//    char dummy;
+//    writeToPhone( "Hi.  Curr stack bot: 0x%08X\r\n", &dummy );
 }
 
 void disconnectionCallback( Gap::Handle_t handle, Gap::DisconnectionReason_t reason )
@@ -315,6 +325,8 @@
 
     updateBatt( getBattLevel() );
 
+    // DEBUG( "Disconnected!\n\r" );
+    // DEBUG( "Restarting the advertising process\n\r" );
     ble.startAdvertising();
 
     ta.post_color(0);
@@ -345,6 +357,8 @@
     va_start( arg, format );
     
     phoneP->vprintf( format, arg );
+    // Also write same to serial port... TODO
+    // pcfc.vprintf( format, arg );
 
     va_end(arg);
 }
@@ -474,9 +488,13 @@
     
     wait_us(400);
     
-    //is_master = //datastore_is_master();
-    Ticker ticker;
+    //is_master = datastore_is_master();
 
+//    Ticker ticker;
+//////ticker.attach( periodicCallback, 0.125 /** 0.2 **/ /** 0.5 **/ /* 1 */ );
+
+/////pcfc.baud( 57600 );
+ 
     ble.init();
     
     ble.onConnection( connectionCallback );
@@ -487,6 +505,14 @@
     /* setup advertising */
     setAdvData();
 
+    /////pcfc.printf( "\r\nHello!   I am \"%s\"\r\n", deviceName );
+
+  /*
+#if LOOPBACK_MODE
+    pcfc.printf( "\r\nIn BLE Loopback mode.\r\n" );
+#endif
+  */
+
     srnd( rndHW() );  // Seed the sw RNG w/ the hw.
 
     DeviceInformationService deviceInfo( ble, "TRX", "TrueAgility", "SN0001", "hw-rev1", "fw-rev1" );
@@ -524,8 +550,10 @@
     unsigned long currMillis = lastMillis +25;
     
     // Main Loop
-    while( true )  
+    while( true )  // for( uint32_t loop=1; ;loop++ )
     {
+//        ble.waitForEvent();
+
         currMillis = millis();
         
         if( currMillis -lastMillis < 25 )  
@@ -537,11 +565,14 @@
 
         periodicCallback();
 
-        toPhoneChk();  
+        toPhoneChk();  // Write any pending data to phone.  
 
-        int bytes = MIN( MAX_LEN, phoneP->readable() );
-        getRadioInput( phoneToDev, phoneP->read( phoneToDev, bytes, 1 ) );
-        
+        if( is_master || Dbg )
+        {
+            int bytes = MIN( MAX_LEN, phoneP->readable() );
+            getRadioInput( phoneToDev, phoneP->read( phoneToDev, bytes, 1 ) );
+        }
+
         loop();
         radio_loop(mac_addr);
     }