[$is_event_jimu] 2 [$group] 元件库.4路按钮类 [$group_e] 元件事件库.4路按钮类 [$last_ver_update_time] 2021-04-03 [$min_need_ver] 1.23 [$p_list] [$short_show_UIname] [$code_area_type] codes,exe_per_1ms,init_code [$blocks_type] line [$name] 4路按钮 [$thread_do] thread_anniu4_t_$rnd_varname_pre$();//虚拟线程,不能含阻塞执行的部分,每1ms执行一次 [$thread_do_sim] thread_anniu4_t_$rnd_varname_pre$();//虚拟线程,不能含阻塞执行的部分,每1ms执行一次 [$cs] [$function_ref_define_in_headfile] @@file=anniu4.h u8 read_anniu4_is_pressed_t_$rnd_varname_pre$(u8 anniu_index); u8 read_anniu4_index_t_$rnd_varname_pre$(); u8 read_anniu4_index2_t_$rnd_varname_pre$(); void thread_anniu4_t_$rnd_varname_pre$(); //extern u8 anniu_state_realtime_$rnd_varname_pre$[4]; extern u8 iii_$rnd_varname_pre$; extern u8 anniu_state_$rnd_varname_pre$[4]; extern u8 anniu_state2_$rnd_varname_pre$[4]; extern u16 anniu_preesed_time_count_$rnd_varname_pre$[4]; extern u8 anniu_pre_state_is_pressed_$rnd_varname_pre$[4]; [$function_ref_define_in_headfile_sim] [$init_code_for_define_area] @@file=anniu4.c u8 iii_$rnd_varname_pre$; u8 anniu_state_$rnd_varname_pre$[4]; u8 anniu_state2_$rnd_varname_pre$[4]; //u8 anniu_state_realtime_$rnd_varname_pre$[4]; u16 anniu_preesed_time_count_$rnd_varname_pre$[4]; u8 anniu_pre_state_is_pressed_$rnd_varname_pre$[4]; u16 anniu_unpreesed_time_count_$rnd_varname_pre$[4];//ruandy 20240312 u8 read_anniu4_is_pressed_t_$rnd_varname_pre$(u8 anniu_index){ //获得1-4个按钮的状态,返回0表示未按下,返回1表示对应按钮被按下后并松开(短按后松开),返回2表示长按了按钮 if(anniu_index>3||anniu_index<0 ){return 0; } return anniu_state_$rnd_varname_pre$[anniu_index]; } u8 read_anniu4_index_t_$rnd_varname_pre$(){ //获得1-4个按钮的状态,返回0表示没按钮按下,返回1表示一号按钮被按下后并松开,同理2-4,...,返回5表示按钮1被长按,同理6-8 u8 iii; for(iii=0;iii<4;iii++){ if(anniu_state_$rnd_varname_pre$[iii]==2){//长按状态优先匹配! return iii+1+4; } } for(iii=0;iii<4;iii++){ if(anniu_state_$rnd_varname_pre$[iii]==1){ return iii+1; } } return 0; } u8 read_anniu4_index2_t_$rnd_varname_pre$(){ //获得1-4个按钮的状态,返回0表示没按钮按下,返回1表示一号按钮被按下且未松开,同理。。。 u8 iii; for(iii=0;iii<4;iii++){ if(anniu_state2_$rnd_varname_pre$[iii]>0){ return iii+1; } } return 0; } void process_anniu_t_$rnd_varname_pre$(u8 anniu_index){ if(anniu_index>3){return; } if( (anniu_index==0&&IO_Read( [($_xgm$value1),type=pin])==0) || (anniu_index==1&& IO_Read([($_xgm$value2),type=pin])==0) || (anniu_index==2&& IO_Read([($_xgm$value3),type=pin])==0) || (anniu_index==3&& IO_Read([($_xgm$value4),type=pin])==0) ){ if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]<=65000){ anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]++; } anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]=1; if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]>20){ anniu_state2_$rnd_varname_pre$[anniu_index]=1;//按钮状态2 置为1 } if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]>3000&& anniu_state_$rnd_varname_pre$[anniu_index]!=99){//20221114 anniu_state_$rnd_varname_pre$[anniu_index]=2;//按钮状态1 置为2,表示长按了按钮 } anniu_unpreesed_time_count_$rnd_varname_pre$[anniu_index]=0;//按钮未完全释放时重置已释放时间为0,ruandy 20240312 }else{ anniu_unpreesed_time_count_$rnd_varname_pre$[anniu_index]++;//按钮释放时间去抖动ruandy 20240312 if(anniu_unpreesed_time_count_$rnd_varname_pre$[anniu_index]>4){ //去抖动ruandy 20240312 if( anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]==1){//如果上次按下1次 anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]=0;//清除 按下1次 状态 if(anniu_state_$rnd_varname_pre$[anniu_index]==0&&anniu_state2_$rnd_varname_pre$[anniu_index]==1){//如果不是长按触发状态,anniu_state2_$rnd_varname_pre$[anniu_index]:去抖动 anniu_state_$rnd_varname_pre$[anniu_index]=1;//按钮状态1 置为1,表示按了一次按钮并松开 } if(anniu_state_$rnd_varname_pre$[anniu_index]==2){//如果是长按触发状态 anniu_state_$rnd_varname_pre$[anniu_index]=0;//按钮状态1 置为0 } } anniu_state2_$rnd_varname_pre$[anniu_index]=0;//按钮状态2 清零 anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]=0; if(anniu_state_$rnd_varname_pre$[anniu_index]==99){//要和 if( anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]==1)同层! anniu_state_$rnd_varname_pre$[anniu_index]=0; } anniu_unpreesed_time_count_$rnd_varname_pre$[anniu_index]=0; }//ruandy 20240312 } } void thread_anniu4_t_$rnd_varname_pre$(){ // anniu_state_realtime_$rnd_varname_pre$[0]=[($_xgm$value1),type=pin]; // anniu_state_realtime_$rnd_varname_pre$[1]=[($_xgm$value2),type=pin]; // anniu_state_realtime_$rnd_varname_pre$[2]=[($_xgm$value3),type=pin]; // anniu_state_realtime_$rnd_varname_pre$[3]=[($_xgm$value4),type=pin]; process_anniu_t_$rnd_varname_pre$(0); process_anniu_t_$rnd_varname_pre$(1); process_anniu_t_$rnd_varname_pre$(2); process_anniu_t_$rnd_varname_pre$(3); } [$init_code_for_define_area_sim] static int iii_$rnd_varname_pre$; static int[] anniu_state_$rnd_varname_pre$=new int[4]; static int[] anniu_state2_$rnd_varname_pre$=new int[4]; static int[] anniu_preesed_time_count_$rnd_varname_pre$=new int[4]; static int[] anniu_pre_state_is_pressed_$rnd_varname_pre$=new int[4]; static int read_anniu4_is_pressed_t_$rnd_varname_pre$(byte anniu_index){ //获得1-4个按钮的状态,返回0表示未按下,返回1表示对应按钮被按下后并松开(短按后松开),返回2表示长按了按钮 if(anniu_index>3||anniu_index<0 ){return 0; } return anniu_state_$rnd_varname_pre$[anniu_index]; } static int read_anniu4_index_t_$rnd_varname_pre$(){ //获得1-4个按钮的状态,返回0表示没按钮按下,返回1表示一号按钮被按下后并松开,同理2-4,...,返回5表示按钮1被长按,同理6-8 int iii; for(iii=0;iii<4;iii++){ if(anniu_state_$rnd_varname_pre$[iii]==2){ //长按状态优先匹配! return iii+1+4; } } for(iii=0;iii<4;iii++){ if(anniu_state_$rnd_varname_pre$[iii]==1){ return iii+1; } } return 0; } static int read_anniu4_index2_t_$rnd_varname_pre$(){ //获得1-4个按钮的状态,返回0表示没按钮按下,返回1表示一号按钮被按下且未松开,同理。。。 int iii; for(iii=0;iii<4;iii++){ if(anniu_state2_$rnd_varname_pre$[iii]>0){ return iii+1; } } return 0; } static void process_anniu_t_$rnd_varname_pre$(byte anniu_index){ if(anniu_index>3){return; } if( (anniu_index==0&&API_funcs_for_sim.get_stm32_IO( p_item1_ref , "[($_xgm$value1),type=pin]")==0) || (anniu_index==1&& API_funcs_for_sim.get_stm32_IO( p_item1_ref ,"[($_xgm$value2),type=pin]")==0) || (anniu_index==2&&API_funcs_for_sim.get_stm32_IO( p_item1_ref ,"[($_xgm$value3),type=pin]")==0) || (anniu_index==3&& API_funcs_for_sim.get_stm32_IO( p_item1_ref ,"[($_xgm$value4),type=pin]")==0) ){ if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]<=650){//old=65000; anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]++; } anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]=1; if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]>3){//old=20 anniu_state2_$rnd_varname_pre$[anniu_index]=1;//按钮状态2 置为1 } if(anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]>200&& anniu_state_$rnd_varname_pre$[anniu_index]!=99){//20221114 //old=anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]>3000 anniu_state_$rnd_varname_pre$[anniu_index]=2;//按钮状态1 置为2,表示长按了按钮 } }else{ if( anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]==1){//如果上次按下1次 anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]=0;//清除 按下1次 状态 if(anniu_state_$rnd_varname_pre$[anniu_index]==0&&anniu_state2_$rnd_varname_pre$[anniu_index]==1){//如果不是长按触发状态,anniu_state2_$rnd_varname_pre$[anniu_index]:去抖动 anniu_state_$rnd_varname_pre$[anniu_index]=1;//按钮状态1 置为1,表示按了一次按钮并松开 } if(anniu_state_$rnd_varname_pre$[anniu_index]==2){//如果是长按触发状态 anniu_state_$rnd_varname_pre$[anniu_index]=0;//按钮状态1 置为0 } } anniu_state2_$rnd_varname_pre$[anniu_index]=0;//按钮状态2 清零 anniu_preesed_time_count_$rnd_varname_pre$[anniu_index]=0; if(anniu_state_$rnd_varname_pre$[anniu_index]==99){//要和 if( anniu_pre_state_is_pressed_$rnd_varname_pre$[anniu_index]==1)同层! anniu_state_$rnd_varname_pre$[anniu_index]=0; } } } static void thread_anniu4_t_$rnd_varname_pre$(){ process_anniu_t_$rnd_varname_pre$(0); process_anniu_t_$rnd_varname_pre$(1); process_anniu_t_$rnd_varname_pre$(2); process_anniu_t_$rnd_varname_pre$(3); } [$init_code_for_init_val] //shanled_flag_$rnd_varname_pre$=0; #get_P口_to_PxM1_PxM0_set_code(group_xml,rand1,block_name,ref_complier,extinfo,"[($_xgm$value1),type=pin]","0","anniu1")% #get_P口_to_PxM1_PxM0_set_code(group_xml,rand1,block_name,ref_complier,extinfo,"[($_xgm$value2),type=pin]","0","anniu2")% #get_P口_to_PxM1_PxM0_set_code(group_xml,rand1,block_name,ref_complier,extinfo,"[($_xgm$value3),type=pin]","0","anniu3")% #get_P口_to_PxM1_PxM0_set_code(group_xml,rand1,block_name,ref_complier,extinfo,"[($_xgm$value4),type=pin]","0","anniu4")% IO_Write([($_xgm$value1),type=pin],1); IO_Write([($_xgm$value2),type=pin],1); IO_Write([($_xgm$value3),type=pin],1); IO_Write([($_xgm$value4),type=pin],1); anniu_pre_state_is_pressed_$rnd_varname_pre$[0]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[1]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[2]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[3]=0; anniu_state_$rnd_varname_pre$[0]=0; anniu_state_$rnd_varname_pre$[1]=0; anniu_state_$rnd_varname_pre$[2]=0; anniu_state_$rnd_varname_pre$[3]=0; anniu_state2_$rnd_varname_pre$[0]=0; anniu_state2_$rnd_varname_pre$[1]=0; anniu_state2_$rnd_varname_pre$[2]=0; anniu_state2_$rnd_varname_pre$[3]=0; [$init_code_for_init_val_sim] API_funcs_for_sim.set_stm32_IO(p_item1_ref , "[($_xgm$value1),type=pin]",1,0); API_funcs_for_sim.set_stm32_IO(p_item1_ref , "[($_xgm$value2),type=pin]",1,0); API_funcs_for_sim.set_stm32_IO(p_item1_ref , "[($_xgm$value3),type=pin]",1,0); API_funcs_for_sim.set_stm32_IO(p_item1_ref , "[($_xgm$value4),type=pin]",1,0); //API_funcs_for_sim.alert_to_js_tishi_cannot_sim_this_ele(p_item1_ref , "4路按钮1"); //API_funcs_for_sim.alert_to_js_tishi_cannot_sim_this_ele(p_item1_ref , "4路按钮2233"); anniu_pre_state_is_pressed_$rnd_varname_pre$[0]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[1]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[2]=0; anniu_pre_state_is_pressed_$rnd_varname_pre$[3]=0; anniu_state_$rnd_varname_pre$[0]=0; anniu_state_$rnd_varname_pre$[1]=0; anniu_state_$rnd_varname_pre$[2]=0; anniu_state_$rnd_varname_pre$[3]=0; anniu_state2_$rnd_varname_pre$[0]=0; anniu_state2_$rnd_varname_pre$[1]=0; anniu_state2_$rnd_varname_pre$[2]=0; anniu_state2_$rnd_varname_pre$[3]=0; [$timer0_1ms_code] [$toolbox_block_code] [$replace_map] $_xgm$value1 = $field$guanjiao1 ,mytype|pin, ptype|TIMES $_xgm$value2 = $field$guanjiao2 ,mytype|pin, ptype|TIMES $_xgm$value3 = $field$guanjiao3 ,mytype|pin, ptype|TIMES $_xgm$value4 = $field$guanjiao4 ,mytype|pin, ptype|TIMES