Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
52:060fdec99780
Parent:
49:626e84ce5e52
Child:
53:c1c3e65b4542
diff -r fabe54861f1b -r 060fdec99780 proto_code.cpp
--- a/proto_code.cpp	Wed Jan 13 18:58:11 2016 +0000
+++ b/proto_code.cpp	Thu Jan 14 05:27:44 2016 +0000
@@ -125,7 +125,7 @@
 
 static const int active_colour  = 0x00FF00; /// 0x00FF;
 static const int warn_colour    = 0xFFA500; /// 0xF050;
-static const int fail_colour    = 0x00;     /// 0x0000FF;
+static const int fail_colour    = 0xFF0000; /// 0x0000FF;
 static const int touch_colour   = 0x0000FF; /// 0x005050;
 static const int success_colour = 0x00FF00; /// 0xFFFF;
 static const int pen_colour     = 0xFFFF00; /// 0x10FF;
@@ -231,7 +231,7 @@
         switch(m_in->command)
         {
         case 't':
-            timeout = 10000L;//m_in->value;
+            timeout = m_in->value;
             //serial.printf("timeout: ");
             //serial.printf("%d\n",timeout);
             break;
@@ -259,7 +259,7 @@
   if(message == 'f')
   { // Fail
      //serial.printf("Fail!\n");
-     writeToPhone("FAIL\r\n");
+     DEBUG("FAIL\r\n");
 ///  ta.post_color(fail_colour);
      ta.pulse(25,200,3000,fail_colour);
      state = FAIL;
@@ -268,7 +268,7 @@
   if(message == 's')
   {  // Success
     //serial.printf("Success!\n");
-    ta.post_color(0x0FFF00);
+    ta.post_color(success_colour);
     ta.beep(1500);
     state = SUCCESS;
   }
@@ -289,9 +289,9 @@
 
   if(message == 'q')
   {  // Quit
-    writeToPhone("Clear!\r\n");
+    DEBUG("Clear!\r\n");
     ta.pulse_off();
-    ta.mask_color(idle_colour);
+//    ta.mask_color(idle_colour);
     state = IDLE;
   }
   
@@ -332,7 +332,7 @@
       }
       else if(timer > timeout && !penalty)
       {
-        writeToPhone("PEN\r\n");
+        DEBUG("PEN\r\n");
         //serial.printf("Penalty!\n");
         penalty = true;
         ta.pulse(350,600,~0L,pen_colour);
@@ -340,7 +340,7 @@
       }
       else if(timer > ((timeout*3)/4) && !warning)
       {
-            writeToPhone("WARN\r\n");
+        DEBUG("WARN\r\n");
         //serial.printf("Warning!\n");
         warning = true;
         ta.pulse(350,750,~0L,warn_colour);
@@ -348,7 +348,7 @@
       }
       break;
     case IDLE:
-        bool act = ta.activated();
+      bool act = ta.activated();
       ta.post_color(act?touch_colour:idle_colour);
       break;
     default:
@@ -366,9 +366,10 @@
     if (last_mode != mode)
     {
         if (mode == FREEFORM)
+        {
             srnd( rndHW() );
             writeToPhone("RR.\r\n");
-            
+        }
         if (mode == PATTERN)
             writeToPhone("SP.\r\n");    
     }
@@ -399,9 +400,9 @@
     if(mode == FREEFORM)
     {
       active_cone = getRandomCone(); 
-      
-      writeToPhone("GN_AC: %d\r\n", active_cone);
-      
+
+      if( Dbg )  writeToPhone("GN_AC: %d\r\n", active_cone);
+
       mask = 0x07;
       ta.setMask(mask & LIGHTS);
       timeout = ~0;
@@ -436,7 +437,7 @@
   
     if(ta.recieve(m_in))
     {
-        writeToPhone("SR: %d '%c'\r\n", m_in->cone, m_in->command);
+        if( Dbg )  writeToPhone("SR: %d '%c'\r\n", m_in->cone, m_in->command);
         command = m_in->command;
         value = m_in->value;
     }
@@ -512,17 +513,19 @@
       m->value = mask;
       m->cone = active_cone;
       ta.send(m);
-      
-      wait_ms(300);
+
+      wait_ms(50);
+///      wait_ms(300);
       m->command = 't';
       m->value = (uint32_t)timeout;
       ta.send(m);
-      
-      wait_ms(300);
+
+      wait_ms(50);
+///      wait_ms(300);
       m->command = 'g';
       ta.send(m);
       
-      writeToPhone("ACW: %d\r\n", active_cone);      
+      if( Dbg )  writeToPhone("ACW: %d\r\n", active_cone);
     }
     
     ta.post_color(( ta.activated())?touch_colour:idle_colour);
@@ -533,9 +536,9 @@
     {
       if((timer >= timeout) && !fakeout)
       {
-        writeToPhone("TSP\r\n");
+        writeToPhone("Timesplit penalty! ");  // PROTOCOL
       }
-      printSplit(timer);
+      printSplit(timer);                      // PROTOCOL
       getNext(); 
       start = millis();
       
@@ -543,13 +546,13 @@
       
       if(state_p == WAITING_P) 
       {
-        writeToPhone("NSW\r\n");
+        if( Dbg )  writeToPhone("NSW\r\n");
         new_state = true;
         }
     }
     else if(~timeout != 0 && mode == PATTERN && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
     {
-      writeToPhone("FW\r\n");
+      if( Dbg )  writeToPhone("FW\r\n");
       state_p = FAIL_P;
     }
     break;
@@ -586,9 +589,9 @@
     if(ta.activated() || ((timer >= timeout) && fakeout))
     {
       if((timer >= timeout) && !fakeout)
-        DEBUG("Timesplit penalty! ");
-        
-      printSplit(timer);
+        writeToPhone("Timesplit penalty! ");  // PROTOCOL
+      printSplit(timer);                      // PROTOCOL
+
       ta.post_color(success_colour);
       getNext();
         start = millis();
@@ -968,10 +971,11 @@
 static uint8_t getRandomCone(void)
 {
   static uint8_t last_cone = 0;
+  static uint8_t ac[NUM_CONES] = {1};
+
   uint8_t cone;
 
   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;
 
@@ -1114,7 +1118,7 @@
   
   lonely = true;
   
-  writeToPhone("FC\r\n");
+  if( Dbg )  writeToPhone("FC\r\n");
   
   int retry_count = 0;
 
@@ -1130,7 +1134,7 @@
     unsigned long current = 0L;
     unsigned long delta = 0L;
     
-    writeToPhone("S: %lu F: %d\r\n", st, i);  /// DEBUG-only message
+    if( Dbg )  writeToPhone("S: %lu F: %d\r\n", st, i);
 
     while(1)
     {
@@ -1139,7 +1143,7 @@
       
       if(delta > 300L) 
       {
-        writeToPhone("FT: %d %lu\r\n", i, current);
+        if( Dbg )  writeToPhone("FT: %d %lu\r\n", i, current);
         
         if (++retry_count < 3)
         {
@@ -1155,15 +1159,15 @@
         lonely = false;
         active_cones[m_in->cone] = true;
         
-        writeToPhone("FS: %d\r\n", m_in->cone);
+        if( Dbg )  writeToPhone("FS: %d\r\n", m_in->cone);
         break;
       }
     }
     
     wait_us(50);
   }
-  
-  writeToPhone("available cones are: (1");
+
+  writeToPhone("Available cones are: (1");
   
   for(i = 2; i < NUM_CONES + 1; ++i)
   {
@@ -1182,7 +1186,7 @@
   
   remainder = number%1000;
 
-  writeToPhone( "%d.%03d", number/1000, remainder );  /// Needs to stay without newline.
+  writeToPhone( "%d.%03d", number/1000, remainder );  /// Needs to stay without CRLF.
 }
 
  static void spinButtons(void)