Browse Source

update

master
zwsd 3 years ago
parent
commit
a5cf2c7559
  1. 18
      main/main.c
  2. 2
      main/motor_drive.h

18
main/main.c

@ -58,10 +58,18 @@ void construct_set_position_packet_and_report(int index, uint8_t setPosition_cod
void construct_get_status_packet_and_report(int index, double motor_position) {
uint8_t buffer[construct_cmd_packet_buffer_size] = {0};
snprintf((char *)buffer, construct_cmd_packet_buffer_size,
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": "
", \"position\":%lf }",
index, motor_position);
if (motor_turning == false) {
snprintf((char *)buffer, construct_cmd_packet_buffer_size,
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"%s\", \"deviceException\": 0, \"deviceExceptionInfo\": "
", \"position\":%lf }",
index, "idel", motor_position);
} else {
snprintf((char *)buffer, construct_cmd_packet_buffer_size,
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"%s\", \"deviceException\": 0, \"deviceExceptionInfo\": "
", \"position\":%lf }",
index, "rotating", motor_position);
}
ESP_LOGI(MAIN_LOG_TAG, "report %s", buffer);
bleuart_notify_send(buffer, strlen((char *)buffer));
}
@ -96,6 +104,7 @@ void process_setPosition(RxContext_t *context, cJSON *rxjson) {
}
ESP_LOGI(MAIN_LOG_TAG, "index = %d,speedLevel = %d,position = %lf,direction = %d", index, speedLevel, position, direction);
setPosition_code = motor_run_to_postion(1, position, 0);
motor_turning = true;
construct_set_position_packet_and_report(index, setPosition_code);
}
@ -157,6 +166,7 @@ void motor_on_event(motor_event_t event) {
//使sprintf
if (event == kRunToPosition) {
ESP_LOGI(MAIN_LOG_TAG, "motor_on_event: kRunToPosition");
motor_turning = false;
uint8_t buffer[construct_cmd_packet_buffer_size] = {0};
double motor_stop_position = motor_get_position_degree();

2
main/motor_drive.h

@ -11,6 +11,8 @@ typedef enum {
} motor_event_t;
typedef void (*motor_on_event_t)(motor_event_t event);
bool motor_turning;
void motor_init(motor_t* motor);
void motor_set_zero_point();
double motor_get_position_degree();

Loading…
Cancel
Save