Browse Source

setPosition

master
zwsd 3 years ago
parent
commit
338a4ec12d
  1. 24
      main/gatts_demo.c
  2. 45
      main/motor_drive.c
  3. 7
      main/motor_drive.h

24
main/gatts_demo.c

@ -241,6 +241,9 @@ uint32_t total = 0;
#define cmd_length_get_status 2
// #define cmd_length_device_status_report 6
#define set_position "setPosition"
#define get_status "getStatus"
/***********************************************************************************************************************
* **********************************************user_function_statement********************************************** *
***********************************************************************************************************************/
@ -943,14 +946,17 @@ void bluetooth_gatts_try_process_data()
// JSON解析到结构体order更改表示有指令传输进来(cmd_flag)true
if (parse_json_to_struct(json_tmp->child))
{
ESP_LOGI(GATTS_TAG, "order:%s ,index:%d speedLevel:%d position:%f direction:%d", s_bluetooth_processer.order, s_bluetooth_processer.index, s_bluetooth_processer.speed_level, s_bluetooth_processer.position, s_bluetooth_processer.direction);
if (strcmp(s_bluetooth_processer.order, "setPosition") == 0)
ESP_LOGI(GATTS_TAG, "order:%s ,index:%d speedLevel:%d position:%f direction:%d",
s_bluetooth_processer.order, s_bluetooth_processer.index, s_bluetooth_processer.speed_level,
s_bluetooth_processer.position, s_bluetooth_processer.direction);
if (strcmp(s_bluetooth_processer.order, set_position) == 0)
{
ESP_LOGI(GATTS_TAG, "setPosition");
ESP_LOGI(GATTS_TAG, set_position);
// motor_cmd_set_position(s_bluetooth_processer.speed_level, s_bluetooth_processer.position, s_bluetooth_processer.direction);
}
if (strcmp(s_bluetooth_processer.order, "getStatus") == 0)
if (strcmp(s_bluetooth_processer.order, get_status) == 0)
{
ESP_LOGI(GATTS_TAG, "getStatus");
ESP_LOGI(GATTS_TAG, get_status);
}
// if (strcmp(s_bluetooth_processer.order, "deviceStatusReport") == 0)
// {
@ -1025,11 +1031,11 @@ bool parse_json_to_struct(cJSON *ch)
{
s_bluetooth_processer.order = ch->valuestring;
if (strcmp(ch->valuestring, "setPosition") == 0)
if (strcmp(ch->valuestring, set_position) == 0)
{
cmd_length = cmd_length_set_position;
}
if (strcmp(ch->valuestring, "getStatus") == 0)
if (strcmp(ch->valuestring, get_status) == 0)
{
cmd_length = cmd_length_get_status;
}
@ -1065,7 +1071,9 @@ bool parse_json_to_struct(cJSON *ch)
if (cmd_length == 0)
{
s_bluetooth_processer.cmd_flag = true;
}else{
}
else
{
ESP_LOGE(GATTS_TAG, "JSON directive missing or exceeded");
}

45
main/motor_drive.c

@ -1,2 +1,47 @@
#include "motor_drive.h"
bool motor_cmd_set_position(int speed_level, double position, int direction)
{
int last_direction = direction;
if (!motor_validation_set_position_parameters(speed_level, position, direction))
{
return false;
}
if (direction == 0)
{
last_direction = motor_find_short_path_direction(position);
}
motor_set_position(speed_level, position, last_direction);
return true;
}
void motor_set_position(int speed_level, double position, int direction)
{
}
bool motor_validation_set_position_parameters(int speed_level, double position, int direction)
{
return true;
}
int motor_find_short_path_direction(double position)
{
double encoder_position = 0.0;
encoder_position = motor_read_encoder();
if (encoder_position > position)
{
return 2;
}
else
{
return 1;
}
return;
}
double motor_read_encoder()
{
return 0.0;
}

7
main/motor_drive.h

@ -0,0 +1,7 @@
#include "stdbool.h"
void motor_set_position(int speed_level, double position, int direction);
bool motor_cmd_set_position(int speed_level, double position, int direction);
bool motor_validation_set_position_parameters(int speed_level, double position, int direction);
int motor_find_short_path_direction(double position);
double motor_read_encoder();
Loading…
Cancel
Save