Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
58:fb2198ceb412
Parent:
49:626e84ce5e52
Child:
59:297133497153
--- a/proto_code.cpp	Tue Jan 12 14:50:32 2016 +0000
+++ b/proto_code.cpp	Sat Jan 16 17:24:38 2016 +0000
@@ -10,9 +10,6 @@
 #define ENABLE_3 p8
 
 #define DEBUG_BAUD  57600 //57600
-#define NUM_CONES         3
-#define STATIONS         20  // max length of a pattern
-#define SEQUENCES         9  // number of patterns to store
 
 #define TRILAT_CONE      99
 
@@ -23,7 +20,7 @@
 #define SILENT      0x20
 #define GRACE_PERIOD 3000
 
-#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need //////////////////////DEBUG messages on the console;
+#define NEED_CONSOLE_OUTPUT 1 /* 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
@@ -37,6 +34,10 @@
 #if 1
 extern int random(int numberone, int numbertwo);
 
+extern uint8_t* datastore_get_cones();
+extern uint8_t* datastore_get_masks();
+extern uint16_t* datastore_get_times();
+
 unsigned long millis();
 unsigned long micros();
 
@@ -88,15 +89,15 @@
 static volatile unsigned long ping_timer = 0;
 static volatile unsigned long dist_timeout = 0;
 
-// all sequence data
-uint8_t cone_table[STATIONS * SEQUENCES];
-uint8_t mask_table[STATIONS * SEQUENCES];
-uint16_t time_table[STATIONS * SEQUENCES];
+// These pointers are allocated in DataStore
+static uint8_t *cone_table  = NULL;
+static uint8_t *mask_table  = NULL;
+static uint16_t *time_table = NULL;
 
 // pointer to active table
-uint8_t *cones = (uint8_t*)cone_table;
-uint8_t *masks = (uint8_t*)mask_table; 
-uint16_t *times = (uint16_t*)time_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 bool lonely = false;
 
@@ -122,7 +123,6 @@
 
 extern "C" void writeToPhone(char *format, ...);
 
-
 static const int active_colour  = 0x00FF00; /// 0x00FF;
 static const int warn_colour    = 0xFFA500; /// 0xF050;
 static const int fail_colour    = 0x00;     /// 0x0000FF;
@@ -133,12 +133,9 @@
 
 char local_input[50] = {0};
 
-//DigitalOut red(RED);
-//DigitalOut enable1(ENABLE_1);
-//DigitalOut green(GREEN);
-//DigitalOut blue(BLUE);
-//DigitalOut enable2(ENABLE_2);
-//DigitalOut enable3(ENABLE_3);
+void datastore_write_patterns();
+void datastore_read_patterns();
+void write_test_pattern();
 
 #ifdef MASTER
 static void master_setup()
@@ -148,14 +145,11 @@
   uint16_t sent = 0;
   uint16_t lost = 0;
   unsigned long start = micros();
-  //while (millis() - now <= ACK_TIME){
+
   m->command = 'p';
   m->value = 0;
   m->cone = 0;
   
-  
-  //find_cones(); // this causes the beep to be interrupted
-  //ta.beep(100);  
   int i;
   
   for(i = 1; i < NUM_CONES + 1; ++i)
@@ -165,13 +159,9 @@
     
   unsigned long time = 0;
   
-  // pull course sequences from non-volatile memory  
-  for(uint8_t i = 0; i <STATIONS * SEQUENCES; ++i)
-  {
-    cone_table[i] = i+1;
-    mask_table[i] = 1;
-    time_table[i] = 1000;
-  }    
+  cone_table = datastore_get_cones();
+  mask_table = datastore_get_masks();
+  time_table = datastore_get_times();   
   
   ta.post_color(0xFF0000);
   
@@ -415,7 +405,8 @@
   fail_quick = mask & FAIL_QUICK;
   timeout = times[index];
   index++;
-  writeToPhone( "Next cone is %u\r\n", active_cone );  // PROTOCOL
+  writeToPhone("%d %x %d\r\n", active_cone, mask, timeout);
+  writeToPhone("Next cone is %u\r\n", active_cone);  // PROTOCOL
   #endif
 }
 #if 1
@@ -723,6 +714,8 @@
   uint8_t v;
   uint16_t val;
   
+  DEBUG("data\r\n");
+  
   switch(parameter)
   {
   case 'f':
@@ -752,6 +745,8 @@
     }
     else
     {
+      write_test_pattern();
+      datastore_read_patterns();
       writeToPhone("Selected pattern %d\r\n", value);
       
       if(value <= SEQUENCES && value > 0)
@@ -760,6 +755,11 @@
         cones = (uint8_t*)cone_table + (value-1)*STATIONS;
         times = (uint16_t*)time_table + (value-1)*STATIONS;
         masks = (uint8_t*)mask_table + (value-1)*STATIONS;
+        
+        for (int i = 0; i < STATIONS; ++i)
+        {
+            writeToPhone("PS: %d %x %d\r\n", cones[i], masks[i], times[i]);    
+        }
       }
       else
       {
@@ -905,21 +905,17 @@
     }
     break;
   case 'w':
-    if(value > 0 && value <= SEQUENCES){
+    if(value > 0 && value <= SEQUENCES)
+    {
       length = STATIONS;
       offset = (value - 1) * STATIONS;
       writeToPhone("Saved sequence %d\r\n", value);
     }
-    else{
-      length = STATIONS * SEQUENCES;
-      offset = 0;
+    else
+    {
+      datastore_write_patterns();
       writeToPhone("Saved all sequences.\r\n");
     }
-    for(i=offset;i<length+offset;i++){
-      //eeprom_update_byte(addressConeTable + i, cone_table[i]);
-      //eeprom_update_byte(addressMaskTable + i, mask_table[i]);
-      //eeprom_update_word(addressTimeTable + i, time_table[i]);
-    }
     break;
    case 'x':
      resetSensors();