X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fcobboard%2Fi2c_protocol.c;h=21a9bd8b12e9e61d8ee83a9ca13de768c3f0f12c;hp=77846d098bb24b5e5b47cf0eeec67c85f66a8225;hb=d10eb76208e401ae2c4dc44de2f96cdcf2e7e4ac;hpb=4fb57a4dab8bd564445e824696a2dab470af8628 diff --git a/projects/microb2010/cobboard/i2c_protocol.c b/projects/microb2010/cobboard/i2c_protocol.c index 77846d0..21a9bd8 100644 --- a/projects/microb2010/cobboard/i2c_protocol.c +++ b/projects/microb2010/cobboard/i2c_protocol.c @@ -93,41 +93,35 @@ static void i2c_send_status(void) /* status */ ans.mode = state_get_mode(); - ans.status = 0x55; /* TODO */ + ans.status = state_get_status(); ans.left_cobroller_speed = cobboard.left_cobroller_speed; ans.right_cobroller_speed = cobboard.right_cobroller_speed; ans.cob_count = state_get_cob_count(); -; + i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans, sizeof(ans), I2C_CTRL_GENERIC); } -static int8_t i2c_set_mode(struct i2c_cmd_cobboard_set_mode *cmd) -{ - state_set_mode(cmd->mode); - return 0; -} - void i2c_recvevent(uint8_t * buf, int8_t size) { void *void_cmd = buf; - + static uint8_t a = 0; - + a++; if (a & 0x10) LED2_TOGGLE(); - + if (size <= 0) { goto error; } - + switch (buf[0]) { /* Commands (no answer needed) */ - case I2C_CMD_GENERIC_LED_CONTROL: + case I2C_CMD_GENERIC_LED_CONTROL: { struct i2c_cmd_led_control *cmd = void_cmd; if (size != sizeof (*cmd)) @@ -135,13 +129,14 @@ void i2c_recvevent(uint8_t * buf, int8_t size) i2c_led_control(cmd->led_num, cmd->state); break; } - + case I2C_CMD_COBBOARD_SET_MODE: { struct i2c_cmd_cobboard_set_mode *cmd = void_cmd; if (size != sizeof(struct i2c_cmd_cobboard_set_mode)) goto error; - i2c_set_mode(cmd); + if (!state_get_i2c_ignore()) + state_set_mode(cmd->mode); break; } @@ -155,7 +150,7 @@ void i2c_recvevent(uint8_t * buf, int8_t size) } #ifdef notyet - case I2C_CMD_EXTENSION_TEST: + case I2C_CMD_EXTENSION_TEST: { struct i2c_cmd_extension_test *cmd = void_cmd; if (size != sizeof (*cmd)) @@ -164,16 +159,21 @@ void i2c_recvevent(uint8_t * buf, int8_t size) break; } #endif - - /* Add other commands here ...*/ + /* Add other commands here ...*/ case I2C_REQ_COBBOARD_STATUS: { - //struct i2c_req_cobboard_status *cmd = void_cmd; + struct i2c_req_cobboard_status *cmd = void_cmd; if (size != sizeof (struct i2c_req_cobboard_status)) goto error; - + + /* mode is in req */ + if (state_get_status() != I2C_COBBOARD_STATUS_OFF && + !state_get_i2c_ignore()) { + state_set_spickle(I2C_LEFT_SIDE, cmd->lspickle); + state_set_spickle(I2C_RIGHT_SIDE, cmd->rspickle); + } i2c_send_status(); break; }