add SOS BUTTON CONTROL....
This commit is contained in:
parent
190a3c652d
commit
79e2ee456b
|
@ -57,7 +57,9 @@ static uint8_t consecutiveEqualCount = 0; // 数据接收相同计数
|
|||
static uint8_t Bit_Count = 0; // 接收数据位计数
|
||||
static uint8_t Received_Data = 0; // 接收到的数据
|
||||
static Decode_State_t RF_Decode_State = LEAD_CODE; // 数据解码状态
|
||||
|
||||
static uint32_t Lead_Code_Count_Start =0;
|
||||
static uint32_t High_Bit_Count_Start =0;
|
||||
static uint32_t Low_Bit_Count_Start =0;
|
||||
void Decode_Data(void);
|
||||
void Execute_Function(void);
|
||||
void Reset_Decode_Parameters(void);
|
||||
|
@ -91,19 +93,28 @@ void RF_Signal_Decode(void)
|
|||
// 判断是否低电平
|
||||
if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET)
|
||||
{
|
||||
Lead_Code_Count++;
|
||||
// printf("_");
|
||||
// Lead_Code_Count++;
|
||||
// Lead_Code_Count = TIM1_cnt - Lead_Code_Count_Start;
|
||||
|
||||
}
|
||||
else // 高电平判断范围
|
||||
{
|
||||
|
||||
Lead_Code_Count = TIM1_cnt - Lead_Code_Count_Start;
|
||||
printf("+");
|
||||
// 判断引导码范围是否合法
|
||||
|
||||
if (Lead_Code_Count >= MIN_LEAD_CODE && Lead_Code_Count <= MAX_LEAD_CODE)
|
||||
{
|
||||
Lead_Code_Count = 0;
|
||||
Reset_Decode_Parameters(); // 重置解码参数
|
||||
RF_Decode_State = HIGH_BIT; // 进入高位数据位判断状态
|
||||
printf("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(".");
|
||||
Reset_Decode_Parameters(); // 引导码范围不合法,重置解码参数
|
||||
}
|
||||
}
|
||||
|
@ -113,16 +124,20 @@ void RF_Signal_Decode(void)
|
|||
// 判断是否高电平
|
||||
if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_SET)
|
||||
{
|
||||
High_Bit_Count++;
|
||||
// High_Bit_Count++;
|
||||
// High_Bit_Count = TIM1_cnt;
|
||||
High_Bit_Count_Start = TIM1_cnt;
|
||||
}
|
||||
else // 低电平判断范围
|
||||
{
|
||||
High_Bit_Count = TIM1_cnt - High_Bit_Count_Start;
|
||||
// 判断高位数据位范围是否合法
|
||||
if (High_Bit_Count >= MIN_BIT_DURATION && High_Bit_Count <= MAX_BIT_DURATION)
|
||||
{
|
||||
High_Bit_Duration = High_Bit_Count; // 保存计数值,用于区分0和1
|
||||
High_Bit_Count = 0;
|
||||
RF_Decode_State = LOW_BIT; // 进入低位数据位判断状态
|
||||
printf("-");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,16 +150,20 @@ void RF_Signal_Decode(void)
|
|||
// 判断是否低电平
|
||||
if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET)
|
||||
{
|
||||
Low_Bit_Count++;
|
||||
//Low_Bit_Count++;
|
||||
// Low_Bit_Count = TIM1_cnt;
|
||||
Low_Bit_Count_Start = TIM1_cnt;
|
||||
}
|
||||
else // 高电平判断范围
|
||||
{
|
||||
Low_Bit_Count = TIM1_cnt - Low_Bit_Count_Start;
|
||||
// 判断低位数据位范围是否合法
|
||||
if (Low_Bit_Count >= MIN_BIT_DURATION && Low_Bit_Count <= MAX_BIT_DURATION)
|
||||
{
|
||||
Low_Bit_Duration = Low_Bit_Count; // 保存计数值,用于区分0和1
|
||||
Low_Bit_Count = 0;
|
||||
RF_Decode_State = DATA_PROCESS; // 进入数据处理状态
|
||||
printf("o");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -292,6 +311,10 @@ void Reset_Decode_Parameters(void)
|
|||
High_Bit_Duration = 0;
|
||||
Low_Bit_Duration = 0;
|
||||
RF_Decode_State = LEAD_CODE;
|
||||
|
||||
Lead_Code_Count_Start = TIM1_cnt;
|
||||
High_Bit_Count_Start = TIM1_cnt;
|
||||
|
||||
}
|
||||
|
||||
/**----------------------------------------------------------------------------------------------**
|
||||
|
@ -400,12 +423,24 @@ extern uint8_t rf_data[4];
|
|||
#define BIT0_LOW_US 1100
|
||||
#endif
|
||||
|
||||
#if 0 // RC_PROJECTOR
|
||||
#define BIT1_HIGH_US 1000 // duty cycle =
|
||||
#define BIT1_LOW_US 500 //
|
||||
#define BIT0_HIGH_US 250
|
||||
#define BIT0_LOW_US 1200
|
||||
#define ENDING_LOW_US 200
|
||||
#define ENDING_HIGH_US 12000
|
||||
#define ENDING_LOW_US 12000
|
||||
#define ENDING_HIGH_US 200
|
||||
#endif
|
||||
|
||||
#if 1 // SOS BUTTON
|
||||
#define BIT1_HIGH_US 800 // duty cycle =
|
||||
#define BIT1_LOW_US 300 //
|
||||
#define BIT0_HIGH_US 300
|
||||
#define BIT0_LOW_US 800
|
||||
#define ENDING_LOW_US 8000
|
||||
#define ENDING_HIGH_US 245
|
||||
#endif
|
||||
|
||||
|
||||
//#define CNT_SHORT_US 305 // 305 usec
|
||||
#define LEADING_MS 12 // 8 msec
|
||||
|
@ -494,7 +529,7 @@ void STS_RF_Send_AddressBit_and_CmdBit(uint8_t *rf_payload, uint8_t rf_length)
|
|||
|
||||
// send leading or sync signal for receiver to sync the RX clock
|
||||
// printf("leading sync signal ...\r\n");
|
||||
STS_RF_write_send_leading();
|
||||
//STS_RF_write_send_leading();
|
||||
|
||||
// printf("address bits and cmd bits ...\r\n");
|
||||
// send address and cmd code
|
||||
|
|
|
@ -123,12 +123,13 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(RF_Send_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
#if 0
|
||||
GPIO_InitStruct.Pin = RF_Receive_GPIO_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(RF_Receive_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef L8
|
||||
/*Configure GPIO pins : PAPin PAPin */
|
||||
|
@ -189,7 +190,7 @@ void MX_GPIO_Init(void)
|
|||
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
|
||||
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
|
||||
|
|
|
@ -64,7 +64,8 @@ uint32_t uwFrequency = 0;
|
|||
#endif
|
||||
//uint8_t rf_payload[3]={0xF8,0xCD,0x07}, rf_length=3;
|
||||
|
||||
uint8_t rf_payload[3]={0x1F,0xB3,0xE0}, rf_length=3;
|
||||
uint8_t rf_payload[3]={0x1F,0xB3,0xE0}, rf_length=3; // RC_PROJECTOR
|
||||
uint8_t sos_rf_payload[3]={0x82,0x73,0xA0}, sos_rf_length=3; // sos_button
|
||||
enum rf_cmd_enum
|
||||
{ BUTTON_NONE=0,
|
||||
BUTTON_ON,
|
||||
|
@ -79,7 +80,7 @@ enum rf_cmd_enum
|
|||
};
|
||||
|
||||
uint8_t rf_cmd[16]={0x00, 0x8,0xC,0x4,0x6,0x1,0x9,0x2,0x3}; // cmd 1 = 1, cmd2=4, cmd3=3, cmd4=2
|
||||
|
||||
uint8_t sos_rf_cmd[16]={0x00, 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0}; // cmd 1 = 1
|
||||
void sts_rc_key(uint8_t key);
|
||||
void sts_rc_decoder(void);
|
||||
uint8_t sts_rc_decodedx(void);
|
||||
|
@ -207,7 +208,7 @@ int main(void)
|
|||
External Signal DutyCycle = (TIM1_CCR1*100)/(TIM1_CCR2) in %.
|
||||
|
||||
--------------------------------------------------------------------------- */
|
||||
#if 0
|
||||
#if 1
|
||||
/*## Start the Input Capture in interrupt mode ##########################*/
|
||||
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
|
@ -226,6 +227,7 @@ int main(void)
|
|||
|
||||
while(1)
|
||||
{
|
||||
#if 1
|
||||
switch(capture_Cnt) {
|
||||
|
||||
case 0:
|
||||
|
@ -243,7 +245,7 @@ int main(void)
|
|||
capture_Cnt = 0; // clear flag
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,11 +372,20 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
switch(GPIO_Pin)
|
||||
{
|
||||
case BUT1_Pin:
|
||||
#if 0
|
||||
printf("Button 1 pressed, sending cmd #1 \r\n");
|
||||
//STS_RF_Send_AddressBit_and_CmdBit(rf_payload, rf_length);
|
||||
// STS_RF_Send_Multi_Times(rf_payload, 3, 8);
|
||||
single_button = rf_cmd[BUTTON_ON];
|
||||
STS_RF_Send_Button_Multi_Times(rf_payload, single_button, 3, 8);
|
||||
#endif
|
||||
|
||||
printf("SOS Button pressed, sending cmd #1 \r\n");
|
||||
//STS_RF_Send_AddressBit_and_CmdBit(rf_payload, rf_length);
|
||||
// STS_RF_Send_Multi_Times(rf_payload, 3, 8);
|
||||
single_button = sos_rf_cmd[BUTTON_ON];
|
||||
STS_RF_Send_Button_Multi_Times(sos_rf_payload, single_button, 3, 8);
|
||||
|
||||
break;
|
||||
|
||||
case BUT2_Pin:
|
||||
|
@ -393,8 +404,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
|
||||
|
||||
case DATA_433_PIN:
|
||||
|
||||
//printf("^");
|
||||
RF_Signal_Decode();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -372,7 +372,7 @@ void EXTI9_5_IRQHandler(void)
|
|||
HAL_GPIO_EXTI_IRQHandler(BUT3_Pin);
|
||||
|
||||
HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN);
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(DATA_433_PIN);
|
||||
//__HAL_GPIO_EXTI_CLEAR_IT(DATA_433_PIN);
|
||||
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
|
||||
|
||||
|
@ -462,8 +462,10 @@ void SUBGHZ_Radio_IRQHandler(void)
|
|||
|
||||
void TIM1_IRQHandler(void)
|
||||
{
|
||||
TIM1_cnt++;
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
}
|
||||
#if 0
|
||||
/**
|
||||
* @brief This function handles TIM1 Capture Compare Interrupt.
|
||||
*/
|
||||
|
@ -473,12 +475,11 @@ void TIM1_CC_IRQHandler(void)
|
|||
|
||||
/* USER CODE END TIM1_CC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
TIM1_cnt++;
|
||||
/* USER CODE BEGIN TIM1_CC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_CC_IRQn 1 */
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* @brief This function handles TIM1 Capture Compare Interrupt.
|
||||
*/
|
||||
|
@ -488,7 +489,7 @@ void TIM1_IC_IRQHandler(void)
|
|||
|
||||
/* USER CODE END TIM1_CC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
TIM1_cnt++;
|
||||
// TIM1_cnt++;
|
||||
/* USER CODE BEGIN TIM1_CC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_CC_IRQn 1 */
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue