|
|
|
|
@ -17,21 +17,21 @@ void on_I2C_request() {
|
|
|
|
|
// Hopefully because most of our data is pulled in with queues, rather than larger locks,
|
|
|
|
|
// assembling the reply won't take too long.
|
|
|
|
|
|
|
|
|
|
i2c_reply.roller_1_speed = get_roller_speed(0);
|
|
|
|
|
i2c_reply.roller_2_speed = get_roller_speed(1);
|
|
|
|
|
i2c_reply.roller_3_speed = get_roller_speed(2);
|
|
|
|
|
i2c_reply.roller_1_revs = get_roller_revs(0);
|
|
|
|
|
i2c_reply.roller_2_revs = get_roller_revs(1);
|
|
|
|
|
i2c_reply.roller_3_revs = get_roller_revs(2);
|
|
|
|
|
i2c_reply.motor_1_duty = get_motor_duty(0);
|
|
|
|
|
i2c_reply.motor_2_duty = get_motor_duty(1);
|
|
|
|
|
i2c_reply.motor_3_duty = get_motor_duty(2);
|
|
|
|
|
i2c_reply.motor_1_control = get_motor_control(0);
|
|
|
|
|
i2c_reply.motor_2_control = get_motor_control(1);
|
|
|
|
|
i2c_reply.motor_3_control = get_motor_control(2);
|
|
|
|
|
i2c_reply.motor_1_params = get_motor_parameters(0);
|
|
|
|
|
i2c_reply.motor_2_params = get_motor_parameters(1);
|
|
|
|
|
i2c_reply.motor_3_params = get_motor_parameters(2);
|
|
|
|
|
i2c_reply.roller_1_speed = get_roller_speed(ROLLER_1);
|
|
|
|
|
i2c_reply.roller_2_speed = get_roller_speed(ROLLER_2);
|
|
|
|
|
i2c_reply.roller_3_speed = get_roller_speed(ROLLER_3);
|
|
|
|
|
i2c_reply.roller_1_revs = get_roller_revs(ROLLER_1);
|
|
|
|
|
i2c_reply.roller_2_revs = get_roller_revs(ROLLER_2);
|
|
|
|
|
i2c_reply.roller_3_revs = get_roller_revs(ROLLER_3);
|
|
|
|
|
i2c_reply.motor_1_duty = get_motor_duty(MOTOR_1);
|
|
|
|
|
i2c_reply.motor_2_duty = get_motor_duty(MOTOR_2);
|
|
|
|
|
i2c_reply.motor_3_duty = get_motor_duty(MOTOR_3);
|
|
|
|
|
i2c_reply.motor_1_control = get_motor_control(MOTOR_1);
|
|
|
|
|
i2c_reply.motor_2_control = get_motor_control(MOTOR_2);
|
|
|
|
|
i2c_reply.motor_3_control = get_motor_control(MOTOR_3);
|
|
|
|
|
i2c_reply.motor_1_params = get_motor_parameters(MOTOR_1);
|
|
|
|
|
i2c_reply.motor_2_params = get_motor_parameters(MOTOR_2);
|
|
|
|
|
i2c_reply.motor_3_params = get_motor_parameters(MOTOR_3);
|
|
|
|
|
|
|
|
|
|
Wire.write((byte *)&i2c_reply, sizeof(i2c_reply));
|
|
|
|
|
}
|
|
|
|
|
@ -43,15 +43,15 @@ void on_I2C_receive(int len){
|
|
|
|
|
Wire.readBytes((byte *)&motor_write_packet, len);
|
|
|
|
|
if (motor_write_packet.packet_type == MOTOR_CONTROL_PACKET){
|
|
|
|
|
// We got a motor control packet
|
|
|
|
|
set_motor_control(0, motor_write_packet.control.motor_1_control);
|
|
|
|
|
set_motor_control(1, motor_write_packet.control.motor_1_control);
|
|
|
|
|
set_motor_control(2, motor_write_packet.control.motor_1_control);
|
|
|
|
|
set_motor_control(MOTOR_1, motor_write_packet.control.motor_1_control);
|
|
|
|
|
set_motor_control(MOTOR_2, motor_write_packet.control.motor_2_control);
|
|
|
|
|
set_motor_control(MOTOR_3, motor_write_packet.control.motor_3_control);
|
|
|
|
|
|
|
|
|
|
} else if (motor_write_packet.packet_type == MOTOR_PARAMETERS_PACKET){
|
|
|
|
|
// We got a motor parameters packet
|
|
|
|
|
set_motor_params(0, motor_write_packet.params.motor_1_params);
|
|
|
|
|
set_motor_params(1, motor_write_packet.params.motor_1_params);
|
|
|
|
|
set_motor_params(2, motor_write_packet.params.motor_1_params);
|
|
|
|
|
set_motor_params(MOTOR_1, motor_write_packet.params.motor_1_params);
|
|
|
|
|
set_motor_params(MOTOR_2, motor_write_packet.params.motor_2_params);
|
|
|
|
|
set_motor_params(MOTOR_3, motor_write_packet.params.motor_3_params);
|
|
|
|
|
} else {
|
|
|
|
|
// I2C error
|
|
|
|
|
}
|
|
|
|
|
|