Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
48:4c9551c826e9
Parent:
47:c66d2995f957
Child:
49:626e84ce5e52
diff -r c66d2995f957 -r 4c9551c826e9 proto_code.cpp
--- a/proto_code.cpp	Mon Jan 11 16:38:59 2016 +0000
+++ b/proto_code.cpp	Tue Jan 12 00:05:34 2016 +0000
@@ -23,7 +23,7 @@
 #define SILENT      0x20
 #define GRACE_PERIOD 3000
 
-#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need //////////////////////DEBUG messages on the console;
+#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need //////////////////////DEBUG messages on the console;
                                * it will have an impact on code-size and power consumption. */
 
 #define LOOPBACK_MODE       0  // Loopback mode
@@ -175,7 +175,7 @@
   
   ta.post_color(0xFF0000);
   
-  srand(millis());
+  srand( rndHW() );
 }
 #else
 static void slave_setup()
@@ -210,13 +210,13 @@
     if(last_state != state)
     {
         if(state == ACTIVE_TARGET)
-            writeToPhone("State is ACTIVE_TARGET\r\n");
+            DEBUG("State is ACTIVE_TARGET\r\n");
         if(state == IDLE)
-            writeToPhone("State is IDLE\r\n");
+            DEBUG("State is IDLE\r\n");
         if(state == FAIL)
-            writeToPhone("State is FAIL\r\n");
+            DEBUG("State is FAIL\r\n");
         if(state == SUCCESS)
-            writeToPhone("State is SUCCESS\r\n");
+            DEBUG("State is SUCCESS\r\n");
     }
     last_state = state;
 
@@ -366,7 +366,7 @@
     if (last_mode != mode)
     {
         if (mode == FREEFORM)
-            srand(millis());
+            srnd( rndHW() );
             writeToPhone("RR.\r\n");
             
         if (mode == PATTERN)
@@ -415,8 +415,7 @@
   fail_quick = mask & FAIL_QUICK;
   timeout = times[index];
   index++;
-  DEBUG("Next cone is \n");
-  DEBUG("%d\n",active_cone);
+  writeToPhone( "Next cone is %u\r\n", active_cone );  // PROTOCOL
   #endif
 }
 #if 1
@@ -953,20 +952,16 @@
 {
   if(tag_start)
   {
-    //DEBUG("Sequence started at cone ");
-    //DEBUG("%d",active_cone);
-    //DEBUG(" (");
-    printMsAsSeconds(timer);
-    //DEBUG(" seconds).\n");
+    writeToPhone( "Sequence started at cone %u (", active_cone );  // PROTOCOL
+    printMsAsSeconds(timer);                                       // PROTOCOL
+    writeToPhone( " seconds).\r\n" );                              // PROTOCOL
     tag_start = false;
   }
   else
   {
-   //DEBUG("Target cone is: ");
-   //DEBUG("%d",active_cone);
-   //DEBUG(", ");
-   printMsAsSeconds(timer);
-   //DEBUG(" split");
+    writeToPhone( "Target cone is: %u, ", active_cone );           // PROTOCOL
+    printMsAsSeconds(timer);                                       // PROTOCOL
+    writeToPhone( " split\r\n" );                                  // PROTOCOL
   }
 }
 
@@ -974,53 +969,19 @@
 {
   static uint8_t last_cone = 0;
   uint8_t cone;
-  int counter = 0;
-  
-  do
-  {
-    cone =  (rand() % NUM_CONES);
-    ++cone;
-    
-    if (cone == last_cone)
-    {
-        if (rand() % 2 == 1)
-        {
-            --cone;
-            
-            if (cone <= 0)
-            {
-                cone = NUM_CONES;    
-            }    
-        }
-        else
-        {
-            ++cone;
-            
-            if (cone > NUM_CONES)
-            {
-                cone = 1;    
-            }
-        }
-    }
-  }
-  while(active_cones[cone] == false && ++counter < 10);
-  
-  if (!active_cones[cone])
-  {
-      for (int i = 0; i < NUM_CONES; ++i)
-      {
-          if (i == last_cone || !active_cones[cone])
-          {
-              continue;    
-          }    
-          
-          cone = i;
-          break;
-      }
-  }
+
+  uint8_t avail = 1;
+  uint8_t ac[NUM_CONES] = {1};
+  for( uint8_t i=2; i<=NUM_CONES; i++ )
+    if( active_cones[i] && (i != last_cone) )  ac[avail++] = i;
+
+  cone = ((avail >1) ? ac[rnd() % avail] : 1);
+
+  writeToPhone( "Target cone is %u\r\n", cone );  // PROTOCOL
   
   last_cone = cone;
-  return cone;
+
+  return  cone;
 }
 
 static void clearCones(void)
@@ -1034,7 +995,7 @@
     m->cone = i;
     if(active_cones[i])
         ta.send(m);
-    active_cones[i] = false;
+///    active_cones[i] = false;
     //ta.send("q", i);
   }