diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 7a8b1d0..031d18e 100644 --- a/main/CMakeLists.txt +++ b/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/" ".") diff --git a/main/ble_spp_server_demo.c b/main/ble_spp_server_demo.c index 84191cd..ab49f5e 100644 --- a/main/ble_spp_server_demo.c +++ b/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; diff --git a/main/main.c b/main/main.c index 22d1026..763fad8 100644 --- a/main/main.c +++ b/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) { diff --git a/main/motor_drive.c b/main/motor_drive.c index 20bf418..b73e8eb 100644 --- a/main/motor_drive.c +++ b/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]); diff --git a/main/rgb_led.c b/main/rgb_led.c new file mode 100644 index 0000000..4d76978 --- /dev/null +++ b/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); +} \ No newline at end of file diff --git a/main/rgb_led.h b/main/rgb_led.h new file mode 100644 index 0000000..d0d563b --- /dev/null +++ b/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(); \ No newline at end of file