diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 7af198f..e4ee713 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,6 +2,7 @@ set(srcs "app_main.cpp" # "ble_spp_server_demo.c" "camera.cpp" "light.c" + "port.c" ) idf_component_register(SRCS "${srcs}"# diff --git a/main/light.c b/main/light.c index 093ab1a..52c9aa9 100644 --- a/main/light.c +++ b/main/light.c @@ -2,6 +2,7 @@ #include "driver/gpio.h" #include "esp_log.h" +#include "port.h" #define GPIO_DEBUG_LIGHT 12 #define GPIO_POWER_LIGHT 12 @@ -95,6 +96,12 @@ void T_wifi_state_light_init(wifi_state_light_structer_t *wifi_state_light_struc void T_debug_light_schedule(void) { + static uint32_t debug_light_time; + if (port_haspassedms(debug_light_time) > 300) + { + T_debug_light_toggle_level(); + debug_light_time = port_get_ticket(); + } } void T_light_schedule(void) diff --git a/main/port.c b/main/port.c new file mode 100644 index 0000000..7fda6cb --- /dev/null +++ b/main/port.c @@ -0,0 +1,18 @@ +#include "port.h" + +#include "driver/gpio.h" +#include "esp_log.h" + +uint32_t port_get_ticket() { return esp_log_timestamp(); } + +uint32_t port_haspassedms(uint32_t ticket) { return port_get_ticket() - ticket; } + +uint32_t port_delay_ms(uint32_t ms) +{ + uint32_t now = port_get_ticket(); + while (port_get_ticket() - now < ms) + { + } + + return 0; +} \ No newline at end of file diff --git a/main/port.h b/main/port.h new file mode 100644 index 0000000..6db47d0 --- /dev/null +++ b/main/port.h @@ -0,0 +1,6 @@ +#pragma once +#include + +uint32_t port_get_ticket(); +uint32_t port_haspassedms(uint32_t ticket); +uint32_t port_delay_ms(uint32_t ms); \ No newline at end of file