Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
61:dd7002ceea96
Parent:
60:d1fad57e8bfb
Child:
62:9b34dc1b265d
diff -r d1fad57e8bfb -r dd7002ceea96 proto_code.cpp
--- a/proto_code.cpp	Sat Jan 16 19:11:49 2016 +0000
+++ b/proto_code.cpp	Sun Jan 17 07:03:51 2016 +0000
@@ -31,8 +31,8 @@
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
-#if 1
 extern int random(int numberone, int numbertwo);
+extern bool is_master;
 
 extern uint8_t* datastore_get_cones();
 extern uint8_t* datastore_get_masks();
@@ -47,13 +47,12 @@
 
 const static int CONTROL_CONE = 1;
 
-#ifdef MASTER
-static Mode_t mode = PATTERN;
+static Mode_t mode = PATTERN_M;
 static patternState_t state_p = IDLE_P;
 static inputState_t state_i = IDLE_I;
-#else
+
 State_t state = IDLE;
-#endif
+
 
 static Message m1 = { 'm',0,2 };
 
@@ -95,14 +94,13 @@
 static uint16_t *time_table = NULL;
 
 // pointer to active table
-static uint8_t *cones  = NULL;//(uint8_t*)cone_table;
-static uint8_t *masks  = NULL; //(uint8_t*)mask_table; 
-static uint16_t *times = NULL;//(uint16_t*)time_table;
+static uint8_t *cones  = NULL;
+static uint8_t *masks  = NULL; 
+static uint16_t *times = NULL;
 
 static bool lonely = false;
 
 // Function prototypes
-#ifdef MASTER
 void spin();
 patternState_t stateFromCone(uint8_t cone);
 void printSplit(unsigned long timer);
@@ -119,7 +117,7 @@
 Event getInputEvent(void); 
 void getRadioInput(char *ibuffer, int size);
 void interpret(char parameter, int value);
-#endif
+
 
 extern "C" void writeToPhone(char *format, ...);
 
@@ -138,7 +136,6 @@
 void datastore_read_patterns();
 void write_test_pattern();
 
-#ifdef MASTER
 static void master_setup()
 {
     ta.initialize(NODE_ID);
@@ -168,24 +165,25 @@
   
   srand( rndHW() );
 }
-#else
+
 static void slave_setup()
 {
     ta.initialize(NODE_ID);
-///    ta.beep(250);
 }
-#endif
+
 
 void setup()
 {
-    #ifdef MASTER
-    master_setup();
-    #else
-    slave_setup();
-    #endif    
+    if (is_master)
+    {
+        master_setup();
+    }
+    else
+    {
+        slave_setup();   
+    }    
 }
 
-#ifdef SLAVE
 static void slave_loop()
 {
     static unsigned long start = 0;
@@ -352,9 +350,7 @@
     break;
   }
 }
-#endif
 
-#ifdef MASTER
 static void master_loop()
 {
     static Mode_t last_mode = mode;
@@ -362,12 +358,12 @@
     
     if (last_mode != mode)
     {
-        if (mode == FREEFORM)
+        if (mode == FREEFORM_M)
         {
             srnd( rndHW() );
             writeToPhone("RR.\r\n");
         }
-        if (mode == PATTERN)
+        if (mode == PATTERN_M)
             writeToPhone("SP.\r\n");    
     }
     
@@ -380,21 +376,22 @@
    // else 
         spin();  
 }
-#endif  
 
 void loop()
 {
-    #ifdef MASTER
-    master_loop();
-    #else
-    slave_loop();
-    #endif
+    if (is_master)
+    {
+        master_loop();
+    }
+    else
+    {
+        slave_loop();
+    }
 }
 
 static void getNext()
 {
-    #ifdef MASTER
-    if(mode == FREEFORM)
+    if(mode == FREEFORM_M)
     {
       active_cone = getRandomCone(); 
 
@@ -418,12 +415,10 @@
   index++;
   writeToPhone("%d %x %d\r\n", active_cone, mask, timeout);
   writeToPhone("Next cone is %u\r\n", active_cone);  // PROTOCOL
-  #endif
 }
-#if 1
+
 static void spin()
 {
-#ifdef MASTER
     static patternState_t last_state = START_P;
     static uint8_t last_cone = 255;
     static unsigned long start;
@@ -570,7 +565,7 @@
         new_state = true;
       }
     }
-    else if(~timeout != 0 && mode == PATTERN && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
+    else if(~timeout != 0 && mode == PATTERN_M && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
     {
       if(Dbg)
       {  
@@ -625,7 +620,7 @@
       ta.pulse_off();
       
     }
-    else if(~timeout != 0 && mode == PATTERN && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
+    else if(~timeout != 0 && mode == PATTERN_M && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
     {
       state_p = FAIL_P;
       ta.pulse_off();
@@ -678,11 +673,8 @@
     ta.post_color(idle_colour);
     break;
   }  
-    #endif
 }
-#endif
 
-#ifdef MASTER
 void getRadioInput(char *ibuffer, int size)
 {
   static int i = 0;
@@ -761,7 +753,7 @@
     }
     
     writeToPhone("Entered freeform\r\n");
-    mode = FREEFORM;
+    mode = FREEFORM_M;
     state_p = START_P;
     clearCones();
     //find_cones();
@@ -772,7 +764,7 @@
       writeToPhone("\r\n");
       writeToPhone("Running pattern %d\r\n", active_sequence + 1);
       
-      mode = PATTERN;
+      mode = PATTERN_M;
       state_p = START_P;
       active_cone = 0;
       
@@ -1021,7 +1013,6 @@
 
 static void clearCones(void)
 {
-  #if 1
   uint8_t i;
   m->command = 'q';
   
@@ -1035,12 +1026,10 @@
   }
   
   DEBUG("sent clear\r\n"); 
-  #endif
 }
 
 static void powerupCones(uint8_t sound)
 {
-  #if 1
   uint8_t i;
   m->command = 'u';
   m->value = sound;
@@ -1067,13 +1056,11 @@
       //ta.send("f", i);
     }
   }
-  #endif
   //DEBUG("sent powerup");
 }
 
 static void failCones(void)
 {
-  #if 1
   uint8_t i;
   m->command = 'f';
   
@@ -1092,12 +1079,10 @@
   }
   
   //DEBUG("sent fail\n");
-  #endif
 }
 
 static void resetSensors(void)
 {
-  #if 1
   uint8_t i;
   m->command = 'x';
   
@@ -1110,12 +1095,10 @@
   }
   
   DEBUG("sent sensor reset\n");
-  #endif
 }
 
 static void successCones(void)
 {
-  #if 1
   uint8_t i;
   m->command = 's';
   
@@ -1131,9 +1114,6 @@
   {
     ta.spin();
   }
-  
-  //DEBUG("sent success\n");
-  #endif
 }
 
 static void find_cones(void)
@@ -1280,7 +1260,7 @@
     {
       state_i = RUNNING_I;
       //send 'p' or 'f' command as appropriate
-      if(mode == FREEFORM)
+      if(mode == FREEFORM_M)
         interpret('f', 0);
       else 
         interpret('p', 0);
@@ -1316,7 +1296,7 @@
       // set state here based on current light color
       if(section < 2)
       {
-        mode = FREEFORM;
+        mode = FREEFORM_M;
         ta.post_color(0xFF);
         ////////DEBUG.println(F("Freeform mode.");
         state_i = IDLE_I;
@@ -1325,7 +1305,7 @@
       
       if(section < 4)
       {
-        mode = PATTERN;
+        mode = PATTERN_M;
         ta.post_color(0xFF00);
         ////////DEBUG.println(F("Pattern mode.");
         state_i = IDLE_I;
@@ -1344,7 +1324,7 @@
     if(first_i)
     {
       sequence = active_sequence;
-      mode = PATTERN;
+      mode = PATTERN_M;
       //start = millis();
     }
     if(event.type == Event::tap)
@@ -1485,6 +1465,3 @@
   last_buttons = buttons;
   return event;
 }
-#endif
-
-#endif
\ No newline at end of file