61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
/*
|
||
rc Task
|
||
遥控器控制
|
||
*/
|
||
|
||
/* Includes ----------------------------------------------------------------- */
|
||
#include "task/user_task.h"
|
||
/* USER INCLUDE BEGIN*/
|
||
#include "bsp/buzzer.h"
|
||
#include "bsp/gpio.h"
|
||
#include "device/dr16.h"
|
||
#include "component/cmd.h"
|
||
/* USER INCLUDE END*/
|
||
|
||
/* Private typedef ---------------------------------------------------------- */
|
||
/* Private define ----------------------------------------------------------- */
|
||
/* Private macro ------------------------------------------------------------ */
|
||
/* Private variables -------------------------------------------------------- */
|
||
/* USER STRUCT BEGIN*/
|
||
DR16_t dr16;
|
||
CMD_RC_t cmd_rc;
|
||
/* USER STRUCT END*/
|
||
|
||
/* Private function --------------------------------------------------------- */
|
||
/* Exported functions ------------------------------------------------------- */
|
||
void Task_rc(void *argument) {
|
||
(void)argument; /* 未使用argument,消除警告 */
|
||
|
||
|
||
osDelay(RC_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||
|
||
/* USER CODE INIT BEGIN*/
|
||
DR16_Init(&dr16); /* 初始化DR16接收机 */
|
||
BSP_Buzzer_Set(300.0f, 0.2f); /* 启动蜂鸣器,频率1kHz,50%占空比 */
|
||
/* USER CODE INIT END*/
|
||
|
||
while (1) {
|
||
/* USER CODE BEGIN */
|
||
DR16_StartDmaRecv(&dr16);
|
||
if (DR16_WaitDmaCplt(20)) {
|
||
DR16_ParseData(&dr16);
|
||
|
||
// BSP_Buzzer_Start(); /* 启动蜂鸣器 */
|
||
BSP_GPIO_SetPin(BSP_GPIO_24V_EN1, BSP_GPIO_ON); /* 打开24V电源1 */
|
||
BSP_GPIO_SetPin(BSP_GPIO_24V_EN2, BSP_GPIO_ON); /* 打开24V电源2 */
|
||
} else {
|
||
DR16_HandleOffline(&dr16);
|
||
|
||
// BSP_Buzzer_Stop(); /* 停止蜂鸣器 */
|
||
BSP_GPIO_SetPin(BSP_GPIO_24V_EN1, BSP_GPIO_OFF); /* 关闭24V电源1 */
|
||
BSP_GPIO_SetPin(BSP_GPIO_24V_EN2, BSP_GPIO_OFF); /* 关闭24V电源2 */
|
||
}
|
||
DR16_ParseRC(&dr16, &cmd_rc); /* 解析遥控器数据 */
|
||
/* 将遥控器数据放入消息队列 */
|
||
osMessageQueueReset(task_runtime.msgq.cmd.raw.rc); /* 重置消息队列 */
|
||
osMessageQueuePut(task_runtime.msgq.cmd.raw.rc, &cmd_rc, 0, 0);
|
||
|
||
/* USER CODE END */
|
||
}
|
||
|
||
} |