2 * Copyright Droids Corporation (2009)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: commands_ballboard.c,v 1.2 2009-04-24 19:30:42 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
26 #include <aversive/pgmspace.h>
27 #include <aversive/wait.h>
28 #include <aversive/error.h>
33 #include <clock_time.h>
38 #include <control_system_manager.h>
39 #include <blocking_detection_manager.h>
43 #include <parse_string.h>
44 #include <parse_num.h>
48 #include "../common/i2c_commands.h"
49 #include "i2c_protocol.h"
52 struct cmd_event_result {
59 /* function called when cmd_event is parsed successfully */
60 static void cmd_event_parsed(void *parsed_result, void *data)
64 struct cmd_event_result * res = parsed_result;
66 if (!strcmp_P(res->arg1, PSTR("all"))) {
67 bit = DO_ENCODERS | DO_CS | DO_BD | DO_POWER;
68 if (!strcmp_P(res->arg2, PSTR("on")))
69 ballboard.flags |= bit;
70 else if (!strcmp_P(res->arg2, PSTR("off")))
71 ballboard.flags &= bit;
73 printf_P(PSTR("encoders is %s\r\n"),
74 (DO_ENCODERS & ballboard.flags) ? "on":"off");
75 printf_P(PSTR("cs is %s\r\n"),
76 (DO_CS & ballboard.flags) ? "on":"off");
77 printf_P(PSTR("bd is %s\r\n"),
78 (DO_BD & ballboard.flags) ? "on":"off");
79 printf_P(PSTR("power is %s\r\n"),
80 (DO_POWER & ballboard.flags) ? "on":"off");
85 if (!strcmp_P(res->arg1, PSTR("encoders")))
87 else if (!strcmp_P(res->arg1, PSTR("cs"))) {
90 else if (!strcmp_P(res->arg1, PSTR("bd")))
92 else if (!strcmp_P(res->arg1, PSTR("power")))
96 if (!strcmp_P(res->arg2, PSTR("on")))
97 ballboard.flags |= bit;
98 else if (!strcmp_P(res->arg2, PSTR("off"))) {
99 if (!strcmp_P(res->arg1, PSTR("cs"))) {
100 pwm_ng_set(ROLLER_PWM, 0);
101 pwm_ng_set(FORKTRANS_PWM, 0);
102 pwm_ng_set(FORKROT_PWM, 0);
104 ballboard.flags &= (~bit);
106 printf_P(PSTR("%s is %s\r\n"), res->arg1,
107 (bit & ballboard.flags) ? "on":"off");
110 prog_char str_event_arg0[] = "event";
111 parse_pgm_token_string_t cmd_event_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg0, str_event_arg0);
112 prog_char str_event_arg1[] = "all#encoders#cs#bd#power";
113 parse_pgm_token_string_t cmd_event_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg1, str_event_arg1);
114 prog_char str_event_arg2[] = "on#off#show";
115 parse_pgm_token_string_t cmd_event_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg2, str_event_arg2);
117 prog_char help_event[] = "Enable/disable events";
118 parse_pgm_inst_t cmd_event = {
119 .f = cmd_event_parsed, /* function to call */
120 .data = NULL, /* 2nd arg of func */
121 .help_str = help_event,
122 .tokens = { /* token list, NULL terminated */
123 (prog_void *)&cmd_event_arg0,
124 (prog_void *)&cmd_event_arg1,
125 (prog_void *)&cmd_event_arg2,
130 /**********************************************************/
133 /* this structure is filled when cmd_color is parsed successfully */
134 struct cmd_color_result {
136 fixed_string_t color;
139 /* function called when cmd_color is parsed successfully */
140 static void cmd_color_parsed(void *parsed_result, void *data)
142 struct cmd_color_result *res = (struct cmd_color_result *) parsed_result;
143 if (!strcmp_P(res->color, PSTR("red"))) {
144 ballboard.our_color = I2C_COLOR_RED;
146 else if (!strcmp_P(res->color, PSTR("green"))) {
147 ballboard.our_color = I2C_COLOR_GREEN;
149 printf_P(PSTR("Done\r\n"));
152 prog_char str_color_arg0[] = "color";
153 parse_pgm_token_string_t cmd_color_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_color_result, arg0, str_color_arg0);
154 prog_char str_color_color[] = "green#red";
155 parse_pgm_token_string_t cmd_color_color = TOKEN_STRING_INITIALIZER(struct cmd_color_result, color, str_color_color);
157 prog_char help_color[] = "Set our color";
158 parse_pgm_inst_t cmd_color = {
159 .f = cmd_color_parsed, /* function to call */
160 .data = NULL, /* 2nd arg of func */
161 .help_str = help_color,
162 .tokens = { /* token list, NULL terminated */
163 (prog_void *)&cmd_color_arg0,
164 (prog_void *)&cmd_color_color,
170 /**********************************************************/
173 /* this structure is filled when cmd_test is parsed successfully */
174 struct cmd_test_result {
178 /* function called when cmd_test is parsed successfully */
179 static void cmd_test_parsed(void *parsed_result, void *data)
181 //struct cmd_test_result *res = parsed_result;
185 prog_char str_test_arg0[] = "test";
186 parse_pgm_token_string_t cmd_test_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_test_result, arg0, str_test_arg0);
188 prog_char help_test[] = "Test function";
189 parse_pgm_inst_t cmd_test = {
190 .f = cmd_test_parsed, /* function to call */
191 .data = NULL, /* 2nd arg of func */
192 .help_str = help_test,
193 .tokens = { /* token list, NULL terminated */
194 (prog_void *)&cmd_test_arg0,