|
|
@ -7,6 +7,7 @@ |
|
|
|
#define cmd_length_set_position 5 |
|
|
|
#define cmd_length_get_status 2 |
|
|
|
#define cmd_length_set_motor_current_size 2 |
|
|
|
#define cmd_length_set_motor_to_position 5 |
|
|
|
static double encoder_befor_num; |
|
|
|
|
|
|
|
static bluetooth_processer_t *parse_bluetooth_processer; |
|
|
@ -37,19 +38,17 @@ void bluetooth_gatts_try_process_data() { |
|
|
|
parse_bluetooth_processer->auto_report_flag = true; |
|
|
|
ESP_LOGI(BLE_PARSE_DATA_TAG, set_position); |
|
|
|
|
|
|
|
motor_drive_set_motor_to_angle(1,180,0); |
|
|
|
|
|
|
|
// encoder_befor_num = motor_drive_read_encoder(); |
|
|
|
// if (encoder_befor_num >= 0) { |
|
|
|
// if (motor_drive_set_packages_ctr(parse_bluetooth_processer->position, parse_bluetooth_processer->direction) == 0) { |
|
|
|
// ets_delay_us(50000); |
|
|
|
// if (encoder_befor_num == motor_drive_read_encoder()) { |
|
|
|
// ESP_LOGW(BLE_PARSE_DATA_TAG, "motor no turning"); |
|
|
|
// } else { |
|
|
|
// ESP_LOGI(BLE_PARSE_DATA_TAG, "motor turning"); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
encoder_befor_num = motor_drive_read_encoder(); |
|
|
|
if (encoder_befor_num >= 0) { |
|
|
|
if (motor_drive_set_packages_ctr(parse_bluetooth_processer->position, parse_bluetooth_processer->direction) == 0) { |
|
|
|
ets_delay_us(50000); |
|
|
|
if (encoder_befor_num == motor_drive_read_encoder()) { |
|
|
|
ESP_LOGW(BLE_PARSE_DATA_TAG, "motor no turning"); |
|
|
|
} else { |
|
|
|
ESP_LOGI(BLE_PARSE_DATA_TAG, "motor turning"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// receipt_json_set_position(); |
|
|
|
} |
|
|
@ -62,6 +61,12 @@ void bluetooth_gatts_try_process_data() { |
|
|
|
motor_drive_set_motor_current_size(); |
|
|
|
// receipt_json_get_status(); |
|
|
|
} |
|
|
|
if (strcmp(parse_bluetooth_processer->order, set_motor_to_position) == 0) { |
|
|
|
ESP_LOGI(BLE_PARSE_DATA_TAG, set_motor_to_position); |
|
|
|
motor_drive_set_motor_to_angle(parse_bluetooth_processer->direction, parse_bluetooth_processer->position, // |
|
|
|
parse_bluetooth_processer->speedLevel); |
|
|
|
// receipt_json_get_status(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -121,6 +126,9 @@ bool parse_json_to_struct(cJSON *ch) { |
|
|
|
if (strcmp(ch->valuestring, set_motor_current_size) == 0) { |
|
|
|
cmd_length = cmd_length_set_motor_current_size; |
|
|
|
} |
|
|
|
if (strcmp(ch->valuestring, set_motor_to_position) == 0) { |
|
|
|
cmd_length = cmd_length_set_motor_to_position; |
|
|
|
} |
|
|
|
|
|
|
|
cmd_length--; |
|
|
|
} |
|
|
|