You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "driver/gpio.h"
  2. #include "esp_gatts_api.h"
  3. #include "esp_log.h"
  4. #include "esp_system.h"
  5. #include "freertos/FreeRTOS.h"
  6. #include "freertos/event_groups.h"
  7. #include "freertos/task.h"
  8. #include "nvs_flash.h"
  9. #include "string.h"
  10. //
  11. #include "ble_spp_server_demo.h"
  12. #include "ble_uart.h"
  13. #include "motor_drive.h"
  14. #include "timer_u.h"
  15. #define MAIN_TAG "MAIN"
  16. static char bluetooth_tx_buffer[profile_b_buffer_size] = {0};
  17. static char bluetooth_rx_buffer[profile_b_buffer_size] = {0};
  18. #define GPIO_OUTPUT_IO_RED 3
  19. #define GPIO_OUTPUT_IO_GREEN 4
  20. #define GPIO_OUTPUT_IO_BLUE 5
  21. #define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_GREEN) | (1ULL << GPIO_OUTPUT_IO_BLUE) | (1ULL << GPIO_OUTPUT_IO_RED))
  22. bluetooth_processer_t s_bluetooth_processer = {
  23. .bluetooth_processer_rx_buf = bluetooth_rx_buffer,
  24. .bluetooth_processer_rx_buf_size = sizeof(bluetooth_rx_buffer),
  25. .bluetooth_processer_tx_buf = bluetooth_tx_buffer,
  26. .bluetooth_processer_tx_buf_size = sizeof(bluetooth_tx_buffer),
  27. .bluetooth_baundrate_one_packet_delay_ms = kbluetooth_baundrate_one_packet_delay_ms,
  28. .port_delay_ms = port_timer_delay_ms,
  29. .bluetooth_rx_buffer_start_receving = false,
  30. .bluetooth_rx_buffer_processing = false,
  31. .order = "order",
  32. .index = 0,
  33. .speedLevel = 0,
  34. .position = 0.0,
  35. .direction = 0,
  36. .code = 0,
  37. .info = "noerror",
  38. .deviceState = "init",
  39. .deviceException = 0,
  40. .deviceExceptionInfo = "noexception",
  41. .table_conn_id_m = 0,
  42. .table_gatts_if_m = 0,
  43. .table_handle_m = 0,
  44. .cmd_flag = false,
  45. .auto_report_flag = false,
  46. .motor_drive_turn_flag = false,
  47. };
  48. void gpio_rgb_init() {
  49. gpio_config_t gpio_grb_led_structer;
  50. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  51. gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
  52. gpio_grb_led_structer.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
  53. gpio_grb_led_structer.pull_down_en = 0;
  54. gpio_grb_led_structer.pull_up_en = 0;
  55. gpio_config(&gpio_grb_led_structer);
  56. }
  57. void app_main(void) {
  58. constructor_bluetooth_processer(&s_bluetooth_processer);
  59. ble_spp_server_demo_app_main(&s_bluetooth_processer);
  60. timer_group_init(TIMER_GROUP_0, TIMER_0, false, timer_group0_interval_num, timer_interval_ms);
  61. motor_drive_uart_init();
  62. gpio_rgb_init();
  63. gpio_set_level(GPIO_OUTPUT_IO_GREEN,1);
  64. while (true) {
  65. bluetooth_gatts_try_process_data();
  66. // if (s_bluetooth_processer.auto_report_flag) {
  67. // receipt_json_get_status();
  68. // encoder = motor_drive_read_encoder();
  69. // ESP_LOGI(MAIN_TAG, "encoder :%.2lf", encoder);
  70. // s_bluetooth_processer.auto_report_flag = false;
  71. // }
  72. // motor_drive_set_motor_to_angle(0,35.32,5);
  73. }
  74. return;
  75. }