FSM thermostat
fsm_thermostat.h
Go to the documentation of this file.
1 
9 #ifndef FSM_THERMOSTAT_H
10 #define FSM_THERMOSTAT_H
11 
12 /* Includes ------------------------------------------------------------------*/
13 /* Standard C includes */
14 #include <stdint.h>
15 
16 /* Other includes */
17 #include <fsm.h>
18 #include "port_led.h"
19 #include "port_temp_sensor.h"
20 
21 /* Defines and enums ----------------------------------------------------------*/
22 /* Defines */
23 #define THERMOSTAT_TIMEOUT_SEC 1
24 #define THERMOSTAT_HISTORY 10
25 #define THERMOSTAT_DEFAULT_THRESHOLD 25
27 /* Enums */
28 
33 {
36 };
37 
43 {
44  UNKNOWN = -1,
45  ACTIVATION = 0,
47 };
48 
49 /* Typedefs ------------------------------------------------------------------*/
53 typedef struct
54 {
55  fsm_t f;
59  bool last_events[THERMOSTAT_HISTORY];
60  uint32_t last_time_events[THERMOSTAT_HISTORY];
61  uint8_t event_idx;
63  uint32_t timer_period_sec;
65 
66 /* Function prototypes and explanations ---------------------------------------*/
75 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);
76 
83 uint32_t fsm_thermostat_get_last_time_event(fsm_t *p_this, uint8_t event);
84 
90 uint8_t fsm_thermostat_get_status(fsm_t *p_this);
91 
92 #endif /* FSM_THERMOSTAT_H */
THERMOSTAT_EVENTS
THERMOSTAT_EVENTS
Enumerates the events of the thermostat FSM.
Definition: fsm_thermostat.h:42
FSM_THERMOSTAT_STATES
FSM_THERMOSTAT_STATES
Enumerates the states of the thermostat FSM.
Definition: fsm_thermostat.h:32
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.
Definition: fsm_thermostat.c:174
fsm_thermostat_t::p_temp_sensor
port_temp_hw_t * p_temp_sensor
Definition: fsm_thermostat.h:58
UNKNOWN
@ UNKNOWN
Definition: fsm_thermostat.h:44
ACTIVATION
@ ACTIVATION
Definition: fsm_thermostat.h:45
port_led_hw_t
Structure to define the HW dependencies of a LED.
Definition: port_led.h:30
fsm_thermostat_t
Structure to define the thermostat FSM.
Definition: fsm_thermostat.h:53
fsm_thermostat_t::threshold_temp_celsius
double threshold_temp_celsius
Definition: fsm_thermostat.h:62
port_temp_sensor.h
Header file for the temperature sensor port layer.
port_led.h
Header file for the LED port layer.
DEACTIVATION
@ DEACTIVATION
Definition: fsm_thermostat.h:46
fsm_thermostat_t::timer_period_sec
uint32_t timer_period_sec
Definition: fsm_thermostat.h:63
port_temp_hw_t
Structure to define the HW dependencies of a temperature sensor.
Definition: port_temp_sensor.h:31
fsm_thermostat_t::p_led_comfort
port_led_hw_t * p_led_comfort
Definition: fsm_thermostat.h:57
THERMOSTAT_HISTORY
#define THERMOSTAT_HISTORY
Definition: fsm_thermostat.h:24
fsm_thermostat_t::f
fsm_t f
Definition: fsm_thermostat.h:55
fsm_thermostat_t::event_idx
uint8_t event_idx
Definition: fsm_thermostat.h:61
fsm_thermostat_get_status
uint8_t fsm_thermostat_get_status(fsm_t *p_this)
Gets the thermostat status.
Definition: fsm_thermostat.c:123
fsm_thermostat_t::p_led_heat
port_led_hw_t * p_led_heat
Definition: fsm_thermostat.h:56
THERMOSTAT_ON
@ THERMOSTAT_ON
Definition: fsm_thermostat.h:35
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,...
Definition: fsm_thermostat.c:108
THERMOSTAT_OFF
@ THERMOSTAT_OFF
Definition: fsm_thermostat.h:34