Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: proto_code.cpp
- Revision:
- 59:297133497153
- Parent:
- 55:b3cb69d69ce8
- Parent:
- 58:fb2198ceb412
- Child:
- 60:d1fad57e8bfb
diff -r b3cb69d69ce8 -r 297133497153 proto_code.cpp
--- a/proto_code.cpp Sat Jan 16 03:45:13 2016 +0000
+++ b/proto_code.cpp Sat Jan 16 17:31:27 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 = 0xFF0000; /// 0x0000FF;
@@ -134,12 +134,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()
@@ -149,14 +146,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)
@@ -166,13 +160,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);
@@ -423,7 +413,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
@@ -741,6 +732,8 @@
uint8_t v;
uint16_t val;
+ DEBUG("data\r\n");
+
switch(parameter)
{
case 'f':
@@ -770,6 +763,8 @@
}
else
{
+ write_test_pattern();
+ datastore_read_patterns();
writeToPhone("Selected pattern %d\r\n", value);
if(value <= SEQUENCES && value > 0)
@@ -778,6 +773,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
{
@@ -923,21 +923,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();
