FSM thermostat
fsm_thermostat.c File Reference

Finite State Machine for a thermostat. More...

#include <stdlib.h>
#include <string.h>
#include "fsm_thermostat.h"
#include "port_thermostat.h"
#include "port_led.h"
#include "port_temp_sensor.h"

Go to the source code of this file.

Functions

bool check_heat (fsm_t *p_this)
 Check if the temperature is cold enough to activate the thermostat. More...
 
bool check_comfort (fsm_t *p_this)
 Check if the temperature is hot enough to deactivate the thermostat. More...
 
void do_thermostat_on (fsm_t *p_this)
 Turn off the thermostat. More...
 
void do_thermostat_off (fsm_t *p_this)
 Turn on the thermostat. More...
 
uint32_t fsm_thermostat_get_last_time_event (fsm_t *p_this, uint8_t event)
 Gets the last time there was an event in the thermostat. If the event is not found, it returns 0. More...
 
uint8_t fsm_thermostat_get_status (fsm_t *p_this)
 Gets the thermostat status. More...
 
void fsm_thermostat_init (fsm_t *p_this, port_led_hw_t *p_led_heat, port_led_hw_t *p_led_comfort, port_temp_hw_t *p_temp)
 Initialize the thermostat FSM. More...
 
fsm_t * fsm_thermostat_new (port_led_hw_t *p_led_heat, port_led_hw_t *p_led_comfort, port_temp_hw_t *p_temp)
 Creates a new thermostat FSM. More...
 

Variables

fsm_trans_t fsm_trans_thermostat []
 Transitions table for the thermostat. More...
 

Detailed Description

Finite State Machine for a thermostat.

Author
Josué Pagán (j.pag.nosp@m.an@u.nosp@m.pm.es)
Date
2024-05-01

Definition in file fsm_thermostat.c.

Function Documentation

◆ check_comfort()

bool check_comfort ( fsm_t *  p_this)

Check if the temperature is hot enough to deactivate the thermostat.

Parameters
p_thisPointer to the FSM structure
Returns
true if the temperature is hot, false otherwise

Definition at line 50 of file fsm_thermostat.c.

◆ check_heat()

bool check_heat ( fsm_t *  p_this)

Check if the temperature is cold enough to activate the thermostat.

Parameters
p_thisPointer to the FSM structure
Returns
true if the temperature is cold, false otherwise

Definition at line 28 of file fsm_thermostat.c.

◆ do_thermostat_off()

void do_thermostat_off ( fsm_t *  p_this)

Turn on the thermostat.

Parameters
p_thisPointer to the thermostat FSM structure

Definition at line 82 of file fsm_thermostat.c.

◆ do_thermostat_on()

void do_thermostat_on ( fsm_t *  p_this)

Turn off the thermostat.

Parameters
p_thisPointer to the thermostat FSM structure

Definition at line 62 of file fsm_thermostat.c.

◆ fsm_thermostat_get_last_time_event()

uint32_t fsm_thermostat_get_last_time_event ( fsm_t *  p_this,
uint8_t  event 
)

Gets the last time there was an event in the thermostat. If the event is not found, it returns 0.

Parameters
p_thisPointer to the thermostat FSM structure.
eventEvent to check. It can be any of the events in the THERMOSTAT_EVENTS enum.

Definition at line 108 of file fsm_thermostat.c.

◆ fsm_thermostat_get_status()

uint8_t fsm_thermostat_get_status ( fsm_t *  p_this)

Gets the thermostat status.

Parameters
p_thisPointer to the thermostat FSM structure.

Definition at line 123 of file fsm_thermostat.c.

◆ fsm_thermostat_init()

void fsm_thermostat_init ( fsm_t *  p_this,
port_led_hw_t p_led_heat,
port_led_hw_t p_led_comfort,
port_temp_hw_t p_temp 
)

Initialize the thermostat FSM.

Parameters
p_thisPointer to the FSM structure
p_led_heatPointer to the LED structure
p_led_comfortPointer to the LED structure
p_tempPointer to the temperature sensor structure

Definition at line 139 of file fsm_thermostat.c.

◆ fsm_thermostat_new()

fsm_t* fsm_thermostat_new ( port_led_hw_t p_led_heat,
port_led_hw_t p_led_comfort,
port_temp_hw_t p_temp 
)

Creates a new thermostat FSM.

Parameters
p_led_heatPointer to the LED of the thermostat.
p_led_comfortPointer to the comfort LED of the thermostat.
p_tempPointer to the temperature sensor of the thermostat.
Returns
fsm_thermostat_t* Pointer to the new thermostat FSM.

Definition at line 174 of file fsm_thermostat.c.

Variable Documentation

◆ fsm_trans_thermostat

fsm_trans_t fsm_trans_thermostat[]
Initial value:

Transitions table for the thermostat.

Definition at line 102 of file fsm_thermostat.c.

check_comfort
bool check_comfort(fsm_t *p_this)
Check if the temperature is hot enough to deactivate the thermostat.
Definition: fsm_thermostat.c:50
do_thermostat_on
void do_thermostat_on(fsm_t *p_this)
Turn off the thermostat.
Definition: fsm_thermostat.c:62
do_thermostat_off
void do_thermostat_off(fsm_t *p_this)
Turn on the thermostat.
Definition: fsm_thermostat.c:82
check_heat
bool check_heat(fsm_t *p_this)
Check if the temperature is cold enough to activate the thermostat.
Definition: fsm_thermostat.c:28
THERMOSTAT_ON
@ THERMOSTAT_ON
Definition: fsm_thermostat.h:35
THERMOSTAT_OFF
@ THERMOSTAT_OFF
Definition: fsm_thermostat.h:34