#include "include.h" #include "multi_button.h" pKeyState GROUP_KEY = {0}; struct Button kCS,kJS; void ScanKey ( void ) //5ms { button_ticks(); } uint8_t Read_CS_GPIO() { return (bool)GET_KEY_CS; } uint8_t Read_JS_GPIO() { return (bool)GET_KEY_JS; } void Keys_SIG(void* btn) { int event; if(btn == &kCS){ event = get_button_event(btn); switch(event) { case SINGLE_CLICK: GROUP_KEY.CS=1; break; //测试 case LONG_RRESS_START: GROUP_KEY.CS_L=1; break; //长按测试 } }else if(btn == &kJS){ event = get_button_event(btn); switch(event) { case SINGLE_CLICK: GROUP_KEY.JS=1; break; //计时 case LONG_RRESS_START: GROUP_KEY.JS_L=1; break; //长按计时 } } } void Keys_Init(void) { button_init_Head(); button_init(&kCS, Read_CS_GPIO, 0); //低电平触发 button_init(&kJS, Read_JS_GPIO, 0); //低电平触发 button_attach(&kCS, SINGLE_CLICK, Keys_SIG); button_attach(&kCS, LONG_RRESS_START, Keys_SIG); button_attach(&kJS, SINGLE_CLICK, Keys_SIG); button_attach(&kJS, LONG_RRESS_START, Keys_SIG); button_start(&kCS); button_start(&kJS); //make the timer invoking the button_ticks() interval 5ms. //This function is implemented by yourself. //__timer_start(button_ticks, 0, 5); } static bool JS_On = true; void Key_JS_Hanlder ( void* btn ) { #if 0 if ( SysRunType == SysRun_Norm ) { StopBeep(); } #endif Smg_Display_Next(); } void Key_CS_Hanlder ( void* btn ) { #if 0 switch ( SysRunType ) { case SysRun_Norm: SysRunType = SysRun_Test; sysLed_Set ( LED_MODE_TEST_RUN ); break; case SysRun_Test: SysRunType = SysRun_Norm; sysLed_Set ( LED_MODE_WORK_RUN ); break; } Fas_Param_Of_Mode_Change ( SysRunType ); #endif } void Key_JS_Long_Hanlder ( void* btn ) { //WaitKey_GotoTest(); JS_On = !JS_On; Smg_Display_OnOff(JS_On); } void Key_CS_Long_Hanlder ( void* btn ) { } void WaitKey_GotoTest ( void ) { #if 0 static bool Can_enter_Factory = TRUE; if ( sys_rtc_time <= 10 ) //启动10秒内,按下Key_CS { if ( Can_enter_Factory ) { Can_enter_Factory = FALSE; SysRunType = SysRun_Test; sysLed_Set ( LED_MODE_TEST_RUN ); } } #endif } void Keys_All_Handler(void) { if(GROUP_KEY.CS) { GROUP_KEY.CS = 0; Key_CS_Hanlder(&kCS); } if(GROUP_KEY.JS) { GROUP_KEY.JS = 0; Key_JS_Hanlder(&kJS); } if(GROUP_KEY.CS_L) { GROUP_KEY.CS_L = 0; Key_CS_Long_Hanlder(&kCS); } if(GROUP_KEY.JS_L) { GROUP_KEY.JS_L = 0; Key_JS_Long_Hanlder(&kJS); } }