📄 key.c
字号:
{
return( FF_Key_Tabl[key_code] );
}
word TS_Key_Get(word key_code)
{
if((key_code %VRT_KEY_NUM) < LEFT_KEY_NUM )//左界面按键
{
key_code = (key_code/VRT_KEY_NUM)*LEFT_KEY_NUM + (key_code%VRT_KEY_NUM);
if((key_code/LEFT_KEY_NUM > 2)&&(CurrMode != XREPORT)&&(CurrMode != ZREPORT))
return KD_NULL;
return Ts_Left_keyMap[key_code];
}
else //右界面
{
return Ts_Key_Tab[(key_code/VRT_KEY_NUM)*LINE_KEY_NUM + (key_code%VRT_KEY_NUM - LEFT_KEY_NUM)];
}
}
byte TS_Key_Size_Get(word *logic_code, byte *Size_tabl)
{
while(*logic_code %LINE_KEY_NUM >0)//横向值为0, 向左查找到一个横向非0 的位置
{
if(((Size_tabl[*logic_code])&0x0f) != 0)
break;
(*logic_code)--;
}
while(*logic_code/LINE_KEY_NUM >0)
{
if(((Size_tabl[*logic_code])&0xf0) != 0)
break;
(*logic_code) -= LINE_KEY_NUM;
}
return Size_tabl[*logic_code];
}
/*--------------------------------------------------*
* 通过按键的逻辑位置返回按键的ID
* key_code 的范围: 0~39
*
*--------------------------------------------------*/
byte TS_Btn_ID_Get(word key_code)
{
if(key_code/LEFT_KEY_NUM == 0)
return BUF_ID_TL_TITLE;
else if(key_code == LEFT_KEY_NUM+1)
return KD_UP_TEXT;
else if(key_code == LEFT_KEY_NUM)
return PGUP_TEXT;
else if(key_code == LEFT_KEY_NUM+3)
return PGDN_TEXT;
else if(key_code == LEFT_KEY_NUM+2)
return KD_DOWN_TEXT;
else if(key_code/LEFT_KEY_NUM < HORI_KEY_NUM-2)
return BUF_ID_LCD_TEXT;
else if(key_code/LEFT_KEY_NUM < HORI_KEY_NUM-1)
return BUF_ID_TL_SUB;
else
{
if((CurrMode == XREPORT)||(CurrMode == ZREPORT))
{
if(key_code%LEFT_KEY_NUM < 2)
return CLR_RPT_TEXT;
else
return PRN_RPT_TEXT;
}
else
return BUF_ID_TL_INPUT;
}
return 0xff;
}
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
/* Function : Keyboard ring buffer set */
/* 将检测到的键值存入缓冲区 */
/* Create 03-8-14 11:21 by X.C.Zheng */
/* TS 存放的是1~100的逻辑位置 */
/* POS 存放的是 0x80~ 0xff 的逻辑键值 */
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
void key_rngset(word work)
{
static word tmp = KEY_END;
static const word *key_table;
if (0)//(skip_null_key)
{
if (Lcd_Mode_Int == LCD_10_INCH)
{
if (work >= TS_LOGI_OFFSET)
{
tmp = ts_get_logi(work);
key_table = Ts_Key_Tab;
tmp = key_table[tmp];
if (tmp == KD_NULL || tmp == KD_NULL_TS) /* The null key, return */
return;
}
}
else
{ // Lcd_Mode_Int == LCD_7_INCH
if (work >= TS_LOGI_OFFSET)
{
tmp = ts_get_logi(work);
key_table = Ts_Key_Tab;
tmp = key_table[tmp];
if (tmp == KD_NULL || tmp == KD_NULL_TS) /* The null key, return */
return;
}
}
}
if (((Khead + 1) % KEY_BUFF_SIZE) != Ktail) /* Key buffer not full */
{
KeyBuffer[Khead] = work;
Khead = (Khead + 1) % KEY_BUFF_SIZE;
}
if(MainMode != X_OFF) /* Not in the lock mode */
{
if ( bellcnt != 0xFF ) /* Not the long bell */
bellcnt = 30;
g_LCDBLCnt = 1000*sysflag->LCD_BL_Time; /* If press a key, set the LCD backlight time again */
}
}
/******************************************************************************
* Describe: Keyboard scan ISR
* Input : void
* Output: void
* return: void
* For every 5 mSeconds interval interrupt.
* 03-8-14 11:26
* 由于现在不支持小键盘,所以只保留了控制锁扫描部分
* Modified by Analy 2006-07-27
******************************************************************************/
#pragma INTERRUPT/E KeyScan
void KeyScan(void)
{
word chk;
word work;
word j;
key_scan_buf[0] = KEY_INPUT_PORT ^ 0xFF;
k_digit = 0;
CTL_KEY_SCAN = 0;
if(sysflag->soft_lock_flag == 0) /* Not use the soft control lock */
currmodeInt = key_scan_buf[0]; /* Control lock position check and save */
#ifdef SCANNER /* Support the scanner function */
{
void Sc_Scan(void);
static BYTE cntr = 0;
if ( cntr ++ >= 12 )// 每12个周期扫描一次条码缓冲区, 看看是否有条码读入
{
cntr = 0;
Sc_Scan();
}
}
#endif /* End SCANNER */
if (bellsub)
{
bellsub--;
}
else
{
if ( bellcnt != 0 )
{
bellsub = 3;
if ( bellcnt != 0xFF ) bellcnt --;
BuzzerOn();
}
else
{
BuzzerOff();
}
}
return;
if (PS2_ChkKeyIn(&work) == OK)
{
key_rngset(work);
}
}
void InitBuzzer(void)
{
BUZZER_DIR = 1;
BuzzerOff();
}
/******************************************************************************
* Describe: Initial Keyboard scan port and timer.
* Input : void
* Output: void
* return: void
******************************************************************************/
void InitialKey(void)
{
// initial key scan and read port
KEY_INPUT_DIR = 0x00; // input
prc2 = 1; /*Enable change the directory of Port 9*/
CTL_KEY_SCAN_DIR = 1;
pur3 = 0xFF;
BUZZER_DIR = 1; // output
CloseBuzzer();
// initial key scan variable before start key scanning
Khead = Ktail = 0;
key_off = 1;
k_digit = 0;
key_wka = 0xFF;
key_wkb = 0xFF;
bellcnt = 0;
ta3mr = 0x40; // f8, disable gate, timer mode
ta3 = 1.5 * 1000 * FOSC / 8; // 10M xtal, 800ns * 1250 * 3 = 3 ms
ta3ic = 0x03;
ta3s = 1; // Start timer A3
InitBarCode();
Rst_Ts_Key();
}
/*****************************************************************************
* Check the key ring buffer whether it is empty.
*
* TRUE -- there is some keys in buffer.
* FALSE -- for no keys.
*
*****************************************************************************/
byte Key_Poll_Chk(void)
{
if ( Khead == Ktail )
return(FALSE);
else
return(TRUE);
}
/*--------------------------------------------------------------------------*
* Clear the key buffer
*--------------------------------------------------------------------------*/
void Clr_Key_Buff(void)
{
disint();
Khead = Ktail = 0;
enint();
#ifdef SCANNER /* Support the scanner function */
SC_ClrFlag();
#endif /* End SCANNER */
}
/*-----------------------------------------------------------------------*
* Check the key buffer contain the key code or not.
* When call this function, will clear the key buffer
* at the same time.
*-----------------------------------------------------------------------*/
byte Key_Buff_Chk(word key_code)
{
while(Key_Poll_Chk() == TRUE)
{
if(GetKey() == key_code)
{
Clr_Key_Buff();
return (OK);
}
}
return (NG);
}
/* Make a virtual key in the key buffer */
// Note: When the FF_Key_Tabl table inexist this key, this function will do none.
void Make_Virtual_Key(word key_code)
{
word i;
i = key_logi_get(Ts_Key_Tab, key_code, MAX_KEY_CNT);
//i = key_logi_get(FF_Key_Tabl, key_code, MAX_KEY_CNT);
if(i == KD_END)
return;
if(((Khead + 1) % KEY_BUFF_SIZE) != Ktail) /* Key buffer not full */
{
KeyBuffer[Khead] = key_logic[i]<<8;
Khead = (Khead + 1) % KEY_BUFF_SIZE;
}
}
/* Get the scan control lock */
word Get_Scan_Lock(void)
{
return (CTL_KEY_SCAN);
}
/* Sure judged by the phisics position key */
byte Phy_Sure(void)
{
word phy_key;
DEBUG_SET(
return OK;
)
while(1)
{
while(KBPress() == 0);
phy_key = KBCheck();
Clr_Key_Buff();
#if KB == KB_59N24
if(phy_key == 0x41) /* SUBTTL */
return (OK);
else if(phy_key == 0x39) /* SUBTTL */
return (OK);
else if(phy_key == 0x50)
return (NG);
#elif KB == KB_38
if(phy_key == 0x1f) /* SUBTTL */
return (OK);
else if(phy_key == 0x02)
return (NG);
#else
#endif
}
return NG;
}
//inline void OpenBuzzer(void)
//{
// BUZZER = 1;
//}
//
//inline void CloseBuzzer(void)
//{
// BUZZER = 0;
//}
/* Changed the logical position key */
void Modi_Key(word logi_posi, word key_code, byte flag)
{
if(flag == 0)
FF_Key_SaleMain_Tabl[logi_posi - 1] = key_code;
else //flag == 1
FF_Key_HardPLU_Tabl[logi_posi - 1] = key_code;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -