Browse Source

封装了led,蓝牙连接成功绿灯会亮起,关闭连接绿灯关闭

devtest
zwsd 3 years ago
parent
commit
7672ab42e4
  1. 1
      main/CMakeLists.txt
  2. 3
      main/ble_spp_server_demo.c
  3. 19
      main/main.c
  4. 1
      main/motor_drive.c
  5. 13
      main/rgb_led.c
  6. 10
      main/rgb_led.h

1
main/CMakeLists.txt

@ -6,6 +6,7 @@ idf_component_register(SRCS #
"ble_parse_data.c"
"motor_drive.c"
"ble_uart.c"
"rgb_led.c"
INCLUDE_DIRS #
"../dep/"
".")

3
main/ble_spp_server_demo.c

@ -7,6 +7,7 @@
*/
#include "ble_spp_server_demo.h"
#include "rgb_led.h"
#define GATTS_TABLE_TAG "GATTS_SPP_SERVER"
@ -561,6 +562,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:
gpio_set_level(GPIO_OUTPUT_IO_GREEN, 1);
g_bluetooth_processer->table_conn_id_m = param->connect.conn_id;
g_bluetooth_processer->table_gatts_if_m = gatts_if;
g_bluetooth_processer->table_handle_m = spp_handle_table[SPP_IDX_SPP_DATA_NTY_VAL];
@ -574,6 +576,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
#endif
break;
case ESP_GATTS_DISCONNECT_EVT:
gpio_set_level(GPIO_OUTPUT_IO_GREEN, 0);
g_bluetooth_processer->table_conn_id_m = 0;
g_bluetooth_processer->table_gatts_if_m = 0;
g_bluetooth_processer->table_handle_m = 0;

19
main/main.c

@ -1,4 +1,3 @@
#include "driver/gpio.h"
#include "esp_gatts_api.h"
#include "esp_log.h"
#include "esp_system.h"
@ -12,18 +11,13 @@
#include "ble_uart.h"
#include "motor_drive.h"
#include "timer_u.h"
#include "rgb_led.h"
#define MAIN_TAG "MAIN"
static char bluetooth_tx_buffer[profile_b_buffer_size] = {0};
static char bluetooth_rx_buffer[profile_b_buffer_size] = {0};
#define GPIO_OUTPUT_IO_RED 3
#define GPIO_OUTPUT_IO_GREEN 4
#define GPIO_OUTPUT_IO_BLUE 5
#define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_GREEN) | (1ULL << GPIO_OUTPUT_IO_BLUE) | (1ULL << GPIO_OUTPUT_IO_RED))
bluetooth_processer_t s_bluetooth_processer = {
.bluetooth_processer_rx_buf = bluetooth_rx_buffer,
.bluetooth_processer_rx_buf_size = sizeof(bluetooth_rx_buffer),
@ -55,17 +49,7 @@ bluetooth_processer_t s_bluetooth_processer = {
.motor_drive_turn_flag = false,
};
void gpio_rgb_init() {
gpio_config_t gpio_grb_led_structer;
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
gpio_grb_led_structer.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
gpio_grb_led_structer.pull_down_en = 0;
gpio_grb_led_structer.pull_up_en = 0;
gpio_config(&gpio_grb_led_structer);
}
void app_main(void) {
constructor_bluetooth_processer(&s_bluetooth_processer);
@ -74,7 +58,6 @@ void app_main(void) {
motor_drive_uart_init();
gpio_rgb_init();
gpio_set_level(GPIO_OUTPUT_IO_GREEN,1);
while (true) {
bluetooth_gatts_try_process_data();
// if (s_bluetooth_processer.auto_report_flag) {

1
main/motor_drive.c

@ -153,6 +153,7 @@ uint8_t motor_drive_set_packages_ctr(double position, int direction) {
return 0;
}
// Notice the strbuffer size
void motor_drive_hex_to_str(const char *hex, int hex_len, char *str) {
int i, pos = 0;
ESP_LOGI(MOTOR_DRIVE, "0X%X", hex[0]);

13
main/rgb_led.c

@ -0,0 +1,13 @@
#include "rgb_led.h"
void gpio_rgb_init() {
gpio_config_t gpio_grb_led_structer;
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
gpio_grb_led_structer.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
gpio_grb_led_structer.pull_down_en = 0;
gpio_grb_led_structer.pull_up_en = 0;
gpio_config(&gpio_grb_led_structer);
}

10
main/rgb_led.h

@ -0,0 +1,10 @@
#include "driver/gpio.h"
#define GPIO_OUTPUT_IO_RED 3
#define GPIO_OUTPUT_IO_GREEN 4
#define GPIO_OUTPUT_IO_BLUE 5
#define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_GREEN) | (1ULL << GPIO_OUTPUT_IO_BLUE) | (1ULL << GPIO_OUTPUT_IO_RED))
void gpio_rgb_init();
Loading…
Cancel
Save