Browse Source

esp32蓝牙连接灯光闪烁,蓝牙未连接1000ms闪烁一次,连接蓝牙300ms闪烁一次

master
zwsd 3 years ago
parent
commit
40625f03e0
  1. 2
      main/ble_spp_server_demo.c
  2. 1
      main/ble_spp_server_demo.h
  3. 7
      main/main.c
  4. 4
      main/port.c
  5. 2
      main/port.h

2
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;

1
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);

7
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();

4
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();
}

2
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();
Loading…
Cancel
Save