📄 rtd2533b_key.c
字号:
//----------------------------------------------------------------------------------------------------
// ID Code : Key.c No.0000
// Update Note :
//
//----------------------------------------------------------------------------------------------------
#define __RTD2533B_KEY__
#include "Common\Header\Include.h"
#if((_SCALER_TYPE == _RTD2533B) || (_SCALER_TYPE == _RTD2023L) || (_SCALER_TYPE == _RTD2023S) || (_SCALER_TYPE == _RTD2023L_VB) || (_SCALER_TYPE == _RTD2023S_VB))
//--------------------------------------------------
// Description : Key scan process
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyHandler(void)
{
// Clear the key message
ucKeyMessage = _NONE_KEY_MESSAGE;
if(CKeyScanReady())
{
// Store previous key state
ucKeyStatePrev = ucKeyStateCurr;
// Get current key state
ucKeyStateCurr = CKeyScan();
// Power key process, return if power key is pressed
if(CKeyPowerKeyProc())
return;
// Convert key state to key message, store in (ucKeyNotify)
CKeyMessageProc();
}
}
//--------------------------------------------------
// Description : Check power key process
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyCheckPowerKey(void)
{
// Store previous key state
ucKeyStatePrev = ucKeyStateCurr;
// Get current key state
ucKeyStateCurr = CKeyScan();
// Power key process
CKeyPowerKeyProc();
}
//--------------------------------------------------
// Description : Initial key status
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyInitial(void)
{
CLR_KEYSCANREADY();
CLR_KEYSCANSTART();
}
//--------------------------------------------------
// Description : Key scan ready process. We wait 0.02 sec in order to keep the keypad debounce
// Input Value : None
// Output Value : None
//--------------------------------------------------
bit CKeyScanReady(void)
{
if(GET_KEYSCANSTART() && GET_KEYSCANREADY())
{
return _TRUE;
}
else if(!GET_KEYSCANSTART())
{
// Wait 0.02 sec in order to keep the keypad debounce
SET_KEYSCANSTART();
CTimerReactiveTimerEvent(SEC(0.02), CKeyScanReadyTimerEvent);
return _FALSE;
}
else
{
return _FALSE;
}
}
//--------------------------------------------------
// Description : Key scan ready timer event
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyScanReadyTimerEvent(void)
{
SET_KEYSCANREADY();
}
//--------------------------------------------------
// Description : Key repeat enable timer event
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyRepeatEnableTimerEvent(void)
{
SET_KEYREPEATSTART();
}
//--------------------------------------------------
// Description : Key message translation
// Input Value : ucKeyMask --> Key mask
// ucKeyMsg --> Key message
// Output Value : None
//--------------------------------------------------
void CKeyMessageConvert(BYTE ucKeyMask, BYTE ucKeyMsg)
{
if((ucKeyStatePrev ^ ucKeyStateCurr) & ucKeyMask)
{
ucKeyMessage = ucKeyMsg;
}
else
{
if(GET_KEYREPEATENABLE())
{
if(GET_KEYREPEATSTART())
{
ucKeyMessage = ucKeyMsg;
}
else
{
CTimerActiveTimerEvent(SEC(_KEY_REPEAT_START_TIME),CKeyRepeatEnableTimerEvent);
}
}
}
}
//--------------------------------------------------
// Description : Power key process
// Input Value : None
// Output Value : Return _TRUE if power key is pressed
//--------------------------------------------------
bit CKeyPowerKeyProc(void)
{
if(ucKeyStateCurr & _POWER_KEY_MASK)
{
if((ucKeyStatePrev ^ ucKeyStateCurr) & _POWER_KEY_MASK)
{
CTimerDelayXms(25);
ucKeyStateCurr = CKeyScan();
if((ucKeyStatePrev ^ ucKeyStateCurr) & _POWER_KEY_MASK)
{
CKeyPowerKeyMix();
SET_POWERSWITCH();
return _TRUE;
}
}
}
return _FALSE;
}
//--------------------------------------------------
// Description : Get key status
// Input Value : None
// Output Value : Return Key status
//--------------------------------------------------
BYTE CKeyScan(void)
{
#if(_KEYPAD_TYPE == _KEYPAD_AD)
// This AD key's program is for RTD2120.
BYTE keystate = 0, voltage1 = 0, voltage2 = 0;
MCU_ADC_CTRL_FF0B = 0x80;
CTimerDelayXms(3);
voltage1 = (AD_KEY1 & 0xfc);
voltage2 = (AD_KEY0 & 0xfc);
if((0x00 <= voltage1) && (voltage1 < 0x14)) // RIGHT(0.00) 0.00 ~ 0.30
{
keystate = keystate | _LEFT_KEY_MASK;
}
if((0x4c < voltage1) && (voltage1 < 0x60)) // LEFT (1.55) 1 ~ 1.26 //1.45 ~ 1.65
{
keystate = keystate | _RIGHT_KEY_MASK;
}
if((0xa0 < voltage1) && (voltage1 < 0xb0)) // NONE (2.10) 2.1~2.3 //2.00 ~ 2.20
{
keystate = keystate | _RIGHT_KEY_MASK;
}
if((0x00 <= voltage2) && (voltage2 < 0x14)) // POWER(0.00) 0.00 ~ 0.30
{
keystate = keystate | _POWER_KEY_MASK;
}
if((0x4c < voltage2) && (voltage2 < 0x60)) // MENU (1.55) 1.45 ~ 1.65
{
keystate = keystate | _MENU_KEY_MASK;
}
if((0xa0 < voltage2) && (voltage2 < 0xc0)) // EXIT (2.10) 2.00 ~ 2.20
{
keystate = keystate | _EXIT_KEY_MASK;
}
if(keystate != 0)
CKeyInitial();
return keystate;
#endif // End of #if(_KEYPAD_TYPE == _KEYPAD_AD)
#if(_KEYPAD_TYPE == _KEYPAD_NORMAL)
BYTE keystate = 0;
if(!bRIGHT_KEY)
keystate = keystate | _RIGHT_KEY_MASK;
if(!bLEFT_KEY)
keystate = keystate | _LEFT_KEY_MASK;
if(!bEXIT_KEY)
keystate = keystate | _EXIT_KEY_MASK;
if(!bMENU_KEY)
keystate = keystate | _MENU_KEY_MASK;
if(!bPOWER_KEY)
keystate = keystate | _POWER_KEY_MASK;
if(keystate != 0)
CKeyInitial();
return keystate;
#endif // End of #if(_KEYPAD_TYPE == _KEYPAD_NORMAL)
}
//--------------------------------------------------
// Description : We can add some settings here while combo key with power key
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyPowerKeyMix(void)
{
switch(ucKeyStateCurr)
{
case _POWER_RIGHT_KEY_MASK:
ucOsdEventMsg = _ENTER_FACTORY_MODE_MSG;
break;
case _POWER_MENU_KEY_MASK:
break;
case _POWER_LEFT_RIGHT_KEY_MASK:
break;
}
}
//--------------------------------------------------
// Description : Convert keypad status into key message, stores in ucKeyNotify
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CKeyMessageProc(void)
{
switch(ucKeyStateCurr)
{
case _MENU_KEY_MASK:
CKeyMessageConvert(_MENU_KEY_MASK, _MENU_KEY_MESSAGE);
break;
case _RIGHT_KEY_MASK:
CKeyMessageConvert(_RIGHT_KEY_MASK, _RIGHT_KEY_MESSAGE);
break;
case _LEFT_KEY_MASK:
CKeyMessageConvert(_LEFT_KEY_MASK, _LEFT_KEY_MESSAGE);
break;
case _EXIT_KEY_MASK:
CKeyMessageConvert(_EXIT_KEY_MASK, _EXIT_KEY_MESSAGE);
break;
default:
CLR_KEYREPEATSTART();
CTimerCancelTimerEvent(CKeyRepeatEnableTimerEvent);
break;
}
}
#endif // End of #if((_SCALER_TYPE == _RTD2533B) || (_SCALER_TYPE == _RTD2023L) || (_SCALER_TYPE == _RTD2023S) || (_SCALER_TYPE == _RTD2023L_VB) || (_SCALER_TYPE == _RTD2023S_VB))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -