From 40625f03e0242afe6865faa9dda36e4c273bd6af Mon Sep 17 00:00:00 2001 From: zwsd Date: Mon, 8 Aug 2022 15:33:30 +0800 Subject: [PATCH] =?UTF-8?q?esp32=E8=93=9D=E7=89=99=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=81=AF=E5=85=89=E9=97=AA=E7=83=81=EF=BC=8C=E8=93=9D=E7=89=99?= =?UTF-8?q?=E6=9C=AA=E8=BF=9E=E6=8E=A51000ms=E9=97=AA=E7=83=81=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=EF=BC=8C=E8=BF=9E=E6=8E=A5=E8=93=9D=E7=89=99300ms?= =?UTF-8?q?=E9=97=AA=E7=83=81=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/ble_spp_server_demo.c | 2 ++ main/ble_spp_server_demo.h | 1 + main/main.c | 7 ++++++- main/port.c | 4 ++-- main/port.h | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/main/ble_spp_server_demo.c b/main/ble_spp_server_demo.c index fc9a6be..239e081 100644 --- a/main/ble_spp_server_demo.c +++ b/main/ble_spp_server_demo.c @@ -590,6 +590,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ case ESP_GATTS_STOP_EVT: break; case ESP_GATTS_CONNECT_EVT: + s_module->ble_connect_flag = true; table_conn_id_m = param->connect.conn_id; table_gatts_if_m = gatts_if; table_handle_m = spp_handle_table[SPP_IDX_SPP_DATA_NTY_VAL]; @@ -603,6 +604,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ #endif break; case ESP_GATTS_DISCONNECT_EVT: + s_module->ble_connect_flag = false; table_conn_id_m = 0; table_gatts_if_m = 0; table_handle_m = 0; diff --git a/main/ble_spp_server_demo.h b/main/ble_spp_server_demo.h index c83ede3..bf0f514 100644 --- a/main/ble_spp_server_demo.h +++ b/main/ble_spp_server_demo.h @@ -76,6 +76,7 @@ typedef struct { const char *bleName; int last_rx_ticket; + bool ble_connect_flag; } bleuart_t; /*接收完整JSON*/ typedef void (*blerxcb_t)(uint8_t *rx, size_t rxsize); diff --git a/main/main.c b/main/main.c index 7fb1c51..c859955 100644 --- a/main/main.c +++ b/main/main.c @@ -39,6 +39,7 @@ bleuart_t ble_uart_init_struct = { .receive_data_processing_flag = false, .maxClientNum = 1, .bleName = "yimei_ble", + .ble_connect_flag = false, }; motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; @@ -188,7 +189,11 @@ void app_main(void) { gpio_output_debug_light_init(); while (true) { - port_do_debug_light_state(); + if (ble_uart_init_struct.ble_connect_flag == true) { + port_do_debug_light_state(300); + }else{ + port_do_debug_light_state(1000); + } bleuart_schedule(); motor_module_schedule(); diff --git a/main/port.c b/main/port.c index 04381b7..3abaf81 100644 --- a/main/port.c +++ b/main/port.c @@ -48,9 +48,9 @@ void gpio_output_debug_light_init() { gpio_config(&gpio_grb_led_structer); } -void port_do_debug_light_state() { +void port_do_debug_light_state(uint16_t interval_time) { static uint32_t debug_light_time; - if (port_haspassedms(debug_light_time) > 500) { + if (port_haspassedms(debug_light_time) > interval_time) { gpio_set_level(GPIO_DEBUG_LIGHT, !gpio_get_level(GPIO_DEBUG_LIGHT)); debug_light_time = port_get_ticket(); } diff --git a/main/port.h b/main/port.h index bda7a13..40cd850 100644 --- a/main/port.h +++ b/main/port.h @@ -29,5 +29,5 @@ uint32_t port_delay_ms(uint32_t ms); void gpio_electric_relay_init(); void gpio_output_debug_light_init(); -void port_do_debug_light_state(); +void port_do_debug_light_state(uint16_t interval_time); void gpio_input_key_init(); \ No newline at end of file