Browse Source

update

master
zwsd 3 years ago
parent
commit
690d6df6e4
  1. 2
      main/ble_spp_server_demo.c
  2. 3
      main/ble_spp_server_demo.h
  3. 23
      main/main.c

2
main/ble_spp_server_demo.c

@ -638,7 +638,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_
void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; } void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; }
void ble_spp_server_demo_app_main(bleuart_t *bleuart) {
void bleuart_init(bleuart_t *bleuart) {
esp_err_t ret; esp_err_t ret;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();

3
main/ble_spp_server_demo.h

@ -80,7 +80,8 @@ typedef struct {
/*接收完整JSON*/ /*接收完整JSON*/
typedef void (*blerxcb_t)(uint8_t *rx, size_t rxsize); typedef void (*blerxcb_t)(uint8_t *rx, size_t rxsize);
void ble_spp_server_demo_app_main(bleuart_t *bleuart);
void bleuart_init(bleuart_t *bleuart);
void bleuart_reg_cb(blerxcb_t cb); void bleuart_reg_cb(blerxcb_t cb);
void bleuart_send_packet(uint8_t *tx, size_t txsize); void bleuart_send_packet(uint8_t *tx, size_t txsize);

23
main/main.c

@ -30,13 +30,8 @@ bleuart_t ble_uart_init_struct = {
.bleName = "yimei_ble", .bleName = "yimei_ble",
}; };
motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1};
void processrxjson(cJSON *rxjson) {
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) {
return;
}
const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order"));
if (strcmp(order, "setPosition") == 0) {
void process_setPosition(cJSON *rxjson) {
// { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } // { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 }
int index = 0; int index = 0;
int speedLevel = 0; int speedLevel = 0;
@ -56,9 +51,18 @@ void processrxjson(cJSON *rxjson) {
direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction"));
} }
motor_run_to_postion(1, position, index); motor_run_to_postion(1, position, index);
//
} else if (strcmp(order, "getStatus") == 0) {
}
void processrxjson(cJSON *rxjson) {
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) {
return;
}
const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order"));
if (strcmp(order, "setPosition") == 0) {
process_setPosition(rxjson);
} else if (strcmp(order, "getStatus") == 0) {
} }
} }
@ -82,8 +86,9 @@ void motor_on_event(motor_event_t event) {
} }
void app_main(void) { void app_main(void) {
ble_spp_server_demo_app_main(&ble_uart_init_struct);
bleuart_init(&ble_uart_init_struct);
bleuart_reg_cb(blerxcb); bleuart_reg_cb(blerxcb);
motor_init(&ble_uart_motor_structer); motor_init(&ble_uart_motor_structer);
motor_reg_event_cb(motor_on_event); motor_reg_event_cb(motor_on_event);

Loading…
Cancel
Save