⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 51t9py.c

📁 嵌入式T9输入法的源代码
💻 C
字号:
#include <string.h>
#include <stdio.h>
#include "5py_mb.h"
#include "51t9py_indexa.h"
#include "gui.h"
#include "key.h"
#include "uCFS.h"


unsigned char t9_match_max;
T9INFO T9MatchTable[16];

unsigned char t9PY_ime(char *numInput)
{
	T9INFO *t9index, *t9infotableedge;
	unsigned char i,InputNumLength;

	t9_match_max = 0;								// 完全匹配组数
	InputNumLength = strlen(numInput);				// 输入拼音串长度
	GUI_DispDecAt(InputNumLength, 20, 120, 2 );
	if( *numInput=='\0' )							// 如果输入空字符返回0
		return(0);

	t9index         = &(T9InfoTable[0]);			// 查首字母索引
	t9infotableedge = T9InfoTable + sizeof(T9InfoTable)/sizeof(T9InfoTable[0]);
	while(t9index<t9infotableedge)					// 待查询记录条数
	{
		for(i=0;i<InputNumLength;i++)
		{
			if( *(numInput+i)!=*((*t9index).T9+i) )    //检查字符串匹配
			{
				break;								// 发现字母串不配,退出
			}
		}

		t9index++;
	}

	GUI_DispDecAt(t9_match_max, 100, 120, 2 );
	return (t9_match_max);							// 输出完全匹配组数,0为无果而终
}

typedef struct tagcommom {
	unsigned char t9py;
	unsigned char hz_table_size;
	unsigned char hz_table_position;
	unsigned char position;
	unsigned char num[16];
} COMMON;


COMMON common;
char chinese_word[3]="  ";

void t9PY_Test(void)
{
	unsigned char PYEnter=0;
	unsigned char temp;
	char i=0;
	T9INFO t9;
	unsigned char key ;

	common.hz_table_position = 0;
	common.num[0] = 0x00;
	common.position = 0;	// default
	t9PY_ime(common.num);		// clear

	GUI_Clear();
	GUI_DispStringAt("2-abc 3-def 4-ghi 5-jkl 6-mno 7-pqrs 8-tuv 9-wxyz", 20, 160);
	while(1)
	{
		key = GetKey();
		switch(key)
		{
			case KEY_LEFT:
				if(common.position>0)
					common.position--;
				break;
			case KEY_RIGHT:
				common.position++;
				if(common.position>=t9_match_max)
					common.position --;
				break;

			case KEY_UP:
				if(common.hz_table_position>=18)
					common.hz_table_position -= 18;
				break;
			case KEY_DOWN:
				if(common.hz_table_position<common.hz_table_size -18 )
					common.hz_table_position += 18;
				break;

			case KEY_ENTER:				// 输入状态和选字状态切换
				PYEnter = 1;
				break;

			default:
				break;
		}

		common.hz_table_size = strlen(T9MatchTable[common.position].hz_table)/sizeof(char);
		GUI_DispDecAt(common.hz_table_size, 20, 180, 2);

		if(PYEnter)
		{
			GUI_DispStringAt("选:", 20, 60);
			if( (key>='1')&&(key<='9') )
			{
				chinese_word[0] = *( t9.hz_table+common.hz_table_position+(key-'1')*2);
				chinese_word[1] = *( t9.hz_table+common.hz_table_position+(key-'1')*2+1);
				GUI_DispString(chinese_word);
				ClearKey();
				return;
			}
		}


		GUI_ClearRect(20, 20, 319, 20+20);
		GUI_DispStringAt("拼:",20, 20);
		for(temp=common.position;temp<t9_match_max;temp++)
		{
			GUI_DispString( T9MatchTable[temp].py );
		}

		GUI_ClearRect(20, 40, 319, 40+20);
		GUI_DispStringAt("字:", 20, 40);
		t9 = T9MatchTable[common.position];
		GUI_DispString( t9.hz_table+common.hz_table_position );
	}
}

void T9_Test(void)
{
	FS_FILE *t9file;

	t9file = FS_FOpen("t9file.txt","w");
	if(!t9file)
		return;

	while(1)
	{
		t9PY_Test();
		FS_FWrite(chinese_word,1,strlen(chinese_word),t9file);

		if( GetKey() == KEY_ESCAPE )
			break;
	}

	FS_FClose(t9file);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -