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

📄 tskmenu.c

📁 本人编写的无线电话程序,给予PIC18C801设计,包括了uCOS的移植以及菜单,自己设计的拼音注入法,完整地一级汉字库,希望对大家有所帮助
💻 C
📖 第 1 页 / 共 4 页
字号:
INT8U MFunc_LocalNumberSet(void){
	INT8U i,chrTemp,fhdl;
	F_LocalPara *plp;

	fhdl=file_open(localpara_file, &plp);
	for(;;){
		Do_Clear_Screen(2,0,3,127);
		CurPhoneNumLen = app_c2u(plp->SelfNum,6,CurPhoneNum);
		app_printf(CurPhoneNum,CurPhoneNumLen,2,0);
		Display_Menu_Icon(0,&PIC_EDIT);
		Display_Menu_Icon(1,&PIC_RETURN);
		Do_Clear_Screen(6,32,7,95);	//clear the menu index field
		switch(MFunc_WaitForInput(0)){
			case 0xff:
				return(1);
			case KEY_FUNC1:	//Enter 
				CurPhoneNumLen = app_c2a(plp->SelfNum,6,CurPhoneNum);
				chrTemp=EnterPhoneEdit();
				if(chrTemp == 0){//exit because of cancel
				}
				else if (chrTemp == 2){//exit because of enter
					if(CurPhoneNumLen > 12) CurPhoneNumLen = 12;
					app_a2c(CurPhoneNum, CurPhoneNumLen, plp->SelfNum);
					file_save(fhdl, offsetof(F_LocalPara, SelfNum[0]),sizeof(plp->SelfNum));
				}
				else{//exit because of MSG_MENU_CANCEL message
					CurMenu=MENU_ROOT;
					MenuDisplayKey(CurMenu);
					Do_Clear_Screen(6,32,7,95);	//clear the menu index field
					return(1);
				}
				break;
			case KEY_FUNC2:	//Cancel
				return(0);
			case KEY_C:		//Cancel
				return(0);
		}
	}
}



void Func_DisplaySmallIndex (INT8U Index){//max number is "99"
	Index = Index%100;
	Disp_Word(6,58, 0xd41e+(Index/10),PIX6);
	Disp_Word(6,64, 0xd41e+(Index%10),PIX6);
}

//=========================================================================================
//显示拼音字母
void MenuDisplayPinYin(unsigned char arrow)
{
	INT8U i,PosY;

	PosY=40;
	for(i=0;i<CurInputCharsLen;i++){
		(void)Disp_Word(6,PosY,(INT16U)(CurInputChars[i]),PIX8);
		PosY+=8;
	}
	PosY=88;
	if(arrow==3)
		(void)Disp_Word(6,PosY,'>',PIX8);
	else if(arrow==5)
		(void)Disp_Word(6,PosY,'<',PIX8);
	else if(arrow==7)
		(void)Disp_Word(6,PosY,'=',PIX8);
}	

	

//-----------------------------------------------------------------------------------------
// Function of Editing Phone_Number
// Previous step1: assign INT16U CurPhoneNum[], INT8U CurPhoneNumLen;
// Previous stop2: assign INT16U *CurText,INT8U CurTextLen,CurTextIstPos=0xFF
// Return: 0--Normal("return" or "Cancel" key);  1--Force to(should return to MENU_ROOT)
//         2--Return after operation(e.g. after save)
// Used when: MENU_ROOT: "Number_keys" pressed.
//            Check Call_Record: "Save_Key" pressed.
// After function called:  The screen should be processed.

INT8U EnterPhoneEdit(void)
{
	INT8U retval;
	INT8U err;
	INT8U tmpkey;
	
	// display phone number at first

	Do_Clear_Screen(2,0,5,127);
	Do_Clear_Screen(6,32,7,95);	//clear the menu index field
	if(CurPhoneNumLen>0){
		MenuDisplayPhone(2,CurPhoneNumLen,CurPhoneNum);
		Disp_Word(2,CurPhoneNumLen*6,'_',PIX8);				//显示光标0x005F(CurPhoneNumLen * 6)
	}
	else{
		app_printf(TextQPhoneNum,3,4,0);
	}
	Display_Menu_Icon(0, &PIC_ACKNOWLEDGE);				//这里是否用“保存”更好呢?
	Display_Menu_Icon(1, &PIC_RETURN);

	for(;;){
		retval=0xFF;									//0xFF -- don't return
		tmpkey=MFunc_WaitForInput(0);
		switch(tmpkey){
			case 0xFF:
				return(1);

			case KEY_FUNC1:		//Enter 
				if(CurMenu==MENU_BOOK_END){
					retval=EnterTextEdit();
					//如果返回值是2,则需要保存电话号码及姓名
				}
				else
					retval=2;
				break;
			
			case KEY_FUNC2:		//Cancel
				retval=0;
			break;

			case KEY_C:			//BackSpace
				if(CurPhoneNumLen>0){
					CurPhoneNumLen--;

					Do_Clear_Screen(2,0,3,127);

					MenuDisplayPhone(2,CurPhoneNumLen,CurPhoneNum);
					Disp_Word(2,CurPhoneNumLen*6,'_',PIX8);				//显示光标0x005F(CurPhoneNumLen * 6)
				}
				break;
					

			default:
					if(tmpkey<='9' && tmpkey>='0'){
		   				if(CurPhoneNumLen<20){											//May be <20 if PIX6
		   					CurPhoneNum[CurPhoneNumLen++]=tmpkey;	//((MSG_KEYPRESS *)pMsg)->Key;

							if(CurPhoneNumLen==1)
								Do_Clear_Screen(4,0,5,127);

								MenuDisplayPhone(2,CurPhoneNumLen,CurPhoneNum);
								Disp_Word(2,CurPhoneNumLen*6,'_',PIX8);				//显示光标0x005F(CurPhoneNumLen * 6)
						}
					}
				break;
		}
		if(retval!=0xFF)
			return(retval);
	}
}			

			

//Text Edit function
//Before this function is called,"INT16U *CurText","INT8U CurTextIstPos" and "INT8U CurTextLen" should be assigned value.
//return: 0--normal("cancel" or "return(soft)" key);   1--force to return(hook-off);   2--return after operation(i.e. "save" )
//调用场合:编辑电话本时(新建或修改)或编辑短信(新建或修改)
//函数返回时未处理显示屏!文本数据还在RAM中,需调用者进一步处理或保存,特别是返回值为2时。
INT8U EnterTextEdit(void)
{
	INT8U 		i,retval;
	rom INT8U 	*pSml;
	INT8U		tmpkey,tmpval;
	INT8U 		err;
	
	//进入函数时,首先显示已有的文本
	CurTextIstPos=0xFF;

	Do_Clear_Screen(2,0,5,127);
	Do_Clear_Screen(6,32,7,95);	//clear the menu index field

		if(CurTextLen>0)
			MenuDisplayText();
		else if(CurMenu==MENU_BOOK_END){
			app_printf(TextQName,3,4,0);
		}
		Display_Menu_Icon(0, &PIC_ACKNOWLEDGE);
		if(CurInputMethod==PINYIN)
			Display_Menu_Icon(1, &PIC_PINYIN);
		else if(CurInputMethod==ENGLISH)
			Display_Menu_Icon(1, &PIC_ENGLISH);
		else
			Display_Menu_Icon(1, &PIC_SYMBOL);

	CurInputCharsLen=0;						//此变量用于拼音输入
	CurLineNo=0;							//此行可能无必要
	LetterLinePos=0;						//当前字母或数字位置(英文输入)
											//或当前显示首个汉字的序号(如果只有一屏,则为0;两屏,则为MAX_DISP_HANZI_SEL)
	HanZiSelNum=0;							//供选择的汉字的个数
	PrevKey=0x00;							//上次按的键(ASCII码)
	MenuTimerRunning=0;						//定时器是否在运行。(英文输入)
	CurInputCase=LOWER_CASE;				//大小写
	HanZiSel=0;								//汉字正待选择
	tmpval=GetPYNode(0xFF);

	for(;;){
		tmpkey=MFunc_WaitForInput(MenuTimerRunning);
		
		switch(tmpkey){
		case 0xFF:					//Direct message: MSG_MENU_CANCEL
			return(1);
		case 0xFD:					//MSG_TIMER_EXPIRE:TIMER_ENGLISH_INPUT_ID
			if(CurInputMethod==ENGLISH){
				if(CurTextIstPos==0xFF)
					CurText[CurTextLen++]=pLetterLine[LetterLinePos];
				else{
					for(i=CurTextLen;i>CurTextIstPos;i--)
						CurText[i]=CurText[i-1];
					CurText[CurTextIstPos++]=pLetterLine[LetterLinePos];
					CurTextLen++;
				}
						
				Do_Clear_Screen(2,0,5,127);

				MenuDisplayText();
				PrevKey=0x00;						//这样,使得当key==PrevKey时,肯定是在连续按某键
			}
			MenuTimerRunning=0;
			break;
			
		case KEY_FUNC1:		//enter_key
			return(2);
					
		case KEY_FUNC2:		// PINYIN-->ENGLISH-->SYMBOL-->PINYIN...
			if(CurInputMethod==ENGLISH){
				CurInputMethod=SYMBOL;
				CurLineNo=0;
				if(MenuTimerRunning){	//Stop timer
					MenuTimerRunning==0;
				}
			}
			else if(CurInputMethod==SYMBOL){
				CurInputMethod=PINYIN;
				CurLineNo=0;
				HanZiSel=0;
				CurInputCharsLen=0;
				tmpval=GetPYNode(0xFF);
			}
			else if(CurInputMethod==PINYIN){
				CurInputMethod=ENGLISH;
				CurLineNo=0;
				CurInputCase=LOWER_CASE;
				PrevKey=0;
				LetterLinePos=0;
			}
					
			Do_Clear_Screen(4,0,5,127);
			Do_Clear_Screen(6,32,7,95);	//clear the menu index field
			if(CurInputMethod==SYMBOL)
				app_printf(MenuEditSymbol[0],8,4,0);
			if(CurInputMethod==ENGLISH)
				Display_Menu_Icon(1,&PIC_ENGLISH);
			else if(CurInputMethod==SYMBOL)
				Display_Menu_Icon(1,&PIC_SYMBOL);
			else if(CurInputMethod==PINYIN)
				Display_Menu_Icon(1,&PIC_PINYIN);
			else
				Display_Menu_Icon(1,&PIC_WAITING);
			break;

		case KEY_C:		//backspace
			if(CurTextLen==0 && (CurInputCharsLen==0 && HanZiSel==0))
				return(0);
			if(CurInputMethod==PINYIN){
				if(HanZiSel==0 && CurInputCharsLen>0){	//还未开始选取汉字,并且已有拼音字母
					tmpval=GetPYNode(tmpkey);							//CurInputCharsLen--;

					Do_Clear_Screen(4,0,5,127);
					Do_Clear_Screen(6,32,7,95);	//clear the menu index field

					MenuDisplayPinYin(tmpval);	//display PinYin
				}
				else if(HanZiSel==1){				//正在选取汉字
					tmpval=GetPYNode(0xFF);			//CurInputCharsLen=0;
					HanZiSel=0;

					Do_Clear_Screen(4,0,5,127);
					Do_Clear_Screen(6,32,7,95);	//clear the menu index field

				}
				else if(CurTextLen>0 && CurTextIstPos!=0){				//还未选取汉字,并且无拼音字母
					if(CurTextIstPos!=0xFF){
						for(i=CurTextIstPos;i<CurTextLen;i++)
							CurText[i-1]=CurText[i];
						CurTextIstPos--;
					}
					CurTextLen--;
					if(CurTextLen==0)
						CurTextIstPos=0xFF;

					Do_Clear_Screen(2,0,3,127);
					MenuDisplayText();
				}
			}
			else if(CurTextLen>0 && CurTextIstPos!=0){
				if(CurTextIstPos!=0xFF){
					for(i=CurTextIstPos;i<CurTextLen;i++)
						CurText[i-1]=CurText[i];
					CurTextIstPos--;
				}
				CurTextLen--;
				if(CurTextLen==0)
					CurTextIstPos=0xFF;
				Do_Clear_Screen(2,0,3,127);
				MenuDisplayText();
			}
			break;
				
				case KEY_UP:			//page_up
					if(CurInputMethod==SYMBOL && CurLineNo>0){
						CurLineNo--;

						Do_Clear_Screen(4,0,5,127);

						(void)app_printf(MenuEditSymbol[CurLineNo],8,4,0);
					}
					else if(CurInputMethod==PINYIN && LetterLinePos>=MAX_DISP_HANZI_SEL && HanZiSel==1){	//并且前面有汉字
						LetterLinePos-=MAX_DISP_HANZI_SEL;

						Do_Clear_Screen(4,0,5,127);

						(void)app_printf(&pLetterLine[LetterLinePos],MAX_DISP_HANZI_SEL,4,0);
					}
					else if(CurInputMethod==PINYIN && HanZiSel==0 && CurInputCharsLen>0){
						tmpval=GetPYNode(tmpkey);
						Do_Clear_Screen(4,0,5,127);
						Do_Clear_Screen(6,32,7,95);	//clear the menu index field
						MenuDisplayPinYin(tmpval);	//display PinYin
					}
					else if((CurInputMethod==ENGLISH && MenuTimerRunning==0)||
									(CurInputMethod==PINYIN && HanZiSel==0 && CurInputCharsLen==0)){
						if(CurTextIstPos!=0 && CurTextLen>0){
							if(CurTextIstPos==0xFF)
								CurTextIstPos=CurTextLen-1;
							else
								CurTextIstPos--;
							Do_Clear_Screen(2,0,3,127);
							MenuDisplayText();
						}
					}
				break;

				case KEY_DOWN:					//page_down
					if(CurInputMethod==SYMBOL && CurLineNo<2){
						CurLineNo++;
						Do_Clear_Screen(4,0,5,127);
						(void)app_printf(MenuEditSymbol[CurLineNo],8,4,0);
					}
					else if(CurInputMethod==PINYIN && (HanZiSelNum>LetterLinePos+MAX_DISP_HANZI_SEL) && HanZiSel==1){	//并且后面有汉字
						LetterLinePos+=MAX_DISP_HANZI_SEL;
						tmpval=(HanZiSelNum-LetterLinePos)>MAX_DISP_HANZI_SEL ? MAX_DISP_HANZI_SEL: (HanZiSelNum-LetterLinePos);

						Do_Clear_Screen(4,0,5,127);

						(void)app_printf(&pLetterLine[LetterLinePos],tmpval,4,0);
					}
					else if(CurInputMethod==PINYIN && HanZiSel==0 && CurInputCharsLen>0){
							tmpval=GetPYNode(tmpkey);

							Do_Clear_Screen(4,0,5,127);

⌨️ 快捷键说明

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