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:
- 38:76e49d045a3b
- Parent:
- 35:c1405da88d3a
- Child:
- 39:b1f864b71318
--- a/proto_code.cpp Wed Jan 06 22:19:10 2016 +0000
+++ b/proto_code.cpp Fri Jan 08 19:13:02 2016 +0000
@@ -62,7 +62,7 @@
static Message *m_in = &m2;
static uint8_t active_cone = 0;
-static unsigned long timeout = 0;
+static unsigned long timeout = 10000L;
static uint8_t mask = 0x07;
static uint8_t fakeout = 0;
static uint8_t fail_quick = 0;
@@ -123,6 +123,15 @@
extern "C" void writeToPhone(char *format, ...);
+
+static const int active_colour = 0x00FF;
+static const int warn_colour = 0xF050;
+static const int fail_colour = 0x0000FF;
+static const int touch_colour = 0x005050;
+static const int success_colour = 0xFFFF;
+static const int pen_colour = 0x10FF;
+static const int idle_colour = 0x00;
+
char local_input[50] = {0};
//DigitalOut red(RED);
@@ -198,13 +207,13 @@
if(last_state != state)
{
if(state == ACTIVE_TARGET)
- writeToPhone("State is ACTIVE_TARGET\n");
+ writeToPhone("State is ACTIVE_TARGET\r\n");
if(state == IDLE)
- writeToPhone("State is IDLE");
+ writeToPhone("State is IDLE\r\n");
if(state == FAIL)
- writeToPhone("State is FAIL");
+ writeToPhone("State is FAIL\r\n");
if(state == SUCCESS)
- writeToPhone("State is SUCCESS");
+ writeToPhone("State is SUCCESS\r\n");
}
last_state = state;
@@ -218,13 +227,11 @@
{
//ta.beep(1000);
- writeToPhone("got message\r\n");
-
message = m_in->command;
switch(m_in->command)
{
case 't':
- timeout = m_in->value;
+ timeout = 10000L;//m_in->value;
//serial.printf("timeout: ");
//serial.printf("%d\n",timeout);
break;
@@ -254,14 +261,16 @@
if(message == 'f')
{ // Fail
//serial.printf("Fail!\n");
- ta.pulse(25,200,3000,0xFF0000);
+ writeToPhone("FAIL\r\n");
+ ta.post_color(fail_colour);
+ //ta.pulse(25,200,3000,0xFF0000);
state = FAIL;
}
if(message == 's')
{ // Success
//serial.printf("Success!\n");
- ta.post_color(0x00FF00);
+ ta.post_color(0x0FFF00);
ta.beep(1500);
state = SUCCESS;
}
@@ -271,7 +280,8 @@
start = millis();
warning = false;
penalty = false;
- ta.pulse(50,750,~0L,0x00FF00);
+ ta.post_color(active_colour);
+ //ta.pulse(50,750,0L,0x00FF00);
state = ACTIVE_TARGET;
//serial.printf("fakeout, fail_quick\n");
//serial.printf("%d",fakeout);
@@ -283,7 +293,7 @@
{ // Quit
writeToPhone("Clear!\r\n");
ta.pulse_off();
- ta.mask_color(0xFF0000);
+ ta.mask_color(idle_colour);
state = IDLE;
}
@@ -317,25 +327,31 @@
m->command = 'd';
m->cone = CONTROL_CONE;
ta.send(m);
+ ta.post_color(success_colour);
ta.pulse_off();
state = IDLE;
//serial.printf("Done!\n");
}
else if(timer > timeout && !penalty)
{
+ writeToPhone("PEN\r\n");
//serial.printf("Penalty!\n");
penalty = true;
- ta.pulse(50,325,~0L,0xFF00FF);
+ //ta.pulse(350,600,~0L,0xFF00FF);
+ ta.post_color(pen_colour);
}
else if(timer > ((timeout*3)/4) && !warning)
{
+ writeToPhone("WARN\r\n");
//serial.printf("Warning!\n");
warning = true;
- ta.pulse(50,750,~0L,0xFFFF00);
+ //ta.pulse(350,750,~0L,0xFFFF00);
+ ta.post_color(warn_colour);
}
break;
case IDLE:
- ta.post_color((ta.activated())?0xFF:0xFF0000);
+ bool act = ta.activated();
+ ta.post_color(act?touch_colour:idle_colour);
break;
default:
break;
@@ -352,19 +368,19 @@
if (last_mode != mode)
{
if (mode == FREEFORM)
- writeToPhone("Now running random routes.\n");
+ writeToPhone("RR.\r\n");
if (mode == PATTERN)
- writeToPhone("Now running set patterns.\n");
+ writeToPhone("SP.\r\n");
}
last_mode = mode;
ta.spin();
//spinButtons();
- if((logging || micros() < dist_timeout) && ta.recieve(m_in))
- writeToPhone("%c",m_in->command);
- else
+ //if((logging || micros() < dist_timeout) && ta.recieve(m_in))
+ // writeToPhone("CMD: %c",m_in->command);
+ // else
spin();
}
#endif
@@ -383,15 +399,19 @@
#ifdef MASTER
if(mode == FREEFORM)
{
- DEBUG("get next freeform\r\n");
++active_cone;//getRandomCone();
- if (active_cone > 6)
+
+ if (active_cone > NUM_CONES)
{
active_cone = 1;
}
+
+ writeToPhone("GN_AC: %d\r\n", active_cone);
+
mask = 0x07;
ta.setMask(mask & LIGHTS);
- timeout = ~0;
+ //timeout = ~0;
+
return;
}
@@ -423,7 +443,7 @@
if(ta.recieve(m_in))
{
- DEBUG("spin received: %d '%c'\r\n", m_in->cone, m_in->command);
+ writeToPhone("SR: %d '%c'\r\n", m_in->cone, m_in->command);
command = m_in->command;
value = m_in->value;
}
@@ -459,13 +479,13 @@
case IDLE_P:
ta.setMask( DEFTOUCHMASK );
if(!in_menu)
- ta.post_color((ta.activated())?0xFF:0xFF0000);
+ ta.post_color((ta.activated())?touch_colour:idle_colour);
break;
case START_P:
- //clearCones();
+ clearCones();
tag_start = false;
- ta.post_color(0xFF0000);
+ ta.post_color(idle_colour);
index = 0;
getNext();
@@ -473,9 +493,8 @@
{ // timeout of 0 means wait indefinitely for the first cone to be activated, then start the rest of the sequence
timeout = ~0;
tag_start = true;
- DEBUG("Activate cone ");
- DEBUG("%d",active_cone);
- DEBUG(" to start.\n");
+
+ writeToPhone("ACS: %d\r\n", active_cone);
}
start = millis();
@@ -484,6 +503,7 @@
{ // in this case stateFromCone returns SUCCESS_P, but really there was no course sequence
DEBUG("\n");
DEBUG("Empty course sequence!\n");
+ writeToPhone("ECS\r\n");
ta.post_color(0x0000FF);
state_p = IDLE_P;
break;
@@ -497,19 +517,20 @@
m->value = mask;
m->cone = active_cone;
ta.send(m);
+
+ wait_ms(300);
m->command = 't';
m->value = (uint32_t)timeout;
ta.send(m);
+
+ wait_ms(300);
m->command = 'g';
ta.send(m);
- DEBUG("m_in cone=%d\n", active_cone);
- m_in->cone = active_cone;
- command = 'd';
-
+ writeToPhone("ACW: %d\r\n", active_cone);
}
- ta.post_color(( ta.activated())?0xFF:0xFF0000);
+ ta.post_color(( ta.activated())?touch_colour:idle_colour);
DEBUG("Waiting: %d %d %c\n", m_in->cone, active_cone, command);
@@ -517,7 +538,7 @@
{
if((timer >= timeout) && !fakeout)
{
- DEBUG("Timesplit penalty! ");
+ writeToPhone("TSP\r\n");
}
printSplit(timer);
getNext();
@@ -527,13 +548,13 @@
if(state_p == WAITING_P)
{
- DEBUG("New state from waiting\n");
+ writeToPhone("NSW\r\n");
new_state = true;
}
}
else if(~timeout != 0 && mode == PATTERN && timer >= (timeout + ((fail_quick)?0:GRACE_PERIOD)))
{
- DEBUG("Failing from wait\n");
+ writeToPhone("FW\r\n");
state_p = FAIL_P;
}
break;
@@ -545,23 +566,26 @@
warning = false;
penalty = false;
- ta.pulse(50,750,~0L,0x00FF00);
+ ta.post_color(active_colour);
+ //ta.pulse(50,750,~0L,0x00FF00);
//if(!(mask & SILENT))ta.pulse(50,750,~0L,0c00FF00);
}
if(timer >= timeout)
{
if(!penalty)
{
- ta.pulse(50,325,~0L,0xFF00FF);
+ ta.post_color(pen_colour);
+ //ta.pulse(50,325,~0L,0xFF00FF);
penalty = true;
}
- ta.mask_color(0xFF00FF);
+ ta.post_color(pen_colour);
}
else if(timer > ((timeout*3)/4) && !warning)
{
warning = true;
- ta.pulse(50,750,~0L,0xFFFF00);
+ ta.post_color(warn_colour);
+ //ta.pulse(50,750,~0L,0xFFFF00);
}
if(ta.activated() || ((timer >= timeout) && fakeout))
@@ -570,7 +594,7 @@
DEBUG("Timesplit penalty! ");
printSplit(timer);
- ta.post_color(0xFF0000);
+ ta.post_color(success_colour);
getNext();
start = millis();
state_p = stateFromCone(active_cone);
@@ -597,7 +621,8 @@
DEBUG("\n");
DEBUG("Timeout\n");
//ta.post_color();
- ta.pulse(25,200,3000,0xFF0000);
+ //ta.pulse(25,200,3000,0xFF0000);
+ ta.post_color(fail_colour);
failCones();
//ta.fail();
@@ -615,7 +640,7 @@
start = millis();
DEBUG("\n");
DEBUG("Done!\n");
- ta.post_color(0x00FF00);
+ ta.post_color(success_colour);
ta.beep(1500);
successCones();
//ta.success();
@@ -629,6 +654,7 @@
break;
default:
+ ta.post_color(idle_colour);
break;
}
#endif
@@ -928,7 +954,7 @@
static void clearCones(void)
{
- #if 0
+ #if 1
uint8_t i;
m->command = 'q';
@@ -980,7 +1006,7 @@
static void failCones(void)
{
- #if 0
+ #if 1
uint8_t i;
m->command = 'f';
@@ -1004,7 +1030,7 @@
static void resetSensors(void)
{
- #if 0
+ #if 1
uint8_t i;
m->command = 'x';
@@ -1022,7 +1048,7 @@
static void successCones(void)
{
- #if 0
+ #if 1
uint8_t i;
m->command = 's';
@@ -1124,7 +1150,7 @@
remainder = number%1000;
- writeToPhone( "%d.%03d", number/1000, remainder );
+ writeToPhone( "%d.%03d\r\n", number/1000, remainder );
}
static void spinButtons(void)
