Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
bbtq committed Oct 16, 2023
1 parent 31e4036 commit 8b177b1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions drivers/jy901.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ int32_t WitReadReg(jy901_handle_t *handle, uint32_t uiReg, uint32_t uiReadNum)
return WIT_HAL_OK;
}

/**
* @brief 初始化函数执行
* @param handle jy901_handle_t结构体参数
* @return WIT_HAL_OK:成功(0) WIT_HAL_ERROR:失败(-3)
*/
int32_t WitInit(jy901_handle_t *handle)
{
if (handle->SerialInit() != 0)
Expand Down
16 changes: 16 additions & 0 deletions user/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include "control.h"

/**
* @brief RPC服务端线程(推进器控制线程)
* @param arg 输入推进器控制信息,输入类型为void * (rov_info_t *)
* @return NULL
*/
void *control_thread(void *arg)
{
rov_info_t *info = (rov_info_t *)arg;
Expand All @@ -31,6 +36,11 @@ void *control_thread(void *arg)
return NULL;
}

/**
* @brief 启动推进器控制线程
* @param info rov_info结构体参数
* @return 0 :成功 -1:失败
*/
int rov_control_run(struct rov_info* info)
{
if (pthread_mutex_init(&info->thread.mutex.cal_rocket_output, NULL) != 0)
Expand All @@ -48,11 +58,17 @@ int rov_control_run(struct rov_info* info)
return 0;
}

/**
* @brief 取消推进器控制线程
* @param info rov_info结构体参数
* @return 0:成功 -1:失败
*/
int rov_control_stop(struct rov_info* info)
{
if (pthread_cancel(info->thread.tid.control) != 0)
{
log_e("cancel thread failed");
return -1;
}
if (pthread_mutex_destroy(&info->thread.mutex.cal_rocket_output) != 0)
{
Expand Down
14 changes: 14 additions & 0 deletions user/device/application/motion_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

static jy901_handle_t jy901_handle = {0};

/**
* @brief jy901串口初始化
* @return 0:成功 -1:失败
*/
int motion_sensor_init ()
{
jy901_handle.SerialInit = jy901_interface_uart_init;
Expand All @@ -20,12 +24,22 @@ int motion_sensor_init ()
return 0;
}

/**
* @brief 按照协议,处理接收数据
* @param byte 接收数据
* @return 0:成功
*/
int motion_sensor_uart_data_in (uint8_t byte)
{
WitSerialDataIn(&jy901_handle, byte);
return 0;
}

/**
* @brief 获取jy901处理后的坐标参数
* @param data sensor_t结构体参数
* @return 0:成功
*/
int motion_sensor_get_data (sensor_t *data)
{
data->yaw = jy901_handle.fAngle[2]; //z
Expand Down
31 changes: 20 additions & 11 deletions user/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
function(back_left) \
function(back_right)

/**
* @brief 推进器控制数据写入
* @param param propeller_t 结构体参数
*/
static void write_to_propeller(propeller_t *param)
{
#define PWM_COTROLLER_WRITE(propeller) \
Expand All @@ -34,6 +38,11 @@ static void write_to_propeller(propeller_t *param)
#undef PWM_COTROLLER_WRITE
}

/**
* @brief 推进器线程
* @param arg 控制参数信息,void * (rov_info_t)
* @return NULL
*/
void *propeller_thread(void *arg)
{
rov_info_t *info = (rov_info_t *)arg;
Expand All @@ -52,17 +61,11 @@ void *propeller_thread(void *arg)
return NULL;
}

// void *device_thread(void *arg)
// {
// rov_info_t *info = (rov_info_t *)arg;

// for (;;)
// {
// }

// return NULL;
// }

/**
* @brief 推进器启动
* @param info rov_info结构体参数
* @return 0:成功 -1:失败
*/
int rov_device_run(struct rov_info* info)
{
log_i("starting pwm controller");
Expand Down Expand Up @@ -94,6 +97,11 @@ int rov_device_run(struct rov_info* info)
return 0;
}

/**
* @brief 取消推进器控制
* @param info rov_info结构体参数
* @return 0:成功 -1:失败
*/
int rov_device_stop(struct rov_info* info)
{
if (pwm_controller_deinit() < -1)
Expand All @@ -104,6 +112,7 @@ int rov_device_stop(struct rov_info* info)
if (pthread_mutex_destroy(&info->thread.mutex.write_propeller) != 0)
{
log_e("propeller mutex destroy failed");
return -1;
}
return 0;
}

0 comments on commit 8b177b1

Please sign in to comment.