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_cobboard.c,v 1.6 2009-11-08 17:25:00 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>
46 #include "../common/i2c_commands.h"
51 #include "i2c_protocol.h"
56 struct cmd_event_result {
63 /* function called when cmd_event is parsed successfully */
64 static void cmd_event_parsed(void *parsed_result, __attribute__((unused)) void *data)
68 struct cmd_event_result * res = parsed_result;
70 if (!strcmp_P(res->arg1, PSTR("all"))) {
72 if (!strcmp_P(res->arg2, PSTR("on")))
73 cobboard.flags |= bit;
74 else if (!strcmp_P(res->arg2, PSTR("off")))
75 cobboard.flags &= bit;
77 printf_P(PSTR("encoders is %s\r\n"),
78 (DO_ENCODERS & cobboard.flags) ? "on":"off");
79 printf_P(PSTR("cs is %s\r\n"),
80 (DO_CS & cobboard.flags) ? "on":"off");
81 printf_P(PSTR("bd is %s\r\n"),
82 (DO_BD & cobboard.flags) ? "on":"off");
83 printf_P(PSTR("power is %s\r\n"),
84 (DO_POWER & cobboard.flags) ? "on":"off");
85 printf_P(PSTR("errblock is %s\r\n"),
86 (DO_ERRBLOCKING & cobboard.flags) ? "on":"off");
91 if (!strcmp_P(res->arg1, PSTR("encoders")))
93 else if (!strcmp_P(res->arg1, PSTR("cs"))) {
96 else if (!strcmp_P(res->arg1, PSTR("bd")))
98 else if (!strcmp_P(res->arg1, PSTR("power")))
100 else if (!strcmp_P(res->arg1, PSTR("errblock")))
101 bit = DO_ERRBLOCKING;
104 if (!strcmp_P(res->arg2, PSTR("on")))
105 cobboard.flags |= bit;
106 else if (!strcmp_P(res->arg2, PSTR("off"))) {
107 if (!strcmp_P(res->arg1, PSTR("cs"))) {
108 pwm_ng_set(LEFT_SPICKLE_PWM, 0);
109 pwm_ng_set(RIGHT_SPICKLE_PWM, 0);
110 pwm_ng_set(SHOVEL_PWM, 0);
112 cobboard.flags &= (~bit);
114 printf_P(PSTR("%s is %s\r\n"), res->arg1,
115 (bit & cobboard.flags) ? "on":"off");
118 prog_char str_event_arg0[] = "event";
119 parse_pgm_token_string_t cmd_event_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg0, str_event_arg0);
120 prog_char str_event_arg1[] = "all#encoders#cs#bd#power#errblock";
121 parse_pgm_token_string_t cmd_event_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg1, str_event_arg1);
122 prog_char str_event_arg2[] = "on#off#show";
123 parse_pgm_token_string_t cmd_event_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg2, str_event_arg2);
125 prog_char help_event[] = "Enable/disable events";
126 parse_pgm_inst_t cmd_event = {
127 .f = cmd_event_parsed, /* function to call */
128 .data = NULL, /* 2nd arg of func */
129 .help_str = help_event,
130 .tokens = { /* token list, NULL terminated */
131 (prog_void *)&cmd_event_arg0,
132 (prog_void *)&cmd_event_arg1,
133 (prog_void *)&cmd_event_arg2,
138 /**********************************************************/
141 /* this structure is filled when cmd_color is parsed successfully */
142 struct cmd_color_result {
144 fixed_string_t color;
147 /* function called when cmd_color is parsed successfully */
148 static void cmd_color_parsed(void *parsed_result, __attribute__((unused)) void *data)
150 struct cmd_color_result *res = (struct cmd_color_result *) parsed_result;
151 if (!strcmp_P(res->color, PSTR("yellow"))) {
152 cobboard.our_color = I2C_COLOR_YELLOW;
154 else if (!strcmp_P(res->color, PSTR("blue"))) {
155 cobboard.our_color = I2C_COLOR_BLUE;
157 printf_P(PSTR("Done\r\n"));
160 prog_char str_color_arg0[] = "color";
161 parse_pgm_token_string_t cmd_color_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_color_result, arg0, str_color_arg0);
162 prog_char str_color_color[] = "blue#yellow";
163 parse_pgm_token_string_t cmd_color_color = TOKEN_STRING_INITIALIZER(struct cmd_color_result, color, str_color_color);
165 prog_char help_color[] = "Set our color";
166 parse_pgm_inst_t cmd_color = {
167 .f = cmd_color_parsed, /* function to call */
168 .data = NULL, /* 2nd arg of func */
169 .help_str = help_color,
170 .tokens = { /* token list, NULL terminated */
171 (prog_void *)&cmd_color_arg0,
172 (prog_void *)&cmd_color_color,
177 /**********************************************************/
180 /* this structure is filled when cmd_state1 is parsed successfully */
181 struct cmd_state1_result {
186 /* function called when cmd_state1 is parsed successfully */
187 static void cmd_state1_parsed(void *parsed_result,
188 __attribute__((unused)) void *data)
190 struct cmd_state1_result *res = parsed_result;
192 if (!strcmp_P(res->arg1, PSTR("init")))
194 else if (!strcmp_P(res->arg1, PSTR("eject")))
195 state_set_mode(I2C_COBBOARD_MODE_EJECT);
196 else if (!strcmp_P(res->arg1, PSTR("kickstand")))
197 state_set_mode(I2C_COBBOARD_MODE_KICKSTAND);
198 else if (!strcmp_P(res->arg1, PSTR("ignore_i2c")))
199 state_set_i2c_ignore(1);
200 else if (!strcmp_P(res->arg1, PSTR("care_i2c")))
201 state_set_i2c_ignore(0);
206 prog_char str_state1_arg0[] = "cobboard";
207 parse_pgm_token_string_t cmd_state1_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state1_result, arg0, str_state1_arg0);
208 prog_char str_state1_arg1[] = "init#eject#ignore_i2c#care_i2c#kickstand";
209 parse_pgm_token_string_t cmd_state1_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state1_result, arg1, str_state1_arg1);
211 prog_char help_state1[] = "set cobboard mode";
212 parse_pgm_inst_t cmd_state1 = {
213 .f = cmd_state1_parsed, /* function to call */
214 .data = NULL, /* 2nd arg of func */
215 .help_str = help_state1,
216 .tokens = { /* token list, NULL terminated */
217 (prog_void *)&cmd_state1_arg0,
218 (prog_void *)&cmd_state1_arg1,
223 /**********************************************************/
226 /* this structure is filled when cmd_state2 is parsed successfully */
227 struct cmd_state2_result {
233 /* function called when cmd_state2 is parsed successfully */
234 static void cmd_state2_parsed(void *parsed_result,
235 __attribute__((unused)) void *data)
237 struct cmd_state2_result *res = parsed_result;
240 if (!strcmp_P(res->arg2, PSTR("left")))
241 side = I2C_LEFT_SIDE;
243 side = I2C_RIGHT_SIDE;
245 if (!strcmp_P(res->arg1, PSTR("pack"))) {
246 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
247 state_set_spickle(side, 0);
249 else if (!strcmp_P(res->arg1, PSTR("weak_pack"))) {
250 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
251 state_set_spickle(side, I2C_COBBOARD_SPK_WEAK);
253 else if (!strcmp_P(res->arg1, PSTR("deploy"))) {
254 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
255 state_set_spickle(side, I2C_COBBOARD_SPK_DEPLOY);
257 else if (!strcmp_P(res->arg1, PSTR("harvest"))) {
258 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
259 state_set_spickle(side, I2C_COBBOARD_SPK_DEPLOY |
260 I2C_COBBOARD_SPK_AUTOHARVEST);
262 else if (!strcmp_P(res->arg1, PSTR("deploy_nomove"))) {
263 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
264 state_set_spickle(side, I2C_COBBOARD_SPK_DEPLOY |
265 I2C_COBBOARD_SPK_NO_MOVE);
267 else if (!strcmp_P(res->arg1, PSTR("harvest_nomove"))) {
268 state_set_mode(I2C_COBBOARD_MODE_HARVEST);
269 state_set_spickle(side, I2C_COBBOARD_SPK_DEPLOY |
270 I2C_COBBOARD_SPK_AUTOHARVEST |
271 I2C_COBBOARD_SPK_NO_MOVE);
275 prog_char str_state2_arg0[] = "cobboard";
276 parse_pgm_token_string_t cmd_state2_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg0, str_state2_arg0);
277 prog_char str_state2_arg1[] = "harvest#deploy#pack#weak_pack#harvest_nomove#deploy_nomove";
278 parse_pgm_token_string_t cmd_state2_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg1, str_state2_arg1);
279 prog_char str_state2_arg2[] = "left#right";
280 parse_pgm_token_string_t cmd_state2_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg2, str_state2_arg2);
282 prog_char help_state2[] = "set cobboard mode";
283 parse_pgm_inst_t cmd_state2 = {
284 .f = cmd_state2_parsed, /* function to call */
285 .data = NULL, /* 2nd arg of func */
286 .help_str = help_state2,
287 .tokens = { /* token list, NULL terminated */
288 (prog_void *)&cmd_state2_arg0,
289 (prog_void *)&cmd_state2_arg1,
290 (prog_void *)&cmd_state2_arg2,
295 /**********************************************************/
298 /* this structure is filled when cmd_state3 is parsed successfully */
299 struct cmd_state3_result {
305 /* function called when cmd_state3 is parsed successfully */
306 static void cmd_state3_parsed(void *parsed_result,
307 __attribute__((unused)) void *data)
309 struct cmd_state3_result *res = parsed_result;
311 if (!strcmp_P(res->arg1, PSTR("xxx"))) {
312 /* xxx = res->arg2 */
314 else if (!strcmp_P(res->arg1, PSTR("yyy"))) {
319 prog_char str_state3_arg0[] = "cobboard";
320 parse_pgm_token_string_t cmd_state3_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state3_result, arg0, str_state3_arg0);
321 prog_char str_state3_arg1[] = "xxx";
322 parse_pgm_token_string_t cmd_state3_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state3_result, arg1, str_state3_arg1);
323 parse_pgm_token_num_t cmd_state3_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_state3_result, arg2, UINT8);
325 prog_char help_state3[] = "set cobboard mode";
326 parse_pgm_inst_t cmd_state3 = {
327 .f = cmd_state3_parsed, /* function to call */
328 .data = NULL, /* 2nd arg of func */
329 .help_str = help_state3,
330 .tokens = { /* token list, NULL terminated */
331 (prog_void *)&cmd_state3_arg0,
332 (prog_void *)&cmd_state3_arg1,
333 (prog_void *)&cmd_state3_arg2,
338 /**********************************************************/
341 /* this structure is filled when cmd_state_machine is parsed successfully */
342 struct cmd_state_machine_result {
346 /* function called when cmd_state_machine is parsed successfully */
347 static void cmd_state_machine_parsed(__attribute__((unused)) void *parsed_result,
348 __attribute__((unused)) void *data)
353 prog_char str_state_machine_arg0[] = "state_machine";
354 parse_pgm_token_string_t cmd_state_machine_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state_machine_result, arg0, str_state_machine_arg0);
356 prog_char help_state_machine[] = "launch state machine";
357 parse_pgm_inst_t cmd_state_machine = {
358 .f = cmd_state_machine_parsed, /* function to call */
359 .data = NULL, /* 2nd arg of func */
360 .help_str = help_state_machine,
361 .tokens = { /* token list, NULL terminated */
362 (prog_void *)&cmd_state_machine_arg0,
367 /**********************************************************/
370 /* this structure is filled when cmd_state_debug is parsed successfully */
371 struct cmd_state_debug_result {
376 /* function called when cmd_state_debug is parsed successfully */
377 static void cmd_state_debug_parsed(void *parsed_result,
378 __attribute__((unused)) void *data)
380 struct cmd_state_debug_result *res = parsed_result;
381 state_debug = res->on;
384 prog_char str_state_debug_arg0[] = "state_debug";
385 parse_pgm_token_string_t cmd_state_debug_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state_debug_result, arg0, str_state_debug_arg0);
386 parse_pgm_token_num_t cmd_state_debug_on = TOKEN_NUM_INITIALIZER(struct cmd_state_debug_result, on, UINT8);
388 prog_char help_state_debug[] = "Set debug for state machine";
389 parse_pgm_inst_t cmd_state_debug = {
390 .f = cmd_state_debug_parsed, /* function to call */
391 .data = NULL, /* 2nd arg of func */
392 .help_str = help_state_debug,
393 .tokens = { /* token list, NULL terminated */
394 (prog_void *)&cmd_state_debug_arg0,
395 (prog_void *)&cmd_state_debug_on,
400 /**********************************************************/
403 /* this structure is filled when cmd_servo_door is parsed successfully */
404 struct cmd_servo_door_result {
409 /* function called when cmd_servo_door is parsed successfully */
410 static void cmd_servo_door_parsed(void *parsed_result,
411 __attribute__((unused)) void *data)
413 struct cmd_servo_door_result *res = parsed_result;
414 if (!strcmp_P(res->arg1, PSTR("open")))
416 else if (!strcmp_P(res->arg1, PSTR("closed")))
418 else if (!strcmp_P(res->arg1, PSTR("block")))
422 prog_char str_servo_door_arg0[] = "door";
423 parse_pgm_token_string_t cmd_servo_door_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_servo_door_result, arg0, str_servo_door_arg0);
424 prog_char str_servo_door_arg1[] = "open#closed#block";
425 parse_pgm_token_string_t cmd_servo_door_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_servo_door_result, arg1, str_servo_door_arg1);
427 prog_char help_servo_door[] = "Servo door function";
428 parse_pgm_inst_t cmd_servo_door = {
429 .f = cmd_servo_door_parsed, /* function to call */
430 .data = NULL, /* 2nd arg of func */
431 .help_str = help_servo_door,
432 .tokens = { /* token list, NULL terminated */
433 (prog_void *)&cmd_servo_door_arg0,
434 (prog_void *)&cmd_servo_door_arg1,
439 /**********************************************************/
442 /* this structure is filled when cmd_cobroller is parsed successfully */
443 struct cmd_cobroller_result {
449 /* function called when cmd_cobroller is parsed successfully */
450 static void cmd_cobroller_parsed(void *parsed_result,
451 __attribute__((unused)) void *data)
453 struct cmd_cobroller_result *res = parsed_result;
456 if (!strcmp_P(res->arg1, PSTR("left")))
457 side = I2C_LEFT_SIDE;
459 side = I2C_RIGHT_SIDE;
461 if (!strcmp_P(res->arg2, PSTR("on")))
463 else if (!strcmp_P(res->arg2, PSTR("off")))
467 prog_char str_cobroller_arg0[] = "cobroller";
468 parse_pgm_token_string_t cmd_cobroller_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_cobroller_result, arg0, str_cobroller_arg0);
469 prog_char str_cobroller_arg1[] = "left#right";
470 parse_pgm_token_string_t cmd_cobroller_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_cobroller_result, arg1, str_cobroller_arg1);
471 prog_char str_cobroller_arg2[] = "on#off";
472 parse_pgm_token_string_t cmd_cobroller_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_cobroller_result, arg2, str_cobroller_arg2);
474 prog_char help_cobroller[] = "Servo door function";
475 parse_pgm_inst_t cmd_cobroller = {
476 .f = cmd_cobroller_parsed, /* function to call */
477 .data = NULL, /* 2nd arg of func */
478 .help_str = help_cobroller,
479 .tokens = { /* token list, NULL terminated */
480 (prog_void *)&cmd_cobroller_arg0,
481 (prog_void *)&cmd_cobroller_arg1,
482 (prog_void *)&cmd_cobroller_arg2,
487 /**********************************************************/
490 /* this structure is filled when cmd_shovel is parsed successfully */
491 struct cmd_shovel_result {
496 /* function called when cmd_shovel is parsed successfully */
497 static void cmd_shovel_parsed(void *parsed_result,
498 __attribute__((unused)) void *data)
500 struct cmd_shovel_result *res = parsed_result;
501 if (!strcmp_P(res->arg1, PSTR("down")))
503 else if (!strcmp_P(res->arg1, PSTR("up")))
505 else if (!strcmp_P(res->arg1, PSTR("mid")))
509 prog_char str_shovel_arg0[] = "shovel";
510 parse_pgm_token_string_t cmd_shovel_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_shovel_result, arg0, str_shovel_arg0);
511 prog_char str_shovel_arg1[] = "down#up#mid";
512 parse_pgm_token_string_t cmd_shovel_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_shovel_result, arg1, str_shovel_arg1);
514 prog_char help_shovel[] = "Servo shovel function";
515 parse_pgm_inst_t cmd_shovel = {
516 .f = cmd_shovel_parsed, /* function to call */
517 .data = NULL, /* 2nd arg of func */
518 .help_str = help_shovel,
519 .tokens = { /* token list, NULL terminated */
520 (prog_void *)&cmd_shovel_arg0,
521 (prog_void *)&cmd_shovel_arg1,
526 /**********************************************************/
529 /* this structure is filled when cmd_servo_carry is parsed successfully */
530 struct cmd_servo_carry_result {
535 /* function called when cmd_servo_carry is parsed successfully */
536 static void cmd_servo_carry_parsed(void *parsed_result,
537 __attribute__((unused)) void *data)
539 struct cmd_servo_carry_result *res = parsed_result;
540 if (!strcmp_P(res->arg1, PSTR("open")))
542 else if (!strcmp_P(res->arg1, PSTR("closed")))
546 prog_char str_servo_carry_arg0[] = "carry";
547 parse_pgm_token_string_t cmd_servo_carry_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_servo_carry_result, arg0, str_servo_carry_arg0);
548 prog_char str_servo_carry_arg1[] = "open#closed";
549 parse_pgm_token_string_t cmd_servo_carry_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_servo_carry_result, arg1, str_servo_carry_arg1);
551 prog_char help_servo_carry[] = "Servo carry function";
552 parse_pgm_inst_t cmd_servo_carry = {
553 .f = cmd_servo_carry_parsed, /* function to call */
554 .data = NULL, /* 2nd arg of func */
555 .help_str = help_servo_carry,
556 .tokens = { /* token list, NULL terminated */
557 (prog_void *)&cmd_servo_carry_arg0,
558 (prog_void *)&cmd_servo_carry_arg1,
563 /**********************************************************/
566 /* this structure is filled when cmd_spickle is parsed successfully */
567 struct cmd_spickle_result {
573 /* function called when cmd_spickle is parsed successfully */
574 static void cmd_spickle_parsed(void * parsed_result,
575 __attribute__((unused)) void *data)
577 struct cmd_spickle_result * res = parsed_result;
580 if (!strcmp_P(res->arg1, PSTR("left")))
581 side = I2C_LEFT_SIDE;
583 side = I2C_RIGHT_SIDE;
585 if (!strcmp_P(res->arg2, PSTR("deploy"))) {
586 spickle_deploy(side);
588 else if (!strcmp_P(res->arg2, PSTR("pack"))) {
591 else if (!strcmp_P(res->arg2, PSTR("mid"))) {
594 printf_P(PSTR("done\r\n"));
597 prog_char str_spickle_arg0[] = "spickle";
598 parse_pgm_token_string_t cmd_spickle_arg0 =
599 TOKEN_STRING_INITIALIZER(struct cmd_spickle_result, arg0, str_spickle_arg0);
600 prog_char str_spickle_arg1[] = "left#right";
601 parse_pgm_token_string_t cmd_spickle_arg1 =
602 TOKEN_STRING_INITIALIZER(struct cmd_spickle_result, arg1, str_spickle_arg1);
603 prog_char str_spickle_arg2[] = "deploy#pack#mid";
604 parse_pgm_token_string_t cmd_spickle_arg2 =
605 TOKEN_STRING_INITIALIZER(struct cmd_spickle_result, arg2, str_spickle_arg2);
607 prog_char help_spickle[] = "move spickle";
608 parse_pgm_inst_t cmd_spickle = {
609 .f = cmd_spickle_parsed, /* function to call */
610 .data = NULL, /* 2nd arg of func */
611 .help_str = help_spickle,
612 .tokens = { /* token list, NULL terminated */
613 (prog_void *)&cmd_spickle_arg0,
614 (prog_void *)&cmd_spickle_arg1,
615 (prog_void *)&cmd_spickle_arg2,
620 /**********************************************************/
621 /* Set Spickle Params */
623 /* this structure is filled when cmd_spickle_params is parsed successfully */
624 struct cmd_spickle_params_result {
633 /* function called when cmd_spickle_params is parsed successfully */
634 static void cmd_spickle_params_parsed(void *parsed_result,
635 __attribute__((unused)) void *data)
637 struct cmd_spickle_params_result * res = parsed_result;
640 if (!strcmp_P(res->arg1, PSTR("show"))) {
641 spickle_dump_params();
645 if (!strcmp_P(res->arg1, PSTR("left")))
646 side = I2C_LEFT_SIDE;
648 side = I2C_RIGHT_SIDE;
650 if (!strcmp_P(res->arg2, PSTR("pos")))
651 spickle_set_pos(side, res->arg3, res->arg4, res->arg5);
654 prog_char str_spickle_params_arg0[] = "spickle_params";
655 parse_pgm_token_string_t cmd_spickle_params_arg0 =
656 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params_result, arg0, str_spickle_params_arg0);
657 prog_char str_spickle_params_arg1[] = "left#right";
658 parse_pgm_token_string_t cmd_spickle_params_arg1 =
659 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params_result, arg1, str_spickle_params_arg1);
660 prog_char str_spickle_params_arg2[] = "pos";
661 parse_pgm_token_string_t cmd_spickle_params_arg2 =
662 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params_result, arg2, str_spickle_params_arg2);
663 parse_pgm_token_num_t cmd_spickle_params_arg3 =
664 TOKEN_NUM_INITIALIZER(struct cmd_spickle_params_result, arg3, INT32);
665 parse_pgm_token_num_t cmd_spickle_params_arg4 =
666 TOKEN_NUM_INITIALIZER(struct cmd_spickle_params_result, arg4, INT32);
667 parse_pgm_token_num_t cmd_spickle_params_arg5 =
668 TOKEN_NUM_INITIALIZER(struct cmd_spickle_params_result, arg5, INT32);
670 prog_char help_spickle_params[] = "Set spickle pos values: left|right pos INTPACK INTMID INTDEPL";
671 parse_pgm_inst_t cmd_spickle_params = {
672 .f = cmd_spickle_params_parsed, /* function to call */
673 .data = NULL, /* 2nd arg of func */
674 .help_str = help_spickle_params,
675 .tokens = { /* token list, NULL terminated */
676 (prog_void *)&cmd_spickle_params_arg0,
677 (prog_void *)&cmd_spickle_params_arg1,
678 (prog_void *)&cmd_spickle_params_arg2,
679 (prog_void *)&cmd_spickle_params_arg3,
680 (prog_void *)&cmd_spickle_params_arg4,
681 (prog_void *)&cmd_spickle_params_arg5,
686 prog_char str_spickle_params_arg1_show[] = "show";
687 parse_pgm_token_string_t cmd_spickle_params_arg1_show =
688 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params_result, arg1, str_spickle_params_arg1_show);
690 prog_char help_spickle_params_show[] = "show spickle params";
691 parse_pgm_inst_t cmd_spickle_params_show = {
692 .f = cmd_spickle_params_parsed, /* function to call */
693 .data = NULL, /* 2nd arg of func */
694 .help_str = help_spickle_params_show,
695 .tokens = { /* token list, NULL terminated */
696 (prog_void *)&cmd_spickle_params_arg0,
697 (prog_void *)&cmd_spickle_params_arg1_show,
702 /**********************************************************/
703 /* Set Spickle Params */
705 /* this structure is filled when cmd_spickle_params2 is parsed successfully */
706 struct cmd_spickle_params2_result {
713 /* function called when cmd_spickle_params2 is parsed successfully */
714 static void cmd_spickle_params2_parsed(void *parsed_result,
715 __attribute__((unused)) void *data)
717 struct cmd_spickle_params2_result * res = parsed_result;
719 if (!strcmp_P(res->arg1, PSTR("wcoef"))) {
720 spickle_set_wcoefs(res->arg2, res->arg3);
722 else if (!strcmp_P(res->arg1, PSTR("scoef"))) {
723 spickle_set_scoefs(res->arg2, res->arg3);
727 spickle_dump_params();
730 prog_char str_spickle_params2_arg0[] = "spickle_params";
731 parse_pgm_token_string_t cmd_spickle_params2_arg0 =
732 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params2_result, arg0, str_spickle_params2_arg0);
733 prog_char str_spickle_params2_arg1[] = "wcoef#scoef";
734 parse_pgm_token_string_t cmd_spickle_params2_arg1 =
735 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params2_result, arg1, str_spickle_params2_arg1);
736 parse_pgm_token_num_t cmd_spickle_params2_arg2 =
737 TOKEN_NUM_INITIALIZER(struct cmd_spickle_params2_result, arg2, INT32);
738 parse_pgm_token_num_t cmd_spickle_params2_arg3 =
739 TOKEN_NUM_INITIALIZER(struct cmd_spickle_params2_result, arg3, INT32);
741 prog_char help_spickle_params2[] = "Set spickle_params2 values";
742 parse_pgm_inst_t cmd_spickle_params2 = {
743 .f = cmd_spickle_params2_parsed, /* function to call */
744 .data = NULL, /* 2nd arg of func */
745 .help_str = help_spickle_params2,
746 .tokens = { /* token list, NULL terminated */
747 (prog_void *)&cmd_spickle_params2_arg0,
748 (prog_void *)&cmd_spickle_params2_arg1,
749 (prog_void *)&cmd_spickle_params2_arg2,
750 (prog_void *)&cmd_spickle_params2_arg3,
755 prog_char str_spickle_params2_arg1_show[] = "show";
756 parse_pgm_token_string_t cmd_spickle_params2_arg1_show =
757 TOKEN_STRING_INITIALIZER(struct cmd_spickle_params2_result, arg1, str_spickle_params2_arg1_show);
759 prog_char help_spickle_params2_show[] = "show spickle params";
760 parse_pgm_inst_t cmd_spickle_params2_show = {
761 .f = cmd_spickle_params2_parsed, /* function to call */
762 .data = NULL, /* 2nd arg of func */
763 .help_str = help_spickle_params2_show,
764 .tokens = { /* token list, NULL terminated */
765 (prog_void *)&cmd_spickle_params2_arg0,
766 (prog_void *)&cmd_spickle_params2_arg1_show,
771 /**********************************************************/
772 /* Set Shovel Params */
774 /* this structure is filled when cmd_shovel_current is parsed successfully */
775 struct cmd_shovel_current_result {
782 /* function called when cmd_shovel_current is parsed successfully */
783 static void cmd_shovel_current_parsed(void *parsed_result,
784 __attribute__((unused)) void *data)
786 struct cmd_shovel_current_result * res = parsed_result;
790 if (!strcmp_P(res->arg1, PSTR("set")))
791 shovel_set_current_limit_coefs(res->arg2, res->arg3);
792 else if (!strcmp_P(res->arg1, PSTR("on")))
793 shovel_current_limit_enable(1);
794 else if (!strcmp_P(res->arg1, PSTR("off")))
795 shovel_current_limit_enable(0);
798 enable = shovel_get_current_limit_coefs(&k1, &k2);
799 printf_P(PSTR("enabled=%d k1=%"PRIi32" k2=%"PRIi32"\r\n"),
803 prog_char str_shovel_current_arg0[] = "shovel_current";
804 parse_pgm_token_string_t cmd_shovel_current_arg0 =
805 TOKEN_STRING_INITIALIZER(struct cmd_shovel_current_result, arg0, str_shovel_current_arg0);
806 prog_char str_shovel_current_arg1[] = "set";
807 parse_pgm_token_string_t cmd_shovel_current_arg1 =
808 TOKEN_STRING_INITIALIZER(struct cmd_shovel_current_result, arg1, str_shovel_current_arg1);
809 parse_pgm_token_num_t cmd_shovel_current_arg2 =
810 TOKEN_NUM_INITIALIZER(struct cmd_shovel_current_result, arg2, INT32);
811 parse_pgm_token_num_t cmd_shovel_current_arg3 =
812 TOKEN_NUM_INITIALIZER(struct cmd_shovel_current_result, arg3, INT32);
814 prog_char help_shovel_current[] = "Set shovel_current values";
815 parse_pgm_inst_t cmd_shovel_current = {
816 .f = cmd_shovel_current_parsed, /* function to call */
817 .data = NULL, /* 2nd arg of func */
818 .help_str = help_shovel_current,
819 .tokens = { /* token list, NULL terminated */
820 (prog_void *)&cmd_shovel_current_arg0,
821 (prog_void *)&cmd_shovel_current_arg1,
822 (prog_void *)&cmd_shovel_current_arg2,
823 (prog_void *)&cmd_shovel_current_arg3,
828 prog_char str_shovel_current_arg1_show[] = "show#on#off";
829 parse_pgm_token_string_t cmd_shovel_current_arg1_show =
830 TOKEN_STRING_INITIALIZER(struct cmd_shovel_current_result, arg1, str_shovel_current_arg1_show);
832 prog_char help_shovel_current_show[] = "show shovel params";
833 parse_pgm_inst_t cmd_shovel_current_show = {
834 .f = cmd_shovel_current_parsed, /* function to call */
835 .data = NULL, /* 2nd arg of func */
836 .help_str = help_shovel_current_show,
837 .tokens = { /* token list, NULL terminated */
838 (prog_void *)&cmd_shovel_current_arg0,
839 (prog_void *)&cmd_shovel_current_arg1_show,
844 /**********************************************************/
847 /* this structure is filled when cmd_test is parsed successfully */
848 struct cmd_test_result {
852 /* function called when cmd_test is parsed successfully */
853 static void cmd_test_parsed(__attribute__((unused)) void *parsed_result,
854 __attribute__((unused)) void *data)
858 prog_char str_test_arg0[] = "test";
859 parse_pgm_token_string_t cmd_test_arg0 =
860 TOKEN_STRING_INITIALIZER(struct cmd_test_result, arg0, str_test_arg0);
862 prog_char help_test[] = "Test function";
863 parse_pgm_inst_t cmd_test = {
864 .f = cmd_test_parsed, /* function to call */
865 .data = NULL, /* 2nd arg of func */
866 .help_str = help_test,
867 .tokens = { /* token list, NULL terminated */
868 (prog_void *)&cmd_test_arg0,