Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
******************************************************************************
* @file Remote_Control.c
* @author DJI
* @version V1.0.0
* @date 2015/11/15
* @brief
******************************************************************************
* @attention
*
******************************************************************************
*/
#include "Remote_Control.h"
#define LED2_Pin GPIO_PIN_7
#define LED2_GPIO_Port GPIOE
RC_Type remote_control;
uint32_t Latest_Remote_Control_Pack_Time = 0;
uint32_t LED_Flash_Timer_remote_control = 0;
/*******************************************************************************************
* @Func void Callback_RC_Handle(RC_Type* rc, uint8_t* buff)
* @Brief DR16接收机协议解码程序
* @Param RC_Type* rc 存储遥控器数据的结构体 uint8_t* buff 用于解码的缓存
* @Retval None
* @Date
*******************************************************************************************/
void Callback_RC_Handle(RC_Type* rc, uint8_t* buff)
{
// rc->ch1 = (*buff | *(buff+1) << 8) & 0x07FF; offset = 1024
rc->ch1 = (buff[0] | buff[1]<<8) & 0x07FF;
rc->ch1 -= 1024;
rc->ch2 = (buff[1]>>3 | buff[2]<<5 ) & 0x07FF;
rc->ch2 -= 1024;
rc->ch3 = (buff[2]>>6 | buff[3]<<2 | buff[4]<<10) & 0x07FF;
rc->ch3 -= 1024;
rc->ch4 = (buff[4]>>1 | buff[5]<<7) & 0x07FF;
rc->ch4 -= 1024;
rc->switch_left = ( (buff[5] >> 4)& 0x000C ) >> 2;
rc->switch_right = (buff[5] >> 4)& 0x0003 ;
rc->mouse.x = buff[6] | (buff[7] << 8); //x axis
rc->mouse.y = buff[8] | (buff[9] << 8);
rc->mouse.z = buff[10]| (buff[11] << 8);
rc->mouse.press_left = buff[12]; // is pressed?
rc->mouse.press_right = buff[13];
rc->keyBoard.key_code = buff[14] | buff[15] << 8; //key borad code
Latest_Remote_Control_Pack_Time = HAL_GetTick();
if(Latest_Remote_Control_Pack_Time - LED_Flash_Timer_remote_control>500){
HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);
LED_Flash_Timer_remote_control = Latest_Remote_Control_Pack_Time;
}
}
extern uint16_t TIM_COUNT[];
int16_t HighTime;
/*******************************************************************************************
* @Func void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
* @Brief PWM接收机脉宽计算
* @Param TIM_HandleTypeDef *htim 用于测量PWM脉宽的定时器。
* @Retval None
* @Date
*******************************************************************************************/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
HighTime = (TIM_COUNT[1] - TIM_COUNT[0])>0?(TIM_COUNT[1] - TIM_COUNT[0]):((TIM_COUNT[1] - TIM_COUNT[0])+10000);
Latest_Remote_Control_Pack_Time = HAL_GetTick();
remote_control.ch4 = (HighTime - 4000)*660/4000;
if(Latest_Remote_Control_Pack_Time - LED_Flash_Timer_remote_control>500){
HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);
LED_Flash_Timer_remote_control = Latest_Remote_Control_Pack_Time;
}
}