2022-10-20 17:13:02 +08:00
|
|
|
/**
|
2022-11-01 22:32:15 +08:00
|
|
|
* @file remote_control.h
|
|
|
|
* @author DJI 2016
|
|
|
|
* @author modified by neozng
|
|
|
|
* @brief 遥控器模块定义头文件
|
|
|
|
* @version beta
|
|
|
|
* @date 2022-11-01
|
2022-11-05 21:59:03 +08:00
|
|
|
*
|
2022-11-01 22:32:15 +08:00
|
|
|
* @copyright Copyright (c) 2016 DJI corp
|
|
|
|
* @copyright Copyright (c) 2022 HNU YueLu EC all rights reserved
|
2022-11-05 21:59:03 +08:00
|
|
|
*
|
2022-11-01 22:32:15 +08:00
|
|
|
*/
|
2022-10-20 17:13:02 +08:00
|
|
|
#ifndef REMOTE_CONTROL_H
|
|
|
|
#define REMOTE_CONTROL_H
|
|
|
|
|
2022-12-12 22:29:51 +08:00
|
|
|
#include <stdint.h>
|
2022-10-20 17:13:02 +08:00
|
|
|
#include "main.h"
|
2022-12-03 15:20:17 +08:00
|
|
|
#include "usart.h"
|
2022-10-20 17:13:02 +08:00
|
|
|
|
2023-01-01 17:32:22 +08:00
|
|
|
// 用于遥控器数据读取,遥控器数据是一个大小为2的数组
|
2022-12-08 12:08:49 +08:00
|
|
|
#define LAST 1
|
|
|
|
#define TEMP 0
|
|
|
|
|
2022-12-05 21:01:26 +08:00
|
|
|
// 获取按键操作
|
|
|
|
#define KEY_PRESS 0
|
|
|
|
#define KEY_STATE 1
|
2023-03-27 22:03:35 +08:00
|
|
|
#define KEY_PRESS_WITH_CTRL 1
|
|
|
|
#define KEY_PRESS_WITH_SHIFT 2
|
2022-12-05 21:01:26 +08:00
|
|
|
|
2022-12-11 20:48:24 +08:00
|
|
|
// 检查接收值是否出错
|
2022-11-01 22:32:15 +08:00
|
|
|
#define RC_CH_VALUE_MIN ((uint16_t)364)
|
|
|
|
#define RC_CH_VALUE_OFFSET ((uint16_t)1024)
|
|
|
|
#define RC_CH_VALUE_MAX ((uint16_t)1684)
|
2022-12-05 21:01:26 +08:00
|
|
|
|
2022-10-20 17:13:02 +08:00
|
|
|
/* ----------------------- RC Switch Definition----------------------------- */
|
2023-01-01 17:32:22 +08:00
|
|
|
#define RC_SW_UP ((uint16_t)1) // 开关向上时的值
|
|
|
|
#define RC_SW_MID ((uint16_t)3) // 开关中间时的值
|
|
|
|
#define RC_SW_DOWN ((uint16_t)2) // 开关向下时的值
|
|
|
|
// 三个判断开关状态的宏
|
2022-11-01 22:32:15 +08:00
|
|
|
#define switch_is_down(s) (s == RC_SW_DOWN)
|
|
|
|
#define switch_is_mid(s) (s == RC_SW_MID)
|
|
|
|
#define switch_is_up(s) (s == RC_SW_UP)
|
2022-12-05 21:01:26 +08:00
|
|
|
|
2022-10-20 17:13:02 +08:00
|
|
|
/* ----------------------- PC Key Definition-------------------------------- */
|
2023-01-01 17:32:22 +08:00
|
|
|
// 对应key[x][0~16],获取对应的键;例如通过key[KEY_PRESS][Key_W]获取W键是否按下,后续改为位域后删除
|
2022-12-05 21:01:26 +08:00
|
|
|
#define Key_W 0
|
|
|
|
#define Key_S 1
|
|
|
|
#define Key_D 2
|
|
|
|
#define Key_A 3
|
|
|
|
#define Key_Shift 4
|
|
|
|
#define Key_Ctrl 5
|
|
|
|
#define Key_Q 6
|
|
|
|
#define Key_E 7
|
|
|
|
#define Key_R 8
|
|
|
|
#define Key_F 9
|
|
|
|
#define Key_G 10
|
|
|
|
#define Key_Z 11
|
|
|
|
#define Key_X 12
|
|
|
|
#define Key_C 13
|
|
|
|
#define Key_V 14
|
|
|
|
#define Key_B 15
|
|
|
|
|
2022-10-20 17:13:02 +08:00
|
|
|
/* ----------------------- Data Struct ------------------------------------- */
|
2022-12-05 21:01:26 +08:00
|
|
|
// 待测试的位域结构体,可以极大提升解析速度
|
2023-06-08 15:53:53 +08:00
|
|
|
typedef union
|
2022-12-05 21:01:26 +08:00
|
|
|
{
|
2023-06-08 15:53:53 +08:00
|
|
|
struct // 用于访问键盘状态
|
|
|
|
{
|
|
|
|
uint16_t w : 1;
|
|
|
|
uint16_t s : 1;
|
|
|
|
uint16_t d : 1;
|
|
|
|
uint16_t a : 1;
|
|
|
|
uint16_t shift : 1;
|
|
|
|
uint16_t ctrl : 1;
|
|
|
|
uint16_t q : 1;
|
|
|
|
uint16_t e : 1;
|
|
|
|
uint16_t r : 1;
|
|
|
|
uint16_t f : 1;
|
|
|
|
uint16_t g : 1;
|
|
|
|
uint16_t z : 1;
|
|
|
|
uint16_t x : 1;
|
|
|
|
uint16_t c : 1;
|
|
|
|
uint16_t v : 1;
|
|
|
|
uint16_t b : 1;
|
|
|
|
};
|
|
|
|
uint16_t keys; // 用于memcpy而不需要进行强制类型转换
|
2022-12-05 21:01:26 +08:00
|
|
|
} Key_t;
|
|
|
|
|
2023-06-08 15:53:53 +08:00
|
|
|
// @todo 当前结构体嵌套过深,需要进行优化
|
2022-12-06 22:58:42 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2022-12-11 20:48:24 +08:00
|
|
|
int16_t rocker_l_; // 左水平
|
|
|
|
int16_t rocker_l1; // 左竖直
|
|
|
|
int16_t rocker_r_; // 右水平
|
|
|
|
int16_t rocker_r1; // 右竖直
|
|
|
|
int16_t dial; // 侧边拨轮
|
|
|
|
|
|
|
|
uint8_t switch_left; // 左侧开关
|
|
|
|
uint8_t switch_right; // 右侧开关
|
2022-12-07 21:56:34 +08:00
|
|
|
} rc;
|
2022-12-06 22:58:42 +08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
uint8_t press_l;
|
|
|
|
uint8_t press_r;
|
|
|
|
} mouse;
|
2023-06-08 15:53:53 +08:00
|
|
|
|
|
|
|
Key_t key[3]; // 改为位域后的键盘索引,空间减少8倍,速度增加16~倍
|
2022-12-06 22:58:42 +08:00
|
|
|
|
2023-03-27 22:03:35 +08:00
|
|
|
uint8_t key_count[3][16];
|
2022-12-06 22:58:42 +08:00
|
|
|
} RC_ctrl_t;
|
|
|
|
|
2022-11-01 22:32:15 +08:00
|
|
|
/* ------------------------- Internal Data ----------------------------------- */
|
2022-10-20 17:13:02 +08:00
|
|
|
|
|
|
|
/**
|
2022-11-01 22:32:15 +08:00
|
|
|
* @brief 初始化遥控器,该函数会将遥控器注册到串口
|
|
|
|
*
|
|
|
|
* @attention 注意分配正确的串口硬件,遥控器在C板上使用USART3
|
|
|
|
*
|
2022-10-20 17:13:02 +08:00
|
|
|
*/
|
2022-12-05 21:01:26 +08:00
|
|
|
RC_ctrl_t *RemoteControlInit(UART_HandleTypeDef *rc_usart_handle);
|
2022-10-20 17:13:02 +08:00
|
|
|
|
2023-02-22 13:53:25 +08:00
|
|
|
/**
|
|
|
|
* @brief 检查遥控器是否在线,若尚未初始化也视为离线
|
2023-06-08 15:53:53 +08:00
|
|
|
*
|
2023-02-22 13:53:25 +08:00
|
|
|
* @return uint8_t 1:在线 0:离线
|
|
|
|
*/
|
|
|
|
uint8_t RemoteControlIsOnline();
|
|
|
|
|
2022-10-20 17:13:02 +08:00
|
|
|
#endif
|