sentry_chassis_hzz/modules/remote/remote_control.h

121 lines
2.7 KiB
C
Raw Normal View History

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-01 22:32:15 +08:00
* @copyright Copyright (c) 2016 DJI corp
* @copyright Copyright (c) 2022 HNU YueLu EC all rights reserved
*
2022-11-01 22:32:15 +08:00
*/
2022-10-20 17:13:02 +08:00
#ifndef REMOTE_CONTROL_H
#define REMOTE_CONTROL_H
#include <stdint-gcc.h>
2022-10-20 17:13:02 +08:00
#include "main.h"
#include "usart.h"
2022-10-20 17:13:02 +08:00
//
#define LAST 1
#define TEMP 0
// 获取按键操作
#define KEY_PRESS 0
#define KEY_STATE 1
#define KEY_PRESS_WITH_CTRL 2
#define KEY_PRESS_WITH_SHIFT 3
// 检查接受值是否出错
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-10-20 17:13:02 +08:00
/* ----------------------- RC Switch Definition----------------------------- */
2022-11-01 22:32:15 +08:00
#define RC_SW_UP ((uint16_t)1)
#define RC_SW_MID ((uint16_t)3)
#define RC_SW_DOWN ((uint16_t)2)
#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)
#define LEFT_SW 1
#define RIGHT_SW 0
2022-10-20 17:13:02 +08:00
/* ----------------------- PC Key Definition-------------------------------- */
// 对应key[x][0~16],获取对应的键;例如通过key[KEY_PRESS][Key_W]获取W键是否按下
#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 ------------------------------------- */
// 待测试的位域结构体,可以极大提升解析速度
typedef 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;
} Key_t;
typedef struct
{
struct
{
2022-12-07 21:56:34 +08:00
int16_t joystick[5]; // 右|0 ,右-1 ,左-2 ,左|3 ,拨轮4
uint8_t s[2]; //[0]:left [1]:right
2022-12-07 21:56:34 +08:00
} rc;
struct
{
int16_t x;
int16_t y;
int16_t z;
uint8_t press_l;
uint8_t press_r;
} mouse;
uint16_t key_temp;
uint8_t key[4][16]; // 当前使用的键盘索引
Key_t key_test[4]; // 改为位域后的键盘索引,空间减少8倍,速度增加16~倍
} 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
*/
RC_ctrl_t *RemoteControlInit(UART_HandleTypeDef *rc_usart_handle);
2022-10-20 17:13:02 +08:00
#endif