123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- #include "common.h"
- HSKey Key[4];
- void KeyInit(void)
- {
- Key[KEY_SELECT].longPressTimeOne = 2;
- Key[KEY_UP].longPressTimeKeep = 2;
- //Key[KEY_COUNTER].longPressTimeKeep = 4;
- }
- //50ms key polling
- void ReadKEY(void)
- {
- if( SystemTimer.TIM_KEY < 45 )
- return;
- SystemTimer.TIM_KEY = 0;
- //////////////////////////////////////////////////////////////////////////////////////////
- if( nrf_gpio_pin_read(BSP_BUTTON_2) == false )
- {
- if( Key[KEY_SELECT].softRelease == 1 )
- {
- return;
- }
-
- if( Key[KEY_SELECT].onFlag == 0 )
- {
- #ifdef ENABLE_USART
- //printf("KEY_NUMUP\r\n");
- #endif
- KeySelectPressed();
- }else{
- if( Key[KEY_SELECT].longPressTimeKeep != 0 )
- {
- if( Key[KEY_SELECT].pressedSec >= Key[KEY_SELECT].longPressTimeKeep )
- {
- KeySelectLongPressedKeep();
- }
- }
-
- if( Key[KEY_SELECT].pressTime%11 == 0 ) // count up 1 sec
- {
- #ifdef ENABLE_USART
- //printf("KEY_NUMUP Press Time_%d\r\n", (unsigned int)Key[0].pressedSec);
- #endif
- Key[KEY_SELECT].pressedSec++;
- if( Key[KEY_SELECT].longPressTimeOne != 0 )
- {
- if( Key[KEY_SELECT].pressedSec >= Key[KEY_SELECT].longPressTimeOne )
- {
-
- KeySelectLongPressedOne();
- Key[KEY_SELECT].softRelease = 1;
- }
- }
- }
- }
- Key[KEY_SELECT].onFlag = 1;
- Key[KEY_SELECT].pressTime++;
- }else{
- if( Key[KEY_SELECT].onFlag == 1 )
- {
- //printf("KEY_NUMUP_%d\r\n", (unsigned int)Key[0].pressTime);
- KeySelectReleased();
-
- }
- Key[KEY_SELECT].pressTime = 0;
- Key[KEY_SELECT].onFlag = 0;
- Key[KEY_SELECT].pressedSec = 0;
- Key[KEY_SELECT].softRelease = 0;
- Key[KEY_SELECT].prevTime = 0;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- if( nrf_gpio_pin_read(BSP_BUTTON_1) == false )
- {
- if( Key[KEY_UP].softRelease == 1 )
- {
- return;
- }
-
- if( Key[KEY_UP].onFlag == 0 )
- {
- #ifdef ENABLE_USART
- //printf("KEY_NUMUP\r\n");
- #endif
- KeyUpPressed();
- }else{
- if( Key[KEY_UP].longPressTimeKeep != 0 )
- {
- if( Key[KEY_UP].pressedSec >= Key[KEY_UP].longPressTimeKeep )
- {
- KeyUpLongPressedKeep();
- }
- }
-
- if( Key[KEY_UP].pressTime%11 == 0 ) // count up 1 sec
- {
- #ifdef ENABLE_USART
- //printf("KEY_NUMUP Press Time_%d\r\n", (unsigned int)Key[0].pressedSec);
- #endif
- Key[KEY_UP].pressedSec++;
- if( Key[KEY_UP].longPressTimeOne != 0 )
- {
- if( Key[KEY_UP].pressedSec >= Key[KEY_UP].longPressTimeOne )
- {
-
- KeyUpLongPressedOne();
- Key[KEY_UP].softRelease = 1;
- }
- }
- }
- }
- Key[KEY_UP].onFlag = 1;
- Key[KEY_UP].pressTime++;
- }else{
- if( Key[KEY_UP].onFlag == 1 )
- {
- //printf("KEY_NUMUP_%d\r\n", (unsigned int)Key[0].pressTime);
- KeyUpReleased();
-
- }
- Key[KEY_UP].pressTime = 0;
- Key[KEY_UP].onFlag = 0;
- Key[KEY_UP].pressedSec = 0;
- Key[KEY_UP].softRelease = 0;
- Key[KEY_UP].prevTime = 0;
- }
- }
- void KeySelectPressed(void)
- {
- DBGPrint("KeySelectPressed\r\n" );
- }
- void KeySelectReleased(void)
- {
- DBGPrint("KeySelectReleased\r\n" );
- }
- void KeySelectLongPressedOne(void)
- {
- DBGPrint("KeySelectLongPressedOne\r\n" );
- }
- void KeySelectLongPressedKeep(void)
- {
- DBGPrint("KeySelectLongPressedKeep\r\n" );
- }
- void KeyUpPressed(void)
- {
- DBGPrint("KeyUpPressed\r\n" );
- }
- void KeyUpReleased(void)
- {
- DBGPrint("KeyUpReleased\r\n" );
- }
- void KeyUpLongPressedOne(void)
- {
- DBGPrint("KeyUpLongPressedOne\r\n" );
- }
- void KeyUpLongPressedKeep(void)
- {
- DBGPrint("KeyUpLongPressedKeep\r\n" );
- }
|