添加所有遥控控制
This commit is contained in:
@@ -28,6 +28,15 @@ void chx_gpio_init(void)
|
||||
GPIO_InitCfg.Pin = RELAY_CH2_PIN; // 设置通道2引脚
|
||||
xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO
|
||||
|
||||
|
||||
if(flash_ch1_state)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
//用bit表示通道
|
||||
#define CH_GPIO2 (1 << 0) // bit0 = GPIO2
|
||||
|
||||
#define CH_GPIO5 (1 << 1) // bit1 = GPIO5
|
||||
|
||||
|
||||
@@ -368,17 +368,46 @@ void _433_fun(void)
|
||||
if(Key_TypeDef.KEY_STATE_Click==1||KEY_STATE_re==1) return;
|
||||
set_click(); //设置单击长按
|
||||
|
||||
if(res_data==0x03)
|
||||
{
|
||||
uint8_t ch_mask = adress_ch_flag[adress_index_ture];
|
||||
|
||||
uint8_t ch_mask = adress_ch_flag[adress_index_ture];
|
||||
|
||||
switch(res_data)
|
||||
{
|
||||
case 0x03: //如果是3键遥控或者是正方形白色遥
|
||||
if(ch_mask & CH_GPIO5){
|
||||
xc_gpio_toggle_pin(GPIO_5);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 0x04: //如果是黑色长方形遥控或者椭圆遥控关闭按键
|
||||
|
||||
|
||||
if(ch_mask & CH_GPIO5)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x02: //如果是黑色长方形遥控或者椭圆遥控打开按键
|
||||
|
||||
|
||||
if(ch_mask & CH_GPIO5)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -464,14 +464,8 @@ int main(void)
|
||||
|
||||
|
||||
|
||||
if(flash_ch1_state)
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//startTimer(&timer1,1);
|
||||
|
||||
@@ -22,6 +22,8 @@ static volatile uint16_t s2_debounce_cnt = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define DEBOUNCE_MS 2 //消抖时间40ms
|
||||
|
||||
//uint16_t switch1_debounce = 0;
|
||||
@@ -34,6 +36,8 @@ uint8_t s1_first_press_flag = 0; //S2首次按下标志
|
||||
uint8_t s2_first_press_flag = 0; //S2首次按下标志
|
||||
|
||||
|
||||
uint8_t S1_first_on_state=0; //上电时开关的状态
|
||||
|
||||
|
||||
void switch_init(void)
|
||||
{
|
||||
@@ -51,13 +55,28 @@ void switch_init(void)
|
||||
|
||||
xc_gpio_it_config(GPIO_1,FAIL_EDGE_INT);
|
||||
NVIC_EnableIRQ(GPIO_IRQn);
|
||||
|
||||
|
||||
if(xc_gpio_read_pin(SWITCH_S1_PIN)==0)
|
||||
{
|
||||
S1_first_on_state=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
S1_first_on_state=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void trigger_check_process(void)
|
||||
{
|
||||
|
||||
|
||||
if(S1_first_on_state==1)
|
||||
{
|
||||
S1_first_on_state=0;
|
||||
s1_first_press_flag=1;
|
||||
s1_state=DB_PRESSED;
|
||||
}
|
||||
|
||||
switch(s1_state)
|
||||
{
|
||||
@@ -162,10 +181,12 @@ void trigger_check_process(void)
|
||||
trig1_wait = 0;
|
||||
s1_first_press_flag=1;
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_SET);
|
||||
|
||||
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
set_TaskComps_timer(6,1000);
|
||||
}
|
||||
|
||||
else if(trig1_timeout == 0 && (trig1_cnt > 1 && trig1_cnt < 5))
|
||||
else if(trig1_timeout == 0 && (trig1_cnt > 1 && trig1_cnt < TRIGGER_CONTINUE_CNT))
|
||||
{
|
||||
// printf("乱按 trig1_cnt %d\r\n",trig1_cnt);
|
||||
trig1_cnt = 0;
|
||||
@@ -198,6 +219,9 @@ void trigger_check_process(void)
|
||||
s1_first_press_flag=0;
|
||||
xc_gpio_write_pin(GPIO_5,GPIO_PIN_RESET);
|
||||
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
set_TaskComps_timer(6,1000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ typedef enum {
|
||||
} debounce_state_t;
|
||||
|
||||
extern uint8_t rf433_sw_flag;
|
||||
extern uint8_t S1_first_on_state;
|
||||
|
||||
void trigger_check_process(void);
|
||||
|
||||
|
||||
@@ -119,6 +119,8 @@ void scan_uart(uint8_t *arr)
|
||||
{
|
||||
case 0x01:
|
||||
xc_gpio_toggle_pin(GPIO_5);
|
||||
flash_ch1_state=xc_gpio_read_pin(GPIO_5);
|
||||
set_TaskComps_timer(6,1000);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user