Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Files at this revision

API Documentation at this revision

Comitter:
AntonLS
Date:
Tue Jan 12 14:50:32 2016 +0000
Parent:
48:4c9551c826e9
Child:
50:efe0f3017848
Child:
58:fb2198ceb412
Commit message:
Revert to slave ad often. Misc.

Changed in this revision

TA.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
proto_code.cpp Show annotated file Show diff for this revision Revisions of this file
types.h Show annotated file Show diff for this revision Revisions of this file
--- a/TA.cpp	Tue Jan 12 00:05:34 2016 +0000
+++ b/TA.cpp	Tue Jan 12 14:50:32 2016 +0000
@@ -130,7 +130,7 @@
 
 DigitalOut TA::buzzPin( p20, BUZZ_OFF );
 
-uint8_t TA::buttonsRising = 0;  // Appease compiler
+uint8_t TA::buttonsRising = 0;
 
 #if 1
 // inputs
@@ -482,10 +482,14 @@
 
 bool TA::activated(void)
 {
-    return  ((buttons() & mask) ||
-             /* Default to enabling activation on disabled--Except if mask has DIS_ON_DARK set */
-             (!(mask & TOUCHLIGHTS) != !!(mask & DIS_ON_DARK))
-            ) ? true : false; 
+    bool retval = ((((buttons() | buttonsRising) & mask) ||
+                    /* Default to enabling activation on disabled--Except if mask has DIS_ON_DARK set */
+                    (!(mask & TOUCHLIGHTS) != !!(mask & DIS_ON_DARK))
+                   ) ? true : false);
+
+    TA::buttonsRising = 0;
+
+    return  retval;
 }
 
 bool TA::tripped(void)
--- 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);
--- a/proto_code.cpp	Tue Jan 12 00:05:34 2016 +0000
+++ b/proto_code.cpp	Tue Jan 12 14:50:32 2016 +0000
@@ -1345,8 +1345,7 @@
   if(time - last_time > DEBOUNCE_MS)
   {
     last_time = time;
-    buttons = ta.buttons() | TA::buttonsRising;
-    TA::buttonsRising = 0;
+    buttons = ta.buttons();
   }
   
   return buttons;
--- a/types.h	Tue Jan 12 00:05:34 2016 +0000
+++ b/types.h	Tue Jan 12 14:50:32 2016 +0000
@@ -44,8 +44,8 @@
 
 extern "C" void writeToPhone(char *data, ...);
 extern "C" void writeBitsToPhone( uint8_t byte, uint8_t minbits = 1 );
-extern "C" uint32_t rndHW();
-extern "C" void srnd( uint32_t seed );
-extern "C" uint32_t rnd();
+extern uint32_t rndHW();
+extern void srnd( uint32_t seed );
+extern uint32_t rnd();
 
 #endif
\ No newline at end of file