📄 py_interface.c
字号:
//======================================================
// 文件名称: PY_Interface.c
// 功能描述: 输入法界面
// 维护记录: 2006-09-20 v1.0
//======================================================
#include "..\include\CommonFunc.h"
#include "..\include\splc501user.h"
#include "..\include\LCD_Chinese.h"
#include "..\include\PY_IME.h"
#define PY_MAX_CHAR 6
#define HZ_PER_PAGE 6
//========================================================================
// 语法格式: unsigned char PY_GetSymbol(void)
// 实现功能: 通过按键获取符号,0~8以及#键分别对应:
// 1 2 3 4 5 6 7 8 9 0 #
// . , ? ! @ * _ - ' #
// 按'n'或'*'键直接退出
// 参数: 无
// 返回值: 获取的符号
//========================================================================
const unsigned char Symbol_List[] = {
' ', '.', ',', '?', '!', '@',
'*', '_', '-', '\'', '#'
};
unsigned char PY_GetSymbol(void)
{
unsigned char KeyCode;
LCD501_SetPos(0, 32);
LCD501_Print("符: 1234567890#");
LCD501_SetPos(32, 48);
LCD501_Print(".,?!@*_-\' #");
while(1)
{
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return Symbol_List[KeyCode-'0'];
case '#':
return '#';
case '*': case 'n':
return '\b';
case 'u':
return -1;
case 'd':
return -2;
case 'y':
return '\n';
}
}
}
//========================================================================
// 语法格式: unsigned char PY_GetLetter(void)
// 实现功能: 通过按键获取英文字符
// 按'n'或'*'键直接退出
// 参数: 无
// 返回值: 获取的字符
//========================================================================
unsigned char PY_GetLetter(void)
{
unsigned char KeyCode, KeyBuf[2], KeyEvent=1;
unsigned int i, LetterCount=0;
PY_IDX Letter_List[9];
KeyBuf[1] = '\0';
while(1)
{
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
if(LetterCount==0)
{
KeyEvent = 1;
KeyBuf[0] = KeyCode;
LetterCount = PY_GetPY(KeyBuf, Letter_List);
}
else if(KeyCode-'0'<=LetterCount)
return Letter_List[KeyCode-'1'].PY[0];
break;
case '*': case 'n':
if(LetterCount==0)
return '\b';
else
{
KeyEvent = 1;
LetterCount = 0;
}
break;
case 'u':
return -1;
case 'd':
return -2;
case 'y':
return '\n';
}
if(KeyEvent)
{
KeyEvent = 0;
LCD501_SetPos(0, 32);
LCD501_Print("英: ");
LCD501_SetPos(0, 48);
LCD501_Print(" ");
for(i=0; i<LetterCount; i++)
{
LCD501_PutChar(32+i*12, 32, '1'+i);
LCD501_SetPos(32+i*12, 48);
LCD501_Print(Letter_List[i].PY);
}
}
}
}
//========================================================================
// 语法格式: unsigned char PY_GetNumber(void)
// 实现功能: 通过按键获取数字
// 按'n'或'*'键直接退出
// 参数: 无
// 返回值: 获取的数字ASCII码
//========================================================================
unsigned char PY_GetNumber(void)
{
unsigned char KeyCode;
LCD501_SetPos(0, 32);
LCD501_Print("数: 1234567890 ");
while(1)
{
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return KeyCode;
case '#':
return '#';
case '*': case 'n':
return '\b';
case 'u':
return -1;
case 'd':
return -2;
case 'y':
return '\n';
}
}
}
//========================================================================
// 语法格式: unsigned char PY_GetHZ(void)
// 实现功能: 根据输入的拼音显示匹配的汉字列表,并由键盘选取汉字。
// 被PY_GetCh()函数调用
// 参数: 拼音索引地址
// 返回值: 获取的汉字编码
//========================================================================
unsigned char PY_GetHZ(void)
{
unsigned int HZ_Remain=0;
unsigned int CurPageIdx;
unsigned int i=0, j, KeyCode, KeyEvent=1;
unsigned char HZ_Buf[HZ_PER_PAGE+1];
unsigned char PY_Buf[PY_MAX_CHAR+1];
PY_IDX PY_List[10];
unsigned int PY_Count=0, PY_CurIdx=0;
while(1) // 显示拼音列表
{
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '2': case '3': case '4': case '5': // 数字键输入拼音
case '6': case '7': case '8': case '9':
if(i<PY_MAX_CHAR)
{
PY_Buf[i++] = KeyCode;
KeyEvent = 1;
}
break;
case '*': // *键退格
KeyEvent = 1;
if(i>0)
{
PY_Buf[--i] = '\0';
}
else
return '\b';
break;
case 'u': // 选择前一项
if(i>0)
{
KeyEvent = 2;
if(PY_CurIdx>0)
PY_CurIdx--;
else
PY_CurIdx=PY_Count-1;
}
else
return -1;
break;
case 'd': // 选择后一项
if(i>0)
{
KeyEvent = 2;
if(PY_CurIdx<PY_Count-1)
PY_CurIdx++;
else
PY_CurIdx = 0;
}
else
return -2;
break;
case 'y': case '#': // 确定,显示汉字列表
if(PY_Count>0)
KeyEvent = 3;
else
return '\n';
break;
case 'n': // 取消
if(i>0)
{
i=0;
PY_Buf[i] = '\0';
KeyEvent = 1;
}
else
return '\b';
break;
default:
break;
}
if(KeyEvent==3) // 选定拼音则跳出,显示汉字列表
break;
else if(KeyEvent!=0) // 显示拼音列表
{
PY_Buf[i] = '\0';
PY_Count = PY_GetPY(PY_Buf, PY_List);
if(KeyEvent==1)PY_CurIdx = 0;
LCD501_SetPos(0, 32);
LCD501_Print(" ");
LCD501_Print(" ");
LCD501_SetPos(0, 32);
if(*PY_Buf=='\0')
LCD501_Print("拼");
else
LCD501_Print(PY_Buf);
LCD501_Print(":");
for(j=0; j<PY_Count; j++)
{
if(j==PY_CurIdx)
LCD501_SetPaintMode(PAINT_RECO);
else
LCD501_SetPaintMode(PAINT_COVER);
LCD501_Print(PY_List[j].PY);
LCD501_SetPaintMode(PAINT_COVER);
LCD501_Print(" ");
}
KeyEvent = 0;
}
}
CurPageIdx = 0; // 显示汉字列表
KeyEvent = 1;
while(1)
{
if(KeyEvent == 1)
{
HZ_Remain = PY_Ime(&PY_List[PY_CurIdx], CurPageIdx, HZ_PER_PAGE, HZ_Buf);
if(HZ_Remain==0xffff)return '\0';
i = 0;
LCD501_SetPos(0, 32);
LCD501_Print(" ");
if(CurPageIdx>=HZ_PER_PAGE)
LCD501_Print("←");
else
LCD501_Print(" ");
LCD501_Print(" ");
if(HZ_Remain>0)
LCD501_Print("→");
else
LCD501_Print(" ");
while(HZ_Buf[i] != '\0')
{
LCD501_PutChar(4+((1+i)<<4), 32, '1'+i);
i++;
}
LCD501_SetPos(16, 48);
LCD501_PrintPacked(HZ_Buf);
KeyEvent = 0;
}
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '1': case '2': case '3': case '4':
case '5': case '6':
if(KeyCode-'1'<i)
{
return HZ_Buf[KeyCode-'1'];
}
break;
case 'u':
if(CurPageIdx>=HZ_PER_PAGE)
{
CurPageIdx -= HZ_PER_PAGE;
KeyEvent = 1;
}
break;
case 'd':
if(HZ_Remain>0)
{
CurPageIdx += HZ_PER_PAGE;
KeyEvent = 1;
}
break;
case 'y':
return HZ_Buf[0];
break;
case 'n': case '*':
return '\0';
default:
}
}
}
//========================================================================
// 语法格式: unsigned int PY_GetCh(void)
// 实现功能: 通过键盘获取一个汉字或字符
// 参数: 无
// 返回值: 获取的汉字或字符编码
//========================================================================
unsigned int PY_GetCh(void)
{
static unsigned int IME_Mode = 0; // 输入法选择,0-汉字,1-英文,2-字符,3-数字
unsigned int Ret;
while(1)
{
switch(IME_Mode)
{
case 0:
Ret = PY_GetHZ(); // 输入汉字
break;
case 1:
Ret = PY_GetLetter(); // 输入字母
break;
case 2:
Ret = PY_GetSymbol(); // 输入符号
break;
case 3:
Ret = PY_GetNumber(); // 输入数字
break;
default:
break;
}
if(Ret == -1) // 选择前一输入法
{
if(IME_Mode==0) IME_Mode = 3;
else IME_Mode -= 1;
}
else if(Ret == -2) // 选择后一输入法
{
if(IME_Mode==3) IME_Mode = 0;
else IME_Mode += 1;
}
else
return Ret;
}
}
//========================================================================
// 语法格式: unsigned char *PY_GetString(unsigned char *StrBuf, unsigned char StrLen)
// 实现功能: 通过键盘获取一个字符串
// 参数: StrBuf: 字符串起始地址
// StrLen: 字符串的最大显示宽度(每个汉字宽度为2,字符的宽度为1)
// 返回值: 字符串的首地址
//========================================================================
unsigned char *PY_GetString(unsigned char *StrBuf, unsigned char StrLen)
{
unsigned int DispX, DispY, RemainStr, CharSize;
unsigned char *p_StrBuf;
unsigned char HZ_Code;
LCD501_GetPos(&DispX, &DispY);
p_StrBuf = StrBuf;
RemainStr = StrLen;
while(1)
{
HZ_Code = PY_GetCh();
CharSize = HZ_Code>0x00ff ? 2:1;
switch(HZ_Code)
{
case '\b':
if(p_StrBuf>StrBuf)
{
p_StrBuf--;
RemainStr += CharSize;
}
else
{
*p_StrBuf='\0';
return StrBuf;
}
break;
case '\n':
*p_StrBuf='\0';
return StrBuf;
case '\0':
break;
default:
if(RemainStr >= CharSize)
{
*p_StrBuf = HZ_Code;
p_StrBuf++;
RemainStr -= CharSize;
}
break;
}
*p_StrBuf = '\0';
LCD501_SetPos(DispX, DispY);
LCD501_PrintPacked(StrBuf);
if(HZ_Code=='\b')LCD501_Print(" ");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -