mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
增加了大量注释
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
#include "string.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "memory.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#define REMOTE_CONTROL_FRAME_SIZE 18u // 遥控器接收的buffer大小
|
||||
// 遥控器数据
|
||||
static RC_ctrl_t rc_ctrl[2]; //[0]:当前数据,[1]:上一次的数据.用于按键判断
|
||||
// 遥控器拥有的串口实例
|
||||
static RC_ctrl_t rc_ctrl[2]; //[0]:当前数据TEMP,[1]:上一次的数据LAST.用于按键持续按下和切换的判断
|
||||
// 遥控器拥有的串口实例,因为遥控器是单例,所以这里只有一个,就不封装了
|
||||
static USARTInstance *rc_usart_instance;
|
||||
|
||||
/**
|
||||
@@ -17,8 +18,8 @@ static void RectifyRCjoystick()
|
||||
{
|
||||
for (uint8_t i = 0; i < 5; ++i)
|
||||
{
|
||||
if (*(&rc_ctrl[TEMP].rc.rocker_l_+i) > 660 || *(&rc_ctrl[TEMP].rc.rocker_l_+i) < -660)
|
||||
*(&rc_ctrl[TEMP].rc.rocker_l_+i) = 0;
|
||||
if (abs(*(&rc_ctrl[TEMP].rc.rocker_l_ + i)) > 660)
|
||||
*(&rc_ctrl[TEMP].rc.rocker_l_ + i) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +29,7 @@ static void RectifyRCjoystick()
|
||||
* @param[out] rc_ctrl: remote control data struct point
|
||||
* @retval none
|
||||
*/
|
||||
static void sbus_to_rc(volatile const uint8_t *sbus_buf)
|
||||
static void sbus_to_rc(const uint8_t *sbus_buf)
|
||||
{
|
||||
memcpy(&rc_ctrl[1], &rc_ctrl[TEMP], sizeof(RC_ctrl_t)); // 保存上一次的数据
|
||||
// 摇杆,直接解算时减去偏置
|
||||
@@ -68,7 +69,7 @@ static void sbus_to_rc(volatile const uint8_t *sbus_buf)
|
||||
rc_ctrl[TEMP].key[KEY_PRESS_WITH_CTRL][j] = rc_ctrl[TEMP].key_temp & i;
|
||||
}
|
||||
|
||||
// 位域的按键值解算,直接memcpy即可,注意小端低字节在前,即lsb在第一位
|
||||
// 位域的按键值解算,直接memcpy即可,注意小端低字节在前,即lsb在第一位,msb在最后. 尚未测试
|
||||
// *(uint16_t *)&rc_ctrl[TEMP].key_test[KEY_PRESS] = (uint16_t)(sbus_buf[14] | (sbus_buf[15] << 8));
|
||||
// *(uint16_t *)&rc_ctrl[TEMP].key_test[KEY_STATE] = *(uint16_t *)&rc_ctrl[TEMP].key_test[KEY_PRESS] & ~(*(uint16_t *)&(rc_ctrl[1].key_test[KEY_PRESS]));
|
||||
// if (rc_ctrl[TEMP].key_test[KEY_PRESS].ctrl)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "main.h"
|
||||
#include "usart.h"
|
||||
|
||||
//
|
||||
// 用于遥控器数据读取,遥控器数据是一个大小为2的数组
|
||||
#define LAST 1
|
||||
#define TEMP 0
|
||||
|
||||
@@ -33,17 +33,18 @@
|
||||
#define RC_CH_VALUE_MAX ((uint16_t)1684)
|
||||
|
||||
/* ----------------------- RC Switch Definition----------------------------- */
|
||||
#define RC_SW_UP ((uint16_t)1)
|
||||
#define RC_SW_MID ((uint16_t)3)
|
||||
#define RC_SW_DOWN ((uint16_t)2)
|
||||
#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
|
||||
#define LEFT_SW 1 // 左侧开关
|
||||
#define RIGHT_SW 0 // 右侧开关
|
||||
|
||||
/* ----------------------- PC Key Definition-------------------------------- */
|
||||
// 对应key[x][0~16],获取对应的键;例如通过key[KEY_PRESS][Key_W]获取W键是否按下
|
||||
// 对应key[x][0~16],获取对应的键;例如通过key[KEY_PRESS][Key_W]获取W键是否按下,后续改为位域后删除
|
||||
#define Key_W 0
|
||||
#define Key_S 1
|
||||
#define Key_D 2
|
||||
|
||||
Reference in New Issue
Block a user