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:
- 18:affef3a7db2a
- Parent:
- 17:d8b901d791fd
- Child:
- 19:afcbb425b3cf
diff -r d8b901d791fd -r affef3a7db2a proto_code.cpp
--- a/proto_code.cpp Tue Nov 03 07:05:15 2015 +0000
+++ b/proto_code.cpp Sun Nov 29 13:52:53 2015 +0000
@@ -36,49 +36,50 @@
#define DEBUG(...) /* nothing */
#endif /* #if NEED_CONSOLE_OUTPUT */
+#if 1
extern int random(int numberone, int numbertwo);
-void writeToPhone(char *data);
unsigned long millis();
unsigned long micros();
TA ta;
-bool active_cones[NUM_CONES + 1]; // + 1 so we can be 1 based like the cone numbers are
+static bool active_cones[NUM_CONES + 1]; // + 1 so we can be 1 based like the cone numbers are
-Mode_t mode = PATTERN;
-patternState_t state_p = IDLE_P;
-inputState_t state_i = IDLE_I;
+static Mode_t mode = PATTERN;
+static patternState_t state_p = IDLE_P;
+static inputState_t state_i = IDLE_I;
-Message m1 = { 'm',0,2 };
+static Message m1 = { 'm',0,2 };
-Message *m = &m1;
-Message m2 = { 'm',0,2 };
-Message *m_in = &m2;
+static Message *m = &m1;
+static Message m2 = { 'm',0,2 };
+static Message *m_in = &m2;
-uint8_t active_cone = 0;
-unsigned long timeout = 0;
-uint8_t mask = 0x07;
-uint8_t fakeout = 0;
-uint8_t fail_quick = 0;
-uint8_t index = 0;
-bool new_state = false;
-bool tag_start = false; // flag to indicate we should wait for the user to activate the first station before going through the sequence
+static uint8_t active_cone = 0;
+static unsigned long timeout = 0;
+static uint8_t mask = 0x07;
+static uint8_t fakeout = 0;
+static uint8_t fail_quick = 0;
+static uint8_t index = 0;
+static bool new_state = false;
+static bool tag_start = false; // flag to indicate we should wait for the user to activate the first station before going through the sequence
+
static bool in_menu = false;
static bool warning = false;
static bool penalty = false;
static bool logging = false;
// course setup (probably should make some of these persistant settings)
-uint8_t active_sequence = 0;
-//uint8_t pattern = 1;
-uint8_t station = 1;
-uint8_t cone = 0;
-uint16_t ltime = 0;
+static uint8_t active_sequence = 0;
+static uint8_t station = 1;
+static uint8_t cone = 0;
+static uint16_t ltime = 0;
volatile bool triggered;
volatile bool pin;
volatile bool ping = false;
+
static volatile bool captured = false;
static volatile unsigned long ping_timer = 0;
static volatile unsigned long dist_timeout = 0;
@@ -147,34 +148,23 @@
mask_table[i] = 1;
time_table[i] = 1000;
}
+
+ ta.post_color(0xFF0000);
}
void loop()
{
- // wdt_reset();
-
static Mode_t last_mode = mode;
-
- if (last_mode != mode)
- {
- ////DEBUG("\n");
-
- // if (mode == FREEFORM)
- //////DEBUG("Now running random routes.\n");
-
- //if (mode == PATTERN)
- //////DEBUG("Now running set patterns.\n");
- }
-
+
last_mode = mode;
- //getRadioInput();
- ta.spin();
+ //ta.spin();
+ DEBUG("spinning");
//spinButtons();
//if((logging || micros() < dist_timeout) && ta.recieve(m_in))
// //////DEBUG("%c",m_in->command);
//else
- spin();
+ spin();
}
void getNext()
@@ -202,7 +192,7 @@
DEBUG("Next cone is \n");
DEBUG("%d\n",active_cone);
}
-
+#if 1
void spin()
{
@@ -429,6 +419,34 @@
}
}
+#endif
+
+#if 0
+void clearCones()
+{
+
+}
+
+void find_cones()
+{
+
+}
+
+void powerupCones(unsigned char c)
+{
+
+}
+
+void resetSensors()
+{
+
+}
+
+void printMsAsSeconds(unsigned long)
+{
+
+}
+#endif
void getRadioInput(char *ibuffer, int size)
{
@@ -454,9 +472,7 @@
if(parameter == 'l')
value = strtoul(buffer, &endp, 2);
}
- //////DEBUG.print(parameter);
- //////DEBUG.println(value);
- //////DEBUG.println("not _");
+
interpret(parameter, value);
DEBUG("After interp: '%c'\r\n", parameter);
parameter = '_';
@@ -479,59 +495,54 @@
i=0;
}
}
-
- DEBUG("End of radio input\r\n");
}
void interpret(char parameter, int value)
{
- int remainder = 0;
- uint16_t split = 0;
- uint16_t t = 0;
- uint8_t c = 0;
- uint8_t l = 0;
- int last = 0;
- int middle = 0;
- uint8_t length = 0;
- uint8_t offset = 0;
- int i = 0;
- uint8_t v = 0;
- uint16_t val = 0;
- char phone_buffer[150] = {0};
+ int remainder;
+ uint16_t split;
+ uint16_t t;
+ uint8_t c;
+ uint8_t l;
+ int last;
+ int middle;
+ uint8_t length;
+ uint8_t offset;
+ int i;
+ uint8_t v;
+ uint16_t val;
switch(parameter)
{
- case 'S':
- ta.spin();
- break;
case 'f':
if(lonely)
{
- DEBUG("Sorry, no other cones detected, please try detecting cones first.");
+ writeToPhone("Sorry, no other cones detected, please try detecting cones first.\r\n");
break;
}
- DEBUG("Entered freeform");
+
+ writeToPhone("Entered freeform\r\n");
mode = FREEFORM;
state_p = START_P;
clearCones();
- find_cones();
+ //find_cones();
break;
case 'p':
if(value == 0)
{
- DEBUG("\n");
- DEBUG("Running pattern ");
- //DEBUG(pattern);
- DEBUG("%d\n",active_sequence + 1);
+ writeToPhone("\r\n");
+ writeToPhone("Running pattern %d\r\n", active_sequence + 1);
+
mode = PATTERN;
state_p = START_P;
active_cone = 0;
+
clearCones();
}
else
{
- DEBUG("Selected pattern ");
- DEBUG("%d\n",value);
+ writeToPhone("Selected pattern %d\r\n", value);
+
if(value <= SEQUENCES && value > 0)
{
active_sequence = value - 1;
@@ -541,80 +552,49 @@
}
else
{
- DEBUG("This pattern is not available. Please select a value between 1 and ");
- DEBUG("%d\n",SEQUENCES);
+ writeToPhone("This pattern is not available. Please select a value between 1 and %d", SEQUENCES);
}
}
break;
case 's':
station = value;
- DEBUG("Selected station ");
- DEBUG("%d\n",value);
+ writeToPhone("Selected station %d", value);
break;
case 'd':
- if(value == 0)
- {
+ if(value == 0){
logging = false;
m->value = 0;
dist_timeout = micros() + 2000000;
}
- if(value == 1)
- {
+ if(value == 1){
logging = true;
m->value = 1;
}
-
m->command = 'd';
m->cone = TRILAT_CONE;
ta.send(m);
- DEBUG("Sent d");
- //DEBUG(value);
+ //Serial.print("Sent d");
+ //Serial.println(value);
break;
case 'c':
c = value;
- DEBUG("Station ");
- DEBUG("%d",station);
- DEBUG(" will be cone ");
- DEBUG("%d\n",value);
-
- if(station <= STATIONS && station > 0)
- cones[station-1] = c;
+ writeToPhone("Station %d will be cone %d\r\n", station, value);
+ if(station <= STATIONS && station > 0)cones[station-1] = c;
break;
case 't':
t = (uint16_t)value;
- //snprintf(buffer, sizeof(buffer), "station");
- snprintf(phone_buffer, sizeof(phone_buffer), "Station %d split time is: %d.\n", station, t/1000);
- DEBUG(phone_buffer);
- //writeToPhone(phone_buffer);
- //writeToPhone("%d",station);
- //writeToPhone(" split time is: ");
- //writeToPhone("%d",t/1000);
- //writeToPhone(".");
+ writeToPhone("Station %d split time is: %d.", station, t/1000);
remainder = t%1000;
-
- //if(remainder < 100)
- //writeToPhone("0");
- //if(remainder < 10)
- // writeToPhone("0");
- //snprintf(buffer, sizeof(buffer), "%d\n seconds\n\n", remainder);
- //writeToPhone(buffer);
- //writeToPhone("%d\n",remainder);
- //writeToPhone(" seconds.\n");
- //writeToPhone("\n");
-
- if(station <= STATIONS && station > 0)
- times[station-1] = t;
+ if(remainder < 100)writeToPhone("0");
+ if(remainder < 10)writeToPhone("0");
+ writeToPhone("%d seconds.\r\n",remainder);
+ if(station <= STATIONS && station > 0)times[station-1] = t;
break;
case 'l':
l = 0;
l = (uint8_t)value;
masks[station-1] = l;
- DEBUG("Station ");
- DEBUG("%d",station);
- //DEBUG(" config bits: ");
- //DEBUG("%s",byte_to_binary(l));
- //DEBUG("\n");
- //}
+ writeToPhone("Station %d config bits: %d\r\n", station, l);
break;
case 'q':
state_p = IDLE_P;
@@ -623,140 +603,90 @@
clearCones();
break;
case 'r':
- //////DEBUG.println(F(""));
- DEBUG("Current pattern is ");
- DEBUG("%d\n",active_sequence + 1);
- DEBUG(":\n");
-
- for(int i=0; i<STATIONS; i++)
- {
- DEBUG("Station ");
- DEBUG("%d",i+1);
- DEBUG(": cone ");
- DEBUG("%d\n",cones[i]);
- DEBUG(", ");
-
+ //Serial.println(F(""));
+ writeToPhone("Current pattern is %d:", active_sequence+1);
+ for(int i=0; i<STATIONS; i++){
+ writeToPhone("Station %d: cone %d, ", i+1, cones[i]);
split = times[i];
- printMsAsSeconds(split);
- //DEBUG.print(F("s timeout, lights: "));
- DEBUG("s timeout, config bits: ");
+ //printMsAsSeconds(split);
+ //Serial.print(F("s timeout, lights: "));
+ writeToPhone("s timeout, config bits: ");
l = masks[i];
/*
- if(l<0x80)
- ////DEBUG("0");
- if(l<0x40)
- ////DEBUG("0");
- if(l<0x20)
- ////DEBUG("0");
- if(l<0x10)
- ////DEBUG("0");
- if(l<0x08)
- ////DEBUG("0");
- if(l<0x04)
- ////DEBUG("0");
- if(l<0x02)
- ////DEBUG("0");
- //////DEBUG("%s\n",byte_to_binary(l));
- */
+ if(l<0b10000000)
+ writeToPhone("0");
+ if(l<0b1000000)
+ writeToPhone("0");
+ if(l<0b100000)
+ writeToPhone("0");
+ if(l<0b10000)
+ writeToPhone("0");
+ if(l<0b1000)
+ writeToPhone("0");
+ if(l<0b100)
+ writeToPhone("0");
+ if(l<0b10)
+ writeToPhone("0");
+ */
+ writeToPhone("%d\r\n", l);
+ //Serial.println(l, BIN);
}
break;
case 'u':
// let any pending messages clear
- while(ta.get_buffer_size())
- {
+ while(ta.get_buffer_size()){
ta.spin();
}
-
- if(value == 1)
- {
- DEBUG("Course leader!");
+ if(value == 1){
+ writeToPhone("Course leader!\r\n");
powerupCones(value);
ta.powerup(value);
}
-
- if(value == 2)
- {
- DEBUG("Split leader!");
+ if(value == 2){
+ writeToPhone("Split leader!\r\n");
powerupCones(value);
- ta.powerup(value);
+ //ta.powerup(value);
}
-
- if(value > 10 && value < 5000)
- {
+ if(value > 10 && value < 5000){
ta.beep(value);
}
break;
case 'w':
- if(value > 0 && value <= SEQUENCES)
- {
+ if(value > 0 && value <= SEQUENCES){
length = STATIONS;
offset = (value - 1) * STATIONS;
- DEBUG("Saved sequence ");
- DEBUG("%d\n",value);
+ writeToPhone("Saved sequence %d\r\n", value);
}
- else
- {
+ else{
length = STATIONS * SEQUENCES;
offset = 0;
- DEBUG("Saved all sequences.\n");
+ writeToPhone("Saved all sequences.\r\n");
}
-
- for(i=offset;i<length+offset;i++)
- {
- //eeprom_update_byte(addressConeTable + i, cone_table[i]); !SR
- //eeprom_update_byte(addressMaskTable + i, mask_table[i]); !SR
- //eeprom_update_word(addressTimeTable + i, time_table[i]); !SR
+ 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();
- //a3 = 0;
- wait_ms(100);
- //a3 = 1;
+ //digitalWrite(A3, LOW);
+ //delay(100);
+ //digitalWrite(A3, HIGH);
break;
case 'z':
find_cones();
- DEBUG("end of 'z'\r\n");
- /*!SR
- m->value = value;
+ /*m->value = value;
m->command = 'z';
m->cone = 2;
- DEBUG("sending...");
+ Serial.println("sending...");
ta.send(m);
- DEBUG("sent");
- */
- break;
-
- default:
- // seems like this is overflowing some memory somewhere, so commented out for now
- /*////DEBUG.println(F(""));
- ////DEBUG.println(F("Enter:"));
- ////DEBUG.println(F("'f;' to run freeform patterns"));
- ////DEBUG.println(F("'p;' to run the previously selected programmed pattern"));
- ////DEBUG.println(F("'r;' to review the custom pattern"));
- ////DEBUG.println(F("'p#;' to select a pattern"));
- ////DEBUG.println(F("'s#;' to select a station"));
- ////DEBUG.println(F("'c#;' to assign a cone to the selected station"));
- ////DEBUG.println(F("'t#;' to assign a time to a station (in milliseconds)"));
- ////DEBUG.println(F("'l###;' to set the active lights (111 = on,on,on 000=off,off,off"));
- ////DEBUG.println(F("All commands must be terminated by ';'"));
- ////DEBUG.println(F(""));
- ////DEBUG.println(F("Examples:"));
- ////DEBUG.println(F("'s1;'"));
- ////DEBUG.println(F("Select the first station"));
- ////DEBUG.println(F(""));
- ////DEBUG.println(F("'c4;t5000;'"));
- ////DEBUG.println(F("Assign cone 4 and a time split of 5 seconds "));
- ////DEBUG.println(F("to the current station 1"));
- ////DEBUG.println(F(""));
- ////DEBUG.println(F("'s2;c4;t1500;'"));
- ////DEBUG.println(F("Assign cone 2 as the next station 2, "));
- ////DEBUG.println(F("and require a time split of 1.5 seconds."));*/
+ Serial.println("sent");*/
break;
}
}
-
+#if 1
patternState_t stateFromCone(uint8_t cone)
{
if(cone == 0 || index == STATIONS)
@@ -1245,3 +1175,6 @@
last_buttons = buttons;
return event;
}
+#endif
+
+#endif
\ No newline at end of file
