📄 py_interface.c
字号:
#include "CommonFunc.h"
#include "lcd701_functions.h"
#include "PY_IME.h"
#define PY_MAX_CHAR 6
#define HZ_PER_PAGE 8
//========================================================================
// 语法格式: unsigned char PY_GetSymbol(void)
// 实现功能: 通过按键获取符号,0~8以及#键分别对应:
// 0 1 2 3 4 5 6 7 8 #
// . , ? @ # * _- ' 1
// 按'n'或'*'键直接退出
// 参数: 无
// 返回值: 获取的符号
//========================================================================
const unsigned char Symbol_List[] = {
'.', ',', '?', '@', '#',
'*', 0xdfa3, '-', '\'',
};
unsigned char PY_GetSymbol(void)
{
unsigned char KeyCode;
LCD701_SetTextPos(2, 0);
LCD701_Print(" 0 1 2 3 4 5 6 7 8 #");
LCD701_Print(" . , ? @ # * _- ' 1");
while(1)
{
KeyCode = Key_GetCh();
if(KeyCode>='0'&&KeyCode<='8')
{
return Symbol_List[KeyCode-'0'];
}
else if(KeyCode=='#'||KeyCode=='y')
{
return '1';
}
else if(KeyCode=='n'||KeyCode=='*')
return '\0';
}
}
//========================================================================
// 语法格式: unsigned char PY_GetHZ(const T9PY_IDX *PY_Idx)
// 实现功能: 根据输入的拼音显示匹配的汉字列表,并由键盘选取汉字。
// 被PY_GetCh()函数调用
// 参数: 拼音索引地址
// 返回值: 获取的汉字编码
//========================================================================
unsigned char PY_GetHZ(const T9PY_IDX *PY_Idx)
{
unsigned int HZ_Remain=0;
unsigned int CurPageIdx;
unsigned int i=0, KeyCode, KeyEvent;
unsigned char HZ_Buf[HZ_PER_PAGE+1];
CurPageIdx = 0;
KeyEvent = 1;
while(1)
{
if(KeyEvent == 1)
{
HZ_Remain = T9PY_Ime(PY_Idx, CurPageIdx, HZ_PER_PAGE, HZ_Buf);
if(HZ_Remain==0xffff)return '\0';
i = 0;
LCD701_SetTextPos(2, 0);
LCD701_Print(" ");
if(CurPageIdx>=HZ_PER_PAGE)
LCD701_PutHZ("←");
else
LCD701_Print(" ");
LCD701_Print(" ");
if(HZ_Remain>0)
LCD701_PutHZ("→");
else
LCD701_Print(" ");
while(HZ_Buf[i] != '\0')
{
LCD701_SetTextPos(2, 2+(i<<1));
LCD701_PutChar('1' + i);
LCD701_SetTextPos(3, 2+(i<<1));
PrintPacked(HZ_Buf+i);
i++;
}
KeyEvent = 0;
}
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8':
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)
{
unsigned char Input_Buf[PY_MAX_CHAR+1]="";
T9PY_IDX *PY_List[10];
unsigned int i, j, KeyCode, PY_Count;
unsigned int KeyEvent;
unsigned int PY_CurIdx=0;
i = 0;
KeyEvent = 1;
PY_Count = 0;
while(1)
{
KeyCode = Key_GetCh();
switch(KeyCode)
{
case '2': case '3': case '4': case '5': // 2~9键输入拼音
case '6': case '7': case '8': case '9':
if(i<PY_MAX_CHAR)
{
Input_Buf[i++] = KeyCode;
KeyEvent = 1;
}
break;
case '1': // 1键输入符号
if(i==0)
return PY_GetSymbol();
else
break;
case '*': // *键退格
if(i>0)
{
Input_Buf[--i] = '\0';
KeyEvent = 1;
}
else
{
return '\b';
}
break;
case '#': // #键输入数字
if(i==1)
return Input_Buf[0];
else
break;
case '0': // 0键输入字母
if(i==0)
{
Input_Buf[i++] = '0';
KeyEvent = 1;
break;
}
else if(i==1)
return PY_List[PY_CurIdx]->PY[0];
else
break;
case 'u': // 选择前一项
KeyEvent = 2;
if(PY_CurIdx>0)
PY_CurIdx--;
else
PY_CurIdx=PY_Count-1;
break;
case 'd': // 选择后一项
KeyEvent = 2;
if(PY_CurIdx<PY_Count-1)
PY_CurIdx++;
else
PY_CurIdx = 0;
break;
case 'y': // 确定,显示汉字列表
if(PY_Count>0)
return PY_GetHZ(PY_List[PY_CurIdx]);
else
return '\n';
case 'n': // 取消
if(i>0)
{
i=0;
Input_Buf[i] = '\0';
KeyEvent = 1;
}
else
{
return '\b';
}
break;
default:
break;
}
//// 在LCD上显示输入法提示
if(KeyEvent)
{
Input_Buf[i] = '\0';
PY_Count = T9PY_GetPY(Input_Buf, PY_List);
if(KeyEvent==1)PY_CurIdx = 0;
LCD701_SetTextPos(2,0);
LCD701_Print(" ");
LCD701_Print(" ");
LCD701_SetTextPos(2,0);
if(*Input_Buf=='\0')
LCD701_PutHZ("拼");
else
LCD701_Print(Input_Buf);
LCD701_Print(":");
for(j=0; j<PY_Count; j++)
{
if(j==PY_CurIdx)
LCD701_PutChar('-');
else
LCD701_PutChar(' ');
LCD701_Print(PY_List[j]->PY);
if(j==PY_CurIdx)
LCD701_PutChar('-');
else
LCD701_PutChar(' ');
}
KeyEvent = 0;
}
}
}
//========================================================================
// 语法格式: 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;
LCD701_GetTextPos(&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';
LCD701_SetTextPos(DispX, DispY);
PrintPacked(StrBuf);
if(HZ_Code=='\b')LCD701_Print(" ");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -