Urbanite: Parking aid system
|
Header for fsm_button.c file. More...
#include <stdint.h>
#include <stdbool.h>
#include "fsm.h"
Typedefs | |
typedef struct fsm_button_t | fsm_button_t |
Structure to define the Button FSM. | |
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, uint32_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... | |
fsm_t * | fsm_button_get_inner_fsm (fsm_button_t *p_fsm) |
Get the inner FSM of the button. More... | |
uint32_t | fsm_button_get_state (fsm_button_t *p_fsm) |
Get the state of 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_state
of the FSM (fieldf
of the struct).
✅ 2. Returnfalse
if 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_t
struct.
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_t* fsm_button_get_inner_fsm | ( | fsm_button_t * | p_fsm | ) |
Get the inner FSM of the button.
This function returns the inner FSM of the button.
💡 This function is important because the struct is private and external functions such as those of the unit tests cannot access the inner FSM directly.
TODO alumnos:
✅ 1. Return the address of the
f
field of the struct.
p_fsm | Pointer to an fsm_button_t struct. |
uint32_t fsm_button_get_state | ( | fsm_button_t * | p_fsm | ) |
Get the state of the button FSM.
This function returns the current state of the button FSM.
💡 This function is important because the struct is private and external functions such as those of the unit tests cannot access the state of the FSM directly.
TODO alumnos:
✅ 1. Retrieve and return the field
current_state
of the FSM (fieldf
of the struct).
p_fsm | Pointer to an fsm_button_t struct. |
fsm_button_t* fsm_button_new | ( | uint32_t | debounce_time_ms, |
uint32_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. |