FSM thermostat
main.c
Go to the documentation of this file.
1 
10 /* INCLUDES */
11 #include <stdio.h>
12 #include "port_system.h"
13 #include "port_led.h"
14 #include "fsm_thermostat.h"
15 
16 /* Defines and macros --------------------------------------------------------*/
17 //#define USE_LED_ON
18 
19 /* MAIN FUNCTION */
20 
26 int main()
27 {
28  // Local variables
29  uint8_t previous_thermostat_status = UNKNOWN;
30 
31  /* Init board */
33 
34 #ifdef USE_LED_ON
35  // Initialize the GPIOs for the LED on which might be off and it is not part of the FSM
38  port_system_delay_ms(500); // Wait for 500 ms
40 #endif
41 
42  // Create an thermostat FSM and get a pointer to it
44 
45  while (1)
46  {
47  // Launch the FSM
48  fsm_fire(p_fsm_thermostat);
49 
50  uint8_t current_thermostat_status = fsm_thermostat_get_status(p_fsm_thermostat);
51  if (current_thermostat_status != previous_thermostat_status)
52  {
53  uint32_t last_time_activated = fsm_thermostat_get_last_time_event(p_fsm_thermostat, current_thermostat_status);
54  if (current_thermostat_status == ACTIVATION)
55  {
56  printf("Thermostat ON at %ld\n", last_time_activated);
57  }
58  else if (current_thermostat_status == DEACTIVATION)
59  {
60  printf("Thermostat OFF at %ld\n", last_time_activated);
61  }
62  previous_thermostat_status = current_thermostat_status;
63  }
64  }
65  return 0;
66 }
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
led_comfort_temperature
port_led_hw_t led_comfort_temperature
Definition: port_led.c:18
UNKNOWN
@ UNKNOWN
Definition: fsm_thermostat.h:44
ACTIVATION
@ ACTIVATION
Definition: fsm_thermostat.h:45
port_led_init
void port_led_init(port_led_hw_t *p_led)
Initializes the LED.
Definition: port_led.c:41
port_system_delay_ms
void port_system_delay_ms(uint32_t ms)
Wait for some milliseconds.
Definition: port_system.c:135
fsm_thermostat.h
Header file for the thermostat FSM.
port_led_off
void port_led_off(port_led_hw_t *p_led)
Turn off the LED.
Definition: port_led.c:31
port_led.h
Header file for the LED port layer.
DEACTIVATION
@ DEACTIVATION
Definition: fsm_thermostat.h:46
led_on
port_led_hw_t led_on
Definition: port_led.c:19
port_system.h
Header for port_system.c file.
led_heater_active
port_led_hw_t led_heater_active
Definition: port_led.c:17
fsm_thermostat_get_status
uint8_t fsm_thermostat_get_status(fsm_t *p_this)
Gets the thermostat status.
Definition: fsm_thermostat.c:123
main
int main()
Main function.
Definition: main.c:26
port_led_on
void port_led_on(port_led_hw_t *p_led)
Turn on the LED.
Definition: port_led.c:26
port_system_init
size_t port_system_init(void)
This function is based on the initialization of the HAL Library; it must be the first thing to be exe...
Definition: port_system.c:89
temp_sensor_thermostat
port_temp_hw_t temp_sensor_thermostat
Definition: port_temp_sensor.c:20
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