Untitled
unknown
plain_text
2 years ago
1.8 kB
4
Indexable
#include "stddef.h" #include "fsm.h" #include "app_driver.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" extern int boton; static int tiempo_b_op_ms = 100; static int tiempo_c_op_ms = 2000; static int luz; static TickType_t next_b_op_1; static int comprueba_boton (fsm_t* this) { return boton; } static int comprueba_deadline(fsm_t* this) { return (xTaskGetTickCount() >= next_b_op_1)&&(boton!=1); } static void luz_on(fsm_t* this) { next_b_op_1 = xTaskGetTickCount() + (tiempo_b_op_ms / portTICK_PERIOD_MS); boton = 0; luz = 1; app_driver_luz_on(); } static void luz_on_1(fsm_t* this) { next_b_op_1 = xTaskGetTickCount() + (tiempo_c_op_ms / portTICK_PERIOD_MS); boton = 0; luz = 1; app_driver_luz_on(); } static void luz_off (fsm_t* this) { boton = 0; luz = 0; app_driver_luz_off(); } static void luz_change_1 (fsm_t* this) { next_b_op_1 += (tiempo_b_op_ms / portTICK_PERIOD_MS); //como compruebo q la luz esta encendida o apagada? //puedo saber si el led esta encendido o apagado, con una variable global if(luz==1){ luz=0; app_driver_luz_off(); }else{ luz=1; app_driver_luz_on(); } } static void luz_change_2 (fsm_t* this) { next_b_op_1 += (tiempo_c_op_ms / portTICK_PERIOD_MS); if(luz==1){ luz=0; app_driver_luz_off(); }else{ luz=1; app_driver_luz_on(); } } fsm_t* fsm_new_ledButton(void) { static fsm_trans_t tt[] = { // Estado Condicion Proximo estado Funcion de accion { 0, comprueba_boton, 1, luz_on }, { 1, comprueba_boton, 2, luz_on_1 }, { 1, comprueba_deadline, 1, luz_change_1}, { 2, comprueba_boton, 0, luz_off}, { 2, comprueba_deadline, 2, luz_change_2}, { -1, NULL, -1, NULL } }; return fsm_new(tt); }
Editor is loading...