完成1.0版本功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "rf433.h"
|
||||
#include <stdbool.h>
|
||||
#include "xc_drv_gpio.h"
|
||||
#include "key.h"
|
||||
#include "led.h"
|
||||
@@ -6,11 +7,12 @@
|
||||
#include "switch_s.h"
|
||||
#include "timeslice.h"
|
||||
#include "dbg.h"
|
||||
#include "rf433_decoder.h"
|
||||
//用bit表示通道
|
||||
#define CH_GPIO2 0x01
|
||||
#define CH_GPIO5 0x10
|
||||
|
||||
|
||||
Rf433DecoderFrame_t rf433_frame;
|
||||
|
||||
uint32_t receive_temp;
|
||||
uint32_t receive_data;
|
||||
@@ -23,6 +25,8 @@ uint8_t key_state=0;
|
||||
uint8_t KEY_STATE_re=0; // 长按
|
||||
uint8_t long_flag_s=0;
|
||||
|
||||
uint8_t receive_finsh_flag=0;
|
||||
|
||||
static uint8_t power=2;
|
||||
|
||||
uint8_t res_data=255; //433返回的最后一个控制字节(低八位)
|
||||
@@ -43,6 +47,12 @@ uint8_t flash_ch2_state=0;
|
||||
|
||||
union rf433_flag rf_flag = {0};
|
||||
|
||||
|
||||
#define rf433_long_time 500
|
||||
uint16_t long_timer=0;
|
||||
uint8_t last_H_adress=0;
|
||||
uint8_t last_L_adress=0;
|
||||
|
||||
typedef struct {
|
||||
uint32_t KEY_STATE_Click; // 单击
|
||||
uint32_t KEY_STATE_LONG_PRESS; // 长按
|
||||
@@ -305,8 +315,8 @@ void ble_mode_scan(void)
|
||||
|
||||
void _433_fun(void)
|
||||
{
|
||||
if(Key_TypeDef.KEY_STATE_Click==1||KEY_STATE_re==1) return;
|
||||
set_click(); //设置单击长按
|
||||
// if(Key_TypeDef.KEY_STATE_Click==1||KEY_STATE_re==1) return;
|
||||
// set_click(); //设置单击长按
|
||||
|
||||
uint8_t ch_mask = adress_ch_flag[adress_index_ture];
|
||||
|
||||
@@ -370,7 +380,14 @@ void _433_fun(void)
|
||||
void scan_433(void)
|
||||
{
|
||||
uint8_t i=0;
|
||||
|
||||
bool rf433_decoder_flag=false;
|
||||
rf433_decoder_flag=rf433_decoder_get_frame(&rf433_frame);
|
||||
|
||||
if(long_timer>0)
|
||||
{
|
||||
long_timer--;
|
||||
}
|
||||
|
||||
if(rf433_sw_flag==1)
|
||||
{
|
||||
rf433_sw_flag=0;
|
||||
@@ -385,11 +402,19 @@ void scan_433(void)
|
||||
key_state=KEY_SHORT;
|
||||
led_state=2;
|
||||
}
|
||||
|
||||
if(power==3 && rf_flag.rf_receive_flag.receive_finish==1 && key_state==KEY_SHORT ) //双击对码GPIO2
|
||||
|
||||
if(rf433_decoder_flag)
|
||||
{
|
||||
adress_H = rf433_frame.addr_h;
|
||||
adress_L = rf433_frame.addr_l;
|
||||
res_data = rf433_frame.key ;
|
||||
//LOGI("finsh finsh finsh\r\n");
|
||||
}
|
||||
//LOGI("rf433_decoder_flag %d adress_H 0x%02x adress_L 0x%02x res_data 0x%02x\r\n",rf433_decoder_flag,adress_H,adress_L,res_data);
|
||||
if(power==3 && rf433_decoder_flag==true && key_state==KEY_SHORT ) //双击对码GPIO2
|
||||
{
|
||||
|
||||
|
||||
|
||||
key_state=0;
|
||||
power=2;
|
||||
led_state=0;
|
||||
@@ -397,8 +422,8 @@ void scan_433(void)
|
||||
|
||||
uint8_t ch_mask=CH_GPIO2; //对应位掩码
|
||||
|
||||
adress_H=((receive_data>>16)&0xff); //读取高八位地址码
|
||||
adress_L=((receive_data>>8)&0xff); //读取低八位地址码
|
||||
// adress_H=((receive_data>>16)&0xff); //读取高八位地址码
|
||||
// adress_L=((receive_data>>8)&0xff); //读取低八位地址码
|
||||
|
||||
if(adress_index>4)
|
||||
{
|
||||
@@ -433,7 +458,7 @@ void scan_433(void)
|
||||
}
|
||||
|
||||
|
||||
else if(power==4 && rf_flag.rf_receive_flag.receive_finish==1 && key_state==KEY_SHORT ) //四击对码GPIO5
|
||||
else if(power==4 && rf433_decoder_flag==true && key_state==KEY_SHORT ) //四击对码GPIO5
|
||||
{
|
||||
|
||||
|
||||
@@ -443,8 +468,8 @@ void scan_433(void)
|
||||
|
||||
uint8_t ch_mask=CH_GPIO5; //对应位掩码
|
||||
|
||||
adress_H=((receive_data>>16)&0xff); //读取高八位地址码
|
||||
adress_L=((receive_data>>8)&0xff); //读取低八位地址码
|
||||
// adress_H=((receive_data>>16)&0xff); //读取高八位地址码
|
||||
// adress_L=((receive_data>>8)&0xff); //读取低八位地址码
|
||||
|
||||
if(adress_index>4)
|
||||
{
|
||||
@@ -479,14 +504,18 @@ void scan_433(void)
|
||||
|
||||
|
||||
|
||||
if(power==2 && rf_flag.rf_receive_flag.receive_finish==1)
|
||||
if(power==2 && rf433_decoder_flag==true)
|
||||
{
|
||||
|
||||
if(long_timer>0 && (last_H_adress == adress_H && last_L_adress == adress_L))
|
||||
{
|
||||
return;
|
||||
}
|
||||
adress_index_ture = 0xFF; // 默认无效
|
||||
for(i=0; i<5; i++)
|
||||
{
|
||||
if( adress_H_array[i] == ((receive_data>>16)&0xff) &&
|
||||
adress_L_array[i] == ((receive_data>>8)&0xff) )
|
||||
if( adress_H_array[i] == adress_H &&
|
||||
adress_L_array[i] == adress_L )
|
||||
{
|
||||
adress_index_ture = i; // 找到索引
|
||||
break;
|
||||
@@ -495,19 +524,13 @@ void scan_433(void)
|
||||
|
||||
// 找到有效索引执行
|
||||
if(adress_index_ture != 0xFF)
|
||||
{
|
||||
// adress_H=((receive_data>>16)&0xff); //读取高八位地址码
|
||||
// adress_L=((receive_data>>8)&0xff); //读取低八位地址码
|
||||
//LOGI("%d %x %x\r\n",adress_index_ture,adress_H,adress_L);
|
||||
{
|
||||
_433_fun();
|
||||
flash_run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
rf_flag.rf_receive_flag.receive_finish=0;
|
||||
last_H_adress=adress_H;
|
||||
last_L_adress=adress_L;
|
||||
long_timer=rf433_long_time;
|
||||
}
|
||||
|
||||
if( key_state==KEY_LONG )
|
||||
|
||||
Reference in New Issue
Block a user