football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
49:626e84ce5e52
Parent:
48:4c9551c826e9
Child:
51:fabe54861f1b
Child:
58:fb2198ceb412
--- a/main.cpp	Tue Jan 12 00:05:34 2016 +0000
+++ b/main.cpp	Tue Jan 12 14:50:32 2016 +0000
@@ -206,7 +206,7 @@
                                         'T', 'X' };  // Custom ID trick
 
 UARTService    *uartServicePtr;
-PhoneAppIO     *phoneP = NULL;
+PhoneAppIO     *phoneP;
 BatteryService *battServiceP;
 
 // Buffer for holding data from the phone
@@ -349,6 +349,8 @@
 
 extern "C" void writeToPhone(char *format, ...)
 {
+    if( NULL == phoneP )  return;
+
     va_list arg;
     va_start( arg, format );
     
@@ -360,7 +362,7 @@
     va_end(arg);
 }
 
-/**/ // Byte bits to ASCII - Use until we convert protocol to ASCII-hex.
+/**/ // Byte bits to ASCII.
 extern "C" void writeBitsToPhone( uint8_t byte, uint8_t minbits )
 {
     static char ascbits[9] = { 0 };
@@ -570,20 +572,27 @@
 void periodicCallback( void )
 {
     static int callCnt;
-    if( (callCnt++ % /* 5 */ 4 ) != 0 )  return;
-    callCnt = 1;
+    do
+    {
+//        if( is_master && ((callCnt % 3) == 0) )  writeToPhone( "Rnd: %u\r\n", rnd() );
+ 
+        if( (callCnt % 4) != 0 )  break;
 
 #if BLENANO
-    led0 = !led0;
+        led0 = !led0;
 #endif
-    led1 = !led1;
-    led2 = !led2;
-//    rts  = !rts;
+        led1 = !led1;
+        led2 = !led2;
+//        rts  = !rts;
 
-    // Check battery level every 30s.
-    if( 0 == (tickTock % /* 30 */ 60 ) )  updateBatt( getBattLevel() );
+        // Check battery level every 30s.
+        if( 0 == (tickTock % /* 30 */ 60 ) )  updateBatt( getBattLevel() );
 
-    tickTock++;
+        tickTock++;
+
+    } while( false );
+
+    callCnt++;
 }
 
 /*
@@ -684,7 +693,7 @@
     UARTService uartService( ble );
     uartServicePtr = &uartService;
 
-    ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( is_master ? 132 : 5000 ) );
+    ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( is_master ? 132 : 132 ) );
 
     ble.startAdvertising();
 
@@ -754,7 +763,7 @@
     NVIC_SystemReset();
 }
 
-extern "C" uint32_t rndHW()
+uint32_t rndHW()
 {
     uint32_t rndVal;
     uint8_t bytes_available;
@@ -773,7 +782,7 @@
 
 static uint32_t rndZ = 0xCAFE, rndW = 0xF00D;
 // Seed for rnd()
-extern "C" void srnd( uint32_t seed )
+void srnd( uint32_t seed )
 {
     rndZ = 0xCAFE;
     rndW = seed;
@@ -781,7 +790,7 @@
 
 // Simple RNG -- Allows cross-platform compat if we want to run
 //  an apples-to-apples freeform competition by using same seed.
-extern "C" uint32_t rnd()
+uint32_t rnd()
 {
     rndZ = 36969 * (rndZ & 0xffff) + (rndZ >>16);
     rndW = 18000 * (rndW & 0xffff) + (rndW >>16);