Urbanite: Parking aid system
|
Display system FSM main file. More...
#include <stdlib.h>
#include <stdio.h>
#include "port_display.h"
#include "port_system.h"
#include "fsm.h"
#include "fsm_display.h"
Data Structures | |
struct | fsm_display_t |
Structure of the Display FSM. More... | |
Functions | |
void | _compute_display_levels (rgb_color_t *p_color, int32_t distance_cm) |
Set color levels of the RGB LEDs according to the distance. More... | |
static bool | check_set_new_color (fsm_t *p_this) |
Check if a new color has to be set. More... | |
static bool | check_active (fsm_t *p_this) |
Check if the display is set to be active (ON), independently if it is idle or not. More... | |
static bool | check_off (fsm_t *p_this) |
Check if the display is set to be inactive (OFF). More... | |
static void | do_set_on (fsm_t *p_this) |
Turn the display system ON for the first time. More... | |
static void | do_set_color (fsm_t *p_this) |
Set the color of the RGB LED according to the distance measured by the ultrasound sensor. More... | |
static void | do_set_off (fsm_t *p_this) |
Turn the display system OFF. More... | |
static void | fsm_display_init (fsm_display_t *p_fsm_display, uint32_t display_id) |
Initialize a display system FSM. More... | |
fsm_display_t * | fsm_display_new (uint32_t display_id) |
Create a new display FSM. More... | |
void | fsm_display_destroy (fsm_display_t *p_fsm) |
Destroy a display FSM. More... | |
void | fsm_display_fire (fsm_display_t *p_fsm) |
Fire the display FSM. More... | |
void | fsm_display_set_distance (fsm_display_t *p_fsm, uint32_t distance_cm) |
Set the display system to show the distance in cm. More... | |
bool | fsm_display_get_status (fsm_display_t *p_fsm) |
Get the status of the display FSM. More... | |
void | fsm_display_set_status (fsm_display_t *p_fsm, bool status) |
Set the status of the display FSM. More... | |
bool | fsm_display_check_activity (fsm_display_t *p_fsm) |
Check if the display system is active. More... | |
fsm_t * | fsm_display_get_inner_fsm (fsm_display_t *p_fsm) |
Get the inner FSM of the display. More... | |
uint32_t | fsm_display_get_state (fsm_display_t *p_fsm) |
Get the state of the display FSM. More... | |
void | fsm_display_set_state (fsm_display_t *p_fsm, int8_t state) |
Set the state of the display FSM. More... | |
Variables | |
static fsm_trans_t | fsm_trans_display [] |
Array representing the transitions table of the FSM display. More... | |
Display system FSM main file.
void _compute_display_levels | ( | rgb_color_t * | p_color, |
int32_t | distance_cm | ||
) |
Set color levels of the RGB LEDs according to the distance.
This function sets the levels of an RGB LED according to the distance measured by the ultrasound sensor. This RGB LED structure is later passed to the port_display_set_rgb()
function to set the color of the RGB LED.
PORT_DISPLAY_RGB_MAX_VALUE
. The duty cycle of the PWM signal must be set according to the levels of the RGB LED.TODO alumnos:
✅ 1. Set the levels of the RGB LED according to the distance measured by the ultrasound sensor. To do so, follow the flowchart:
![]()
p_color | Pointer to an rgb_color_t struct that will store the levels of the RGB LED. |
distance_cm | Distance measured by the ultrasound sensor in centimeters. |
|
static |
Check if the display is set to be active (ON), independently if it is idle or not.
TODO alumnos:
✅ 1. Return the flag
status
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
|
static |
Check if the display is set to be inactive (OFF).
TODO alumnos:
✅ 1. Return the inverse of the flag
status
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
|
static |
Check if a new color has to be set.
TODO alumnos:
✅ 1. Return the flag
new_color
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
|
static |
Set the color of the RGB LED according to the distance measured by the ultrasound sensor.
TODO alumnos:
✅ 1. Compute the levels of the RGB LEDs according to the distance and set the display level
✅ 2. Call functionport_display_set_rgb()
with the RGB LED ID and the color
✅ 3. Reset the flagnew_color
to indicate that the color has been set
✅ 4. Set the display system to idle. In this case, the display system is active, but while the distance is not changed, the display system is idle and can enter in a low power mode
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
|
static |
Turn the display system OFF.
TODO alumnos:
✅ 1. Call function
port_display_set_rgb()
with the RGB LED ID with no color (COLOR_OFF
).
✅ 2. Reset the flagidle
to indicate that the display system is not idle
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
|
static |
Turn the display system ON for the first time.
TODO alumnos:
✅ 1. Call function
port_display_set_rgb()
with the RGB LED ID with no color (all the duty cycles to 0).
p_this | Pointer to an fsm_t struct than contains an fsm_display_t . |
bool fsm_display_check_activity | ( | fsm_display_t * | p_fsm | ) |
Check if the display system is active.
This function checks if the display system is active.
TODO alumnos
✅ 1. Return
true
if the display system is active and it is not idle. Otherwise, returnfalse
.
p_fsm | Pointer to an fsm_display_t struct. |
void fsm_display_destroy | ( | fsm_display_t * | p_fsm | ) |
Destroy a display FSM.
This function destroys a display FSM and frees the memory.
TODO alumnos:
✅ 1. Implement this function analogously to the
fsm_display_destroy()
function.
p_fsm | Pointer to an fsm_display_t struct. |
void fsm_display_fire | ( | fsm_display_t * | p_fsm | ) |
Fire the display FSM.
This function is used to fire the display FSM. It is used to check the transitions and execute the actions of the display FSM.
TODO alumnos:
✅ 1. Call the
fsm_fire()
function. Pass the address of thefsm_t
struct.
p_fsm | Pointer to an fsm_display_t struct. |
fsm_t* fsm_display_get_inner_fsm | ( | fsm_display_t * | p_fsm | ) |
Get the inner FSM of the display.
This function returns the inner FSM of the display.
💡 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_display_t struct. |
uint32_t fsm_display_get_state | ( | fsm_display_t * | p_fsm | ) |
Get the state of the display FSM.
This function returns the current state of the display 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_display_t struct. |
bool fsm_display_get_status | ( | fsm_display_t * | p_fsm | ) |
Get the status of the display FSM.
This function returns the status of the display system. This function might be used for testing and debugging purposes.
TODO alumnos:
✅ 1. Retrieve and return the field
status
.
p_fsm | Pointer to an fsm_display_t struct. |
|
static |
Initialize a display system FSM.
This function initializes the default values of the FSM struct and calls to the port
to initialize the associated HW given the ID.
The FSM stores the display level of the display system. The user should set it using the function fsm_display_set_distance()
.
The FSM contains information of the RGB LED ID. This ID is a unique identifier that is managed by the user in the port
. That is where the user provides identifiers and HW information for all the RGB LEDs on his system. The FSM does not have to know anything of the underlying HW.
TODO alumnos:
✅ 1. Call the
fsm_init()
to initialize the FSM. Pass the address of thefsm_t
struct and the transition table.
✅ 2. Initialize the ''distance_id. \n ✅ 3. Set the
distance_cmto
-1or any other invalid value in the range of the distance. \n ✅ 4. Initialize the flags
new_color,
status, and
idleto
false. \n ✅ 5. Call function
port_display_init()` to initialize the HW.
p_fsm_display | Pointer to the display FSM. |
display_id | Unique display identifier number. |
fsm_display_t* fsm_display_new | ( | uint32_t | display_id | ) |
Create a new display FSM.
This function creates a new display FSM with the given display ID.
display_id | Display ID. Must be unique. |
void fsm_display_set_distance | ( | fsm_display_t * | p_fsm, |
uint32_t | distance_cm | ||
) |
Set the display system to show the distance in cm.
This function is used to set the display system to show the distance in cm.
TODO alumnos:
✅ 1. Set the distance in cm in the display system FSM.
✅ 2. Set thenew_color
field accordingly to indicate that a new color has to be set.
p_fsm | Pointer to an fsm_display_t struct. |
distance_cm | Distance in cm to show in the display system. |
void fsm_display_set_state | ( | fsm_display_t * | p_fsm, |
int8_t | state | ||
) |
Set the state of the display FSM.
This function sets the current state of the display 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.
p_fsm | Pointer to an fsm_display_t struct. |
state | New state of the display FSM. |
void fsm_display_set_status | ( | fsm_display_t * | p_fsm, |
bool | pause | ||
) |
Set the status of the display FSM.
This function is used to set the status of the display system. Indicating if the display system is active or paused.
TODO alumnos:
✅ 1. Update the field
status
with the received value
p_fsm | Pointer to an fsm_display_t struct. |
pause | Status of the display system. true if the display system is paused, false if the display system is active. |
|
static |
Array representing the transitions table of the FSM display.