diff --git a/Code Telecommande/src/include/inputs.h b/Code Telecommande/src/include/inputs.h index e035cef..b675545 100644 --- a/Code Telecommande/src/include/inputs.h +++ b/Code Telecommande/src/include/inputs.h @@ -3,6 +3,8 @@ #include +#define ANGLE_PER_SECOND 45 + typedef enum buttons_t { BUTTON_L, BUTTON_R, @@ -29,6 +31,7 @@ extern const button_def_t BUTTONS_DEFS[]; typedef struct inputs_buffer_t { int8_t x_axis_speed; int8_t y_axis_speed; + int16_t robot_angle; bool buttons_states[NB_BUTTONS]; } inputs_buffer_t; diff --git a/Code Telecommande/src/inputs.c b/Code Telecommande/src/inputs.c index d122ba7..d298af9 100644 --- a/Code Telecommande/src/inputs.c +++ b/Code Telecommande/src/inputs.c @@ -27,7 +27,13 @@ void inputs_init(void) gpio_init(BUTTON_DEF->pin); gpio_set_dir(BUTTON_DEF->pin, GPIO_OUT); gpio_pull_up(BUTTON_DEF->pin); + + controller.inputs_buffer.buttons_states[actual_button] = 0; } + + controller.inputs_buffer.x_axis_speed = 0; + controller.inputs_buffer.y_axis_speed = 0; + controller.inputs_buffer.robot_angle = 0; } void get_inputs(void) @@ -47,4 +53,10 @@ void get_inputs(void) controller.inputs_buffer.buttons_states[actual_button] = gpio_get(BUTTON_DEF->pin); } + + if(controller.inputs_buffer.buttons_states[BUTTON_L]) + controller.inputs_buffer.robot_angle += controller.delta_time_ms / 1000.0f * ANGLE_PER_SECOND; + + if(controller.inputs_buffer.buttons_states[BUTTON_R]) + controller.inputs_buffer.robot_angle -= controller.delta_time_ms / 1000.0f * ANGLE_PER_SECOND; }