2 * Copyright Droids Corporation (2007)
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: i2c_protocol.c,v 1.3 2009-05-27 20:04:07 zer0 Exp $
25 #include <aversive/list.h>
26 #include <aversive/error.h>
28 #include <scheduler.h>
34 #include <clock_time.h>
39 #include <control_system_manager.h>
40 #include <blocking_detection_manager.h>
44 #include <parse_string.h>
45 #include <parse_num.h>
47 #include "../common/i2c_commands.h"
53 void i2c_protocol_init(void)
58 void i2c_led_control(uint8_t l, uint8_t state)
62 state? LED1_ON():LED1_OFF();
65 state? LED2_ON():LED2_OFF();
72 void i2c_send_status(void)
74 struct i2c_ans_ballboard_status ans;
76 ans.hdr.cmd = I2C_ANS_BALLBOARD_STATUS;
77 ans.status = 0x55; /* XXX */
78 ans.ball_count = state_get_ball_count();
79 ans.lcob = cob_detect_left();
80 ans.rcob = cob_detect_right();
82 i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans,
83 sizeof(ans), I2C_CTRL_GENERIC);
86 static int8_t i2c_set_mode(struct i2c_cmd_ballboard_set_mode *cmd)
88 state_set_mode(cmd->mode);
92 void i2c_recvevent(uint8_t * buf, int8_t size)
108 /* Commands (no answer needed) */
109 case I2C_CMD_GENERIC_LED_CONTROL:
111 struct i2c_cmd_led_control *cmd = void_cmd;
112 if (size != sizeof (*cmd))
114 i2c_led_control(cmd->led_num, cmd->state);
118 case I2C_CMD_GENERIC_SET_COLOR:
120 struct i2c_cmd_generic_color *cmd = void_cmd;
121 if (size != sizeof (*cmd))
123 ballboard.our_color = cmd->color;
127 case I2C_CMD_BALLBOARD_SET_MODE:
129 struct i2c_cmd_ballboard_set_mode *cmd = void_cmd;
130 if (size != sizeof(struct i2c_cmd_ballboard_set_mode))
137 /* Add other commands here ...*/
140 case I2C_REQ_BALLBOARD_STATUS:
142 struct i2c_req_ballboard_status *cmd = void_cmd;
143 if (size != sizeof (*cmd))
155 /* log error on a led ? */
159 void i2c_recvbyteevent(uint8_t hwstatus, uint8_t i, uint8_t c)
163 void i2c_sendevent(int8_t size)