Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
46:28c29ef61276
Parent:
45:1eb335c00cb2
Child:
47:c66d2995f957
--- a/proto_code.cpp	Sat Jan 09 21:46:34 2016 +0000
+++ b/proto_code.cpp	Mon Jan 11 16:34:46 2016 +0000
@@ -10,7 +10,6 @@
 #define ENABLE_3 p8
 
 #define DEBUG_BAUD  57600 //57600
-#define MAX_LEN          24  // buffer input commands up to this length
 #define NUM_CONES         3
 #define STATIONS         20  // max length of a pattern
 #define SEQUENCES         9  // number of patterns to store
@@ -18,10 +17,10 @@
 #define TRILAT_CONE      99
 
 #define DEBOUNCE_MS 100
-#define LIGHTS TOUCHLIGHTS
-#define FAKEOUT 0x08
-#define FAIL_QUICK 0x10
-#define SILENT 0x20
+#define LIGHTS      TOUCHLIGHTS
+#define FAKEOUT     0x08
+#define FAIL_QUICK  0x10
+#define SILENT      0x20
 #define GRACE_PERIOD 3000
 
 #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need //////////////////////DEBUG messages on the console;
@@ -182,7 +181,7 @@
 static void slave_setup()
 {
     ta.initialize(NODE_ID);
-    ta.beep(250);
+///    ta.beep(250);
 }
 #endif
 
@@ -206,6 +205,8 @@
     static State_t last_state = IDLE;
     static int counter = 0;
   
+    ta.spin();
+
     if(last_state != state)
     {
         if(state == ACTIVE_TARGET)
@@ -217,11 +218,8 @@
         if(state == SUCCESS)
             writeToPhone("State is SUCCESS\r\n");
     }
-     
     last_state = state;
 
-    ta.resetTouchIfStuck();
-  
     char message = 'n';
     timer = millis() - start;
   
@@ -255,17 +253,15 @@
   
   if(message == 'x')
   {
-    //a3 = 0;
-    wait_ms(100);
-    //a3 = 1;
+      ta.resetTouch();
   }
   
   if(message == 'f')
   { // Fail
      //serial.printf("Fail!\n");
      writeToPhone("FAIL\r\n");
-     ta.post_color(fail_colour);
-     //ta.pulse(25,200,3000,0xFF0000);
+///  ta.post_color(fail_colour);
+     ta.pulse(25,200,3000,fail_colour);
      state = FAIL;
   }
   
@@ -282,8 +278,8 @@
     start = millis();
     warning = false;
     penalty = false;
-    ta.post_color(active_colour);
-    //ta.pulse(50,750,0L,0x00FF00);
+/// ta.post_color(active_colour);
+    ta.pulse(50,750,~0L,active_colour);
     state = ACTIVE_TARGET;
     //serial.printf("fakeout, fail_quick\n");
     //serial.printf("%d",fakeout);
@@ -329,7 +325,7 @@
         m->command = 'd';
         m->cone = CONTROL_CONE;
         ta.send(m);
-        ta.post_color(success_colour);
+///     ta.post_color(success_colour);
         ta.pulse_off();
         state = IDLE;
         //serial.printf("Done!\n");
@@ -339,16 +335,16 @@
         writeToPhone("PEN\r\n");
         //serial.printf("Penalty!\n");
         penalty = true;
-        //ta.pulse(350,600,~0L,0xFF00FF);
-        ta.post_color(pen_colour);
+        ta.pulse(350,600,~0L,pen_colour);
+///     ta.post_color(pen_colour);
       }
       else if(timer > ((timeout*3)/4) && !warning)
       {
             writeToPhone("WARN\r\n");
         //serial.printf("Warning!\n");
         warning = true;
-        //ta.pulse(350,750,~0L,0xFFFF00);
-        ta.post_color(warn_colour);
+        ta.pulse(350,750,~0L,warn_colour);
+///     ta.post_color(warn_colour);
       }
       break;
     case IDLE:
@@ -408,7 +404,7 @@
       
       mask = 0x07;
       ta.setMask(mask & LIGHTS);
-      //timeout = ~0;
+      timeout = ~0;
       
       return;
   }
@@ -566,16 +562,16 @@
       
       warning = false;
       penalty = false;
-      ta.post_color(active_colour);
-      //ta.pulse(50,750,~0L,0x00FF00);
-      //if(!(mask & SILENT))ta.pulse(50,750,~0L,0c00FF00);
+///   ta.post_color(active_colour);
+      ta.pulse(50,750,~0L,active_colour);
+      //if(!(mask & SILENT))ta.pulse(50,750,~0L,active_colour);
     }
     if(timer >= timeout)
     {
       if(!penalty)
       {
-        ta.post_color(pen_colour);
-        //ta.pulse(50,325,~0L,0xFF00FF);
+///     ta.post_color(pen_colour);
+        ta.pulse(50,325,~0L,pen_colour);
         
         penalty = true;
       }
@@ -584,8 +580,8 @@
     else if(timer > ((timeout*3)/4) && !warning)
     {
       warning = true;
-      ta.post_color(warn_colour);
-      //ta.pulse(50,750,~0L,0xFFFF00);
+///   ta.post_color(warn_colour);
+      ta.pulse(50,750,~0L,warn_colour);
     }
 
     if(ta.activated() || ((timer >= timeout) && fakeout))
@@ -621,8 +617,8 @@
       DEBUG("\n");
       DEBUG("Timeout\n");
       //ta.post_color();
-      //ta.pulse(25,200,3000,0xFF0000);
-      ta.post_color(fail_colour);
+      ta.pulse(25,200,3000,fail_colour);
+///   ta.post_color(fail_colour);
       
       failCones(); 
       //ta.fail();
@@ -668,9 +664,10 @@
   int buffer_counter = 0;
   static char parameter = '_';
   static char buffer[MAX_LEN + 1];
+  static char trashArea[MAX_LEN + 1];
   int value = 0;
   char *endp = NULL;
-  
+
   // listen for commands coming over bluetooth
   while (buffer_counter < size)
   {
@@ -845,15 +842,15 @@
   case 'B':  // After setting bits, echo back station data.
     l = (uint8_t)value;
     masks[station-1] = l;
-    writeToPhone( "%c%02d;C%02d;T%05d;B%02x\r\n", (1==station) ? 'P'                 : 'S',
+    writeToPhone( "%c%02u;C%02u;T%05u;B%02x\r\n", (1==station) ? 'P'                 : 'S',
                                                   (1==station) ?  active_sequence +1 : station,
                                                   cones[station-1], times[station-1], l );
     break;
   case 'q':
     state_p = IDLE_P;
     new_state = true; // force state reporting, even if we're already in IDLE
-    //ta.pulse_off();
-    //clearCones();
+    ta.pulse_off();  /// //
+    clearCones();    /// //
     break;
   case 'r':
     //Serial.println(F(""));
@@ -861,12 +858,12 @@
     writeToPhone("Pattern is %d:\r\n", active_sequence+1);  // PROTOCOL optimization
     for(int i=0; i<STATIONS; i++){
       // writeToPhone("Station %d: cone %d, ", i+1, cones[i]);
-      writeToPhone("S%02d,C%02d", i+1, cones[i]);           // PROTOCOL optimization
+      writeToPhone("S%02u,C%02u", i+1, cones[i]);           // PROTOCOL optimization
       split = times[i];
       // printMsAsSeconds(split);               // Removed for PROTOCOL optimization
       //Serial.print(F("s timeout, lights: "));
       // writeToPhone("s timeout, config bits: ");
-      writeToPhone(",T%05d", split);                        // PROTOCOL optimization
+      writeToPhone(",T%05u", split);                        // PROTOCOL optimization
       l = masks[i];
       /*
       if(l<0b10000000)
@@ -928,9 +925,7 @@
     break;
    case 'x':
      resetSensors();
-     //digitalWrite(A3, LOW);
-     //delay(100);
-     //digitalWrite(A3, HIGH);
+     ta.resetTouch();
      break;
      
    case 'z':