|
Simone: a game of visual memory and speed
|
Header for fsm_button.c file. More...
#include <stdint.h>#include <stdbool.h>#include "fsm.h"Data Structures | |
| struct | fsm_button_t |
| Structure of the Button FSM. More... | |
Enumerations | |
| enum | FSM_BUTTON { BUTTON_RELEASED = 0, BUTTON_RELEASED_WAIT, BUTTON_PRESSED, BUTTON_PRESSED_WAIT } |
| Enumerator for the button finite state machine. More... | |
Functions | |
| fsm_button_t * | fsm_button_new (uint32_t debounce_time_ms, uint8_t button_id) |
| Create a new button FSM. More... | |
| void | fsm_button_destroy (fsm_button_t *p_fsm) |
| Destroy a button FSM. More... | |
| void | fsm_button_fire (fsm_button_t *p_fsm) |
| Fire the button FSM. More... | |
| uint32_t | fsm_button_get_duration (fsm_button_t *p_fsm) |
| Return the duration of the last button press. More... | |
| void | fsm_button_reset_duration (fsm_button_t *p_fsm) |
| Reset the duration of the last button press. More... | |
| uint32_t | fsm_button_get_debounce_time_ms (fsm_button_t *p_fsm) |
| Get the debounce time of the button FSM. More... | |
| bool | fsm_button_check_activity (fsm_button_t *p_fsm) |
| Check if the button FSM is active, or not. More... | |
Header for fsm_button.c file.
| enum FSM_BUTTON |
Enumerator for the button finite state machine.
This enumerator defines the different states that the button finite state machine can be in. Each state represents a specific condition or step in the button press process.
| bool fsm_button_check_activity | ( | fsm_button_t * | p_fsm | ) |
Check if the button FSM is active, or not.
The button is inactive when it is in the status BUTTON_RELEASED.
TODO alumnos Version 4:
✅ 1. Get the field
current_stateof the FSM (fieldfof the struct).
✅ 2. Returnfalseif the current state isBUTTON_RELEASED. Otherwise, returntrue.
| p_fsm | Pointer to an fsm_button_t struct. |
| void fsm_button_destroy | ( | fsm_button_t * | p_fsm | ) |
Destroy a button FSM.
This function destroys a button FSM and frees the memory.
| p_fsm | Pointer to an fsm_button_t struct. |
| void fsm_button_fire | ( | fsm_button_t * | p_fsm | ) |
Fire the button FSM.
This function is used to fire the button FSM. It is used to check the transitions and execute the actions of the button FSM.
TODO alumnos:
✅ 1. Call the
fsm_fire()function. Pass the address of thefsm_tstruct.
| p_fsm | Pointer to an fsm_button_t struct. |
| uint32_t fsm_button_get_debounce_time_ms | ( | fsm_button_t * | p_fsm | ) |
Get the debounce time of the button FSM.
This function returns the debounce time of the button FSM.
TODO alumnos:
✅ 1. Retrieve and return the field
debounce_time_ms
| p_fsm | Pointer to an fsm_button_t struct. |
| uint32_t fsm_button_get_duration | ( | fsm_button_t * | p_fsm | ) |
Return the duration of the last button press.
TODO alumnos:
✅ 1. Retrieve and return the field
duration
| p_fsm | Pointer to an fsm_button_t struct. |
| fsm_button_t* fsm_button_new | ( | uint32_t | debounce_time_ms, |
| uint8_t | button_id | ||
| ) |
Create a new button FSM.
This function creates a new button FSM with the given debounce time and button ID.
| debounce_time_ms | Debounce time in milliseconds. |
| button_id | Button ID. Must be unique. |
| void fsm_button_reset_duration | ( | fsm_button_t * | p_fsm | ) |
Reset the duration of the last button press.
TODO alumnos:
✅ 1. Set to 0 the field
duration
| p_fsm | Pointer to an fsm_button_t struct. |