beacon from 2009
[aversive.git] / projects / microb2010 / mainboard / commands_mainboard.c
index fcc47e6..1875965 100644 (file)
@@ -70,7 +70,6 @@
 #include "strat_corn.h"
 #include "i2c_protocol.h"
 #include "actuator.h"
-#include "beacon.h"
 
 struct cmd_event_result {
        fixed_string_t arg0;
@@ -285,38 +284,38 @@ parse_pgm_inst_t cmd_opponent_set = {
 };
 
 /**********************************************************/
-/* Beacon tests */
+/* Beacon_Start */
 
-/* this structure is filled when cmd_beacon is parsed successfully */
-struct cmd_beacon_result {
+/* this structure is filled when cmd_beacon_start is parsed successfully */
+struct cmd_beacon_start_result {
        fixed_string_t arg0;
        fixed_string_t arg1;
 };
 
-/* function called when cmd_beacon is parsed successfully */
-static void cmd_beacon_parsed(void *parsed_result, void *data)
+/* function called when cmd_beacon_start is parsed successfully */
+static void cmd_beacon_start_parsed(void *parsed_result, void *data)
 {
-       double x, y, a;
+       struct cmd_beacon_start_result *res = parsed_result;
 
-       if (beacon_get_pos_double(&x, &y, &a) < 0)
-               printf_P(PSTR("No position from beacon\r\n"));
+       if (!strcmp_P(res->arg1, PSTR("start")))
+               i2c_ballboard_set_beacon(1);
        else
-               printf_P(PSTR("x=%2.2f y=%2.2f a=%2.2f\r\n"), x, y, DEG(a));
+               i2c_ballboard_set_beacon(0);
 }
 
-prog_char str_beacon_arg0[] = "beacon";
-parse_pgm_token_string_t cmd_beacon_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_beacon_result, arg0, str_beacon_arg0);
-prog_char str_beacon_arg1[] = "show";
-parse_pgm_token_string_t cmd_beacon_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_beacon_result, arg1, str_beacon_arg1);
+prog_char str_beacon_start_arg0[] = "beacon";
+parse_pgm_token_string_t cmd_beacon_start_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_beacon_start_result, arg0, str_beacon_start_arg0);
+prog_char str_beacon_start_arg1[] = "start#stop";
+parse_pgm_token_string_t cmd_beacon_start_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_beacon_start_result, arg1, str_beacon_start_arg1);
 
-prog_char help_beacon[] = "Show (x,y) beacon";
-parse_pgm_inst_t cmd_beacon = {
-       .f = cmd_beacon_parsed,  /* function to call */
+prog_char help_beacon_start[] = "Beacon enabled/disable";
+parse_pgm_inst_t cmd_beacon_start = {
+       .f = cmd_beacon_start_parsed,  /* function to call */
        .data = NULL,      /* 2nd arg of func */
-       .help_str = help_beacon,
+       .help_str = help_beacon_start,
        .tokens = {        /* token list, NULL terminated */
-               (prog_void *)&cmd_beacon_arg0,
-               (prog_void *)&cmd_beacon_arg1,
+               (prog_void *)&cmd_beacon_start_arg0, 
+               (prog_void *)&cmd_beacon_start_arg1, 
                NULL,
        },
 };
@@ -351,15 +350,18 @@ static void cmd_start_parsed(void *parsed_result, void *data)
                mainboard.our_color = I2C_COLOR_YELLOW;
                i2c_set_color(I2C_COBBOARD_ADDR, I2C_COLOR_YELLOW);
                i2c_set_color(I2C_BALLBOARD_ADDR, I2C_COLOR_YELLOW);
-               beacon_set_color(I2C_COLOR_YELLOW);
        }
        else if (!strcmp_P(res->color, PSTR("blue"))) {
                mainboard.our_color = I2C_COLOR_BLUE;
                i2c_set_color(I2C_COBBOARD_ADDR, I2C_COLOR_BLUE);
                i2c_set_color(I2C_BALLBOARD_ADDR, I2C_COLOR_BLUE);
-               beacon_set_color(I2C_COLOR_BLUE);
        }
 
+       printf_P(PSTR("Press a key when beacon ready\r\n"));
+       i2c_ballboard_set_beacon(0);
+       while(!cmdline_keypressed());
+       i2c_ballboard_set_beacon(1);
+
        strat_start();
 
        gen.logs[NB_LOGS] = 0;
@@ -613,13 +615,11 @@ static void cmd_color_parsed(void *parsed_result, void *data)
                mainboard.our_color = I2C_COLOR_YELLOW;
                i2c_set_color(I2C_COBBOARD_ADDR, I2C_COLOR_YELLOW);
                i2c_set_color(I2C_BALLBOARD_ADDR, I2C_COLOR_YELLOW);
-               beacon_set_color(I2C_COLOR_YELLOW);
        }
        else if (!strcmp_P(res->color, PSTR("blue"))) {
                mainboard.our_color = I2C_COLOR_BLUE;
                i2c_set_color(I2C_COBBOARD_ADDR, I2C_COLOR_BLUE);
                i2c_set_color(I2C_BALLBOARD_ADDR, I2C_COLOR_BLUE);
-               beacon_set_color(I2C_COLOR_BLUE);
        }
        printf_P(PSTR("Done\r\n"));
 #endif