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

📄 uinew.c

📁 这个是单片机4200的ui程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
*         Copyright (c) 2006 Primax Corporation,Ltd. All rights reserved.
*
* Author:            Junny Fu
*
* Description:       
*
* Revision History:
* Date      Author   Description

 * 2006-08-08	Cellming.Chen	Trim this routine

******************************************************************************/
#include "sys.h"
#include "Nucleus.h"
#include "syt.h"
#include "time.h"
#include "Standard.h"
#include "Uinew.h"
#include "Ui.h"
#include "Smfm.h"
#include "Uilcdnew.h"
#include "Uifax.h"
#include "Menu.h"
#include "Startup.h"
#include "Bios.h"
#include "Nvflash.h"
#include "Usbpanel.h"
#include "RTC.h"
#include "Memmgr.h"
#include "Errorcode.h"
#include "toner.h"
#include "Message.h"
#include "ts.h"
#include "Fireregs.h"
#include "speaker.h"
#include "pfhmgr.h"

#include "../fax/Oswrap.h"
#include "../fax/faxjob.h"
#include "../fax/faxphonebook.h"

#include	"../scanner/share/Primax_ADF.h"
#include "../scan/share/scancmd.h"

static Uint32     	gUIMainStack[UI_STACK_SIZE/sizeof(Uint32)];
Uint32			tempp[10];//temporary	//for system buffer //Junny
NU_TASK           	gMainUITask;			// Job manager task

MFPSETTING		gMFPSettingNvram;
UIMaintain		gUIMain;
MENUDATA		gMenudata;
P_MENUDATA		gpMenudata;
Bool 			setconfirm;
NU_SEMAPHORE 	gDateTimeSem;
NU_QUEUE		gErrorQueue;
Uint32             gQueueStart[ERROR_QUEUE_SIZE];

Uint32  tKbNow, tKbStart, tKbTimeout=8000;
Uint8     press_and_hold = 0;
char     quickfaxbuf[32];
Bool    password = FALSE;
Bool    diagnosismode = FALSE;
Bool    updateLCD = FALSE;
//Bool    firsttimedisplay = TRUE;
Bool    TimeOutFlag = FALSE;
Bool	   ResetTimeFlag = FALSE;
Bool    defaultset = FALSE;
Bool    DiagnosticMode = FALSE;
UI_State	laststate = SYSTEMINITIAL;
Uint8 factorycount = 0;
Uint8 copypage;//faxbutton

//sPhoneBookDial info[PHONE_RECORD_MAX];

char firstlinebuf[LINE_BUF_LENGTH],secondlinebuf[LINE_BUF_LENGTH];
char faxlayerfirstlinebuf[LINE_BUF_LENGTH],faxlayersecondlinebuf[LINE_BUF_LENGTH];
extern    	char  	inputbuf[DIAL_NUMBER_MAX+1];
extern	Bool    	newnumber;
extern	Bool		curjump;
extern     Uint8 	inputindex;
extern	Uint8	presscount;
extern	Uint8	curindex;
extern	DateTimeSct	datetime;
extern 	Uint16 	utemp;
extern	Bool		modechange;
extern	Uint8	step;
extern	P_PHONEBOOKRECORD	 phonelist;
extern     UI_Panel_Button 	lastbutton;
extern	Uint16	phonebookindex;
extern 	Uint16 utemp;
extern	Bool delperson;
extern	FAX_MAINTENANCE	FaxMaintenanceSetting;
extern	PHONEBOOK	phonebook;
extern	sFaxCommJob *waitingCommJob;
extern	ErrorState	errorstate;
extern	char inputbuf2[5];
extern	Uint16 errmsgdispcnt;
extern 	Bool    copyparaerr;

//#define	PAPER_TEST_

extern API_RET UIDoCopyJob(BOOL bColor);
extern API_RET UIDoScanJob(void);
extern API_RET UIDoCancelJob(void);

//-------------add by sky---------- 
extern unsigned char PanleState;
extern unsigned char FCTMode;
//-------------add by sky---------- 

API_RET UIMain()
{
	STATUS status;

	status = NU_Create_Task(&gMainUITask, 
						"UserMainTask", 
						UIMaintask, 
						0, 
						NU_NULL, 
                  				gUIMainStack, 
                  				UI_STACK_SIZE, 
                  				PRIORITY_UserMainTask,//PRIORITY_NORMAL, 
                  				BASE_TIMESLICE, 
                  				NU_PREEMPT, 
                  				NU_START);

/*	status = TASKCREATE(UIMaintask,
						UI_STACK_SIZE,
						gUIMainStack,
						NULLDATA,
						STATUS_LO_PRIORITY,
						NULLARG,
						"UserMainTask"); 
*/
	if (NU_SUCCESS != status)
   	{
      		/* Fail to create Copy App. Queue, log some error info. here */
		PSPRINTF("UI task Create fail\n");
      		return(API_FAIL);  
   	}

	status = NU_Create_Semaphore(&gDateTimeSem, "Datetime", 1, NU_FIFO);
   	if (status != NU_SUCCESS)
   	{
   		PSPRINTF("Date Time Semaphore Create fail\n");
      		return(API_FAIL);  
   	}
/*
	status = NU_Create_Semaphore(&gDataSem, "Data", 1, NU_FIFO);
   	if (status != NU_SUCCESS)
   	{
   		PSPRINTF("Data Semaphore Create fail\n");
      		return(API_FAIL);  
   	}
*/
	status = NU_Create_Queue(&gErrorQueue, "Error Queue", gQueueStart, ERROR_QUEUE_SIZE, 
		NU_FIXED_SIZE, ERROR_QUEUE_MESSAGE_SIZE, NU_FIFO);
	if (status != NU_SUCCESS)
   	{
   		PSPRINTF("Error Queue Create fail\n");
      		return(API_FAIL);  
   	}
	
	return API_OK;
}

void UIMaintask(UNSIGNED argc, void *argv)
{
	API_RET bReturnStatus;

	Uint16 buttoncurrent;
//	Uint32 taskstarttime,taskendtime,tasktime;

	InitRTC();
	NU_Sleep(1000);
	UIGetUserDefault();
	
//	UIHdwInit();

	bReturnStatus = LCDInit();
	while(bReturnStatus != API_OK)
	{
		NU_Sleep(200);
  	}
	
	//UI_ExecuteInit(); //add by shaohua
	MenuDataInit();
	MenuListInitSet(COPY_IDLE);
	UpdateLCD();

	while(1)
	{
//		taskstarttime = TaskGetSystemMilliTicks();
		buttoncurrent = UIGetKey();
		if( buttoncurrent != PANEL_NONE&& gUIMain.UIstate != SYSTEMINITIAL)
			{
				PSPRINTF("press button code %d\n", buttoncurrent);
				updateLCD = TRUE;//PSPRINTF("\ncall6\n");
				ResetTimeFlag = TRUE;
				if(gUIMain.PowerSavEnable)
					{
					gUIMain.PowerSavEnable = FALSE;
					//gUIMain.UIstate = STANDBY;
					errorstate.enginestate = ENGINEWARMUP;
					ReturnFromPowerSave();
					}
				else
					{
					if(gUIMain.commonsetting.Pressvolume == 1)
						SpeakerSoundPlay(SOUND_OF_KEYPAD);
					UIButtonProcess(buttoncurrent);					
					gUIMain.TimeOutTimerEnable = TRUE;
					}
			}
		//if a delay job present, prompt up on LCD periodically at STANDBY mode
		//if(!gUIMain.FaxlayerEnable)
		ErrorDetection();		
		if(gUIMain.FaxlayerEnable&&errorstate.enginestate == ENGINEREADY&&errorstate.adfstate == ADFREADY
			&&errorstate.scannerstate == SCANNERREADY&&errorstate.faxstate == FAXREADY)
			{
			ResetTimeFlag = TRUE;
			if(gUIMain.PowerSavEnable)
				{
				gUIMain.PowerSavEnable = FALSE;
				gUIMain.UIstate = STANDBY;
				ReturnFromPowerSave();
				}
			}
		if(ResetTimeFlag)
			{
			gUIMain.LastTime = TaskGetSystemMilliTicks();
			ResetTimeFlag = FALSE;
			}
		UIStateDisplay();
		TimeOutDetection();
		
		if(TimeOutFlag)
			{
			UIButtonProcess(PANEL_CANCEL);
			UpdateRam();
			updateLCD = TRUE;
			TimeOutFlag = FALSE;
			}
		if(gUIMain.PowerSavEnable)
			updateLCD = FALSE;
		if (updateLCD)//&&errorstate.enginestate != ENGINEWARMUP)
			{
			//PSPRINTF("\ncall99\n");
				UpdateLCD();				
				updateLCD = FALSE;
			}
//		taskendtime = TaskGetSystemMilliTicks();
//		tasktime = taskendtime - taskstarttime;
//		PSPRINTF("UI task time %dminisec\n", tasktime);
		NU_Sleep(20);
	}

}

void TimeOutDetection()
{
	Uint32 uCurTime;
	Uint32 powertime,standbytime;

	uCurTime = TaskGetSystemMilliTicks();
	powertime = GetPowerSaveTime()*1000;
	standbytime = GetReturnStandbyTime()*1000;

	if(standbytime == 0)
		gUIMain.TimeOutTimerEnable = FALSE;

	if((standbytime < (uCurTime - gUIMain.LastTime))&&(!gUIMain.FaxlayerEnable)&&
		NoJobExecuting()&&gUIMain.TimeOutTimerEnable)
		{
		TimeOutFlag = TRUE;
		gUIMain.TimeOutTimerEnable = FALSE;
		}
	else if(!NoJobExecuting()&&errorstate.enginestate == ENGINEREADY&&errorstate.adfstate == ADFREADY
		&&errorstate.scannerstate == SCANNERREADY&&errorstate.faxstate == FAXREADY)
		ResetTimeFlag = TRUE;
	
	if((powertime < (uCurTime - gUIMain.LastTime))&&NoJobExecuting()&&(!gUIMain.FaxlayerEnable)&&(!gUIMain.PowerSavEnable))
		{
		gUIMain.PowerSavEnable = TRUE;
		gUIMain.UIstate = ENERGYSAVE;
		PowerSaveMode();
		
		strcpy(firstlinebuf,GetMsgData(DISP_POW_SAVING));
		strcpy(secondlinebuf,"");
		LCDCursorOff();
		LCDDisplayClear();

		DisplayLCD(0, firstlinebuf, MIDDLE,FALSE);
		DisplayLCD(1, secondlinebuf, MIDDLE,FALSE);
		}
}

void UpdateLCD()
{
//	char buf[42];
	Bool arrow;
	P_MAIN_MENU_LIST pml;
	Uint8 AlignL1,AlignL2;
	Uint8 toner;
	_TonerInfo tonerinfo;

	pml = gpMenudata->ml +gpMenudata->mlIndex;
	
	AlignL1 = pml->firstline;
	AlignL2 = pml->secondline;
//	sprintf(buf,"%-20s\n%-20s",firstlinebuf,secondlinebuf);
//	PSPRINTF("call UpdateLCD \n");
	if(!gUIMain.FaxlayerEnable)
		{
		/*if(gUIMain.UIstate == STANDBY&&!Copy2upFirstPageFinish&&!IDcopyFrontPageFinish&&!gUIMain.bFirstPowerUP)
			{
			tonerinfo = GetTonerInfo();
			toner = tonerinfo.Percent;
			
			if(errorstate.tonerstate == TONERINVALID)
				strcpy(firstlinebuf,GetMsgData(DISP_TONERINVALID));
			else if(toner>25)
				sprintf(firstlinebuf,"%s %3d%%",firstlinebuf,toner);
			else if(toner>5)
				strcpy(firstlinebuf,GetMsgData(DISP_T_L));
			else
				strcpy(firstlinebuf,GetMsgData(DISP_T_E));
			}
		*/
		if((pml->type != STRING&&setconfirm == TRUE)||gpMenudata ->mlCount == 1||((!diagnosismode)&&gUIMain.UIstate == SERVICE_MODE))
			arrow = FALSE;
		else
			arrow = TRUE;
		
		if(pml->type != DIALINPUT&&pml->type != CHARACTERINPUT&&pml->type !=DATETIMEINPUT&&pml->type !=MULTIDIAL
			&&pml->type!=IDINPUT&&pml->type!= PHONEBOOKINPUT&&pml->type!= SEARCH&&pml->type!= PASSCODE
			&&pml->type!=PERIOD&&pml->type!=CANCELJOB&&pml->type!=REDIAL&&pml->type!=DIALTEST&& gUIMain.UIstate!=QUICKFAX
			&&gUIMain.FaxlayerEnable == FALSE)
			{
			LCDDisplayClear();
			NU_Sleep(5);

//			PSPRINTF("\n%s\n",firstlinebuf);
//			PSPRINTF("%s\n\n",secondlinebuf);
			
			DisplayLCD(0, firstlinebuf, AlignL1,FALSE);
			DisplayLCD(1, secondlinebuf, AlignL2,arrow);
			}
	/*	if(gUIMain.UIstate == STANDBY||gUIMain.UIstate == COPY_IDLE||
			gUIMain.UIstate == FACTORY_MODE||gUIMain.UIstate == SERVICE_MODE)
	//		DisplayLCD(0, buf, strlen(buf));
			{
			LCDDisplayClear();
			
			DisplayLCD(0, firstlinebuf, AlignL1,FALSE);
			DisplayLCD(1, secondlinebuf, AlignL2,arrow);
			}*/
		if(gUIMain.UIstate == QUICKFAX)
			{
			LCDDisplayClear();
			NU_Sleep(5);
			
			DisplayLCD(0, quickfaxbuf, LEFT,FALSE);
			//DisplayLCD(1, secondlinebuf, LEFT,FALSE);
			}
		else if(pml->type == MULTI&&setconfirm == TRUE||gUIMain.UIstate == QUICKCOPY)
			{
			LCDDisplayClear();
			NU_Sleep(5);
			
			DisplayLCD(0, firstlinebuf, AlignL1,FALSE);
			DisplayLCD(1, secondlinebuf, LEFT,arrow);
			}
		}
	else
		{
		LCDDisplayClear();
		NU_Sleep(5);
			
		DisplayLCD(0, faxlayerfirstlinebuf, LEFT,FALSE);
		DisplayLCD(1, faxlayersecondlinebuf, LEFT,FALSE);
		}
}

void UIGetUserDefault()
{
	Uint8* buf;
	Uint8* pFlashdata;
	Uint8* pFlashdata2;
	int	failure;	

	SPI_Config();
	pFlashdata = (Uint8*)malloc_locked(DEFAULTSETTING_PAGES * FLASH_PAGE_SIZE);
	pFlashdata2 = (Uint8*)malloc_locked(FAX_MAINTENANCE_PAGES * FLASH_PAGE_SIZE);

	LockSPIMode(TRUE);

	failure = SPI_ReadPage(DEFAULTSETTING_STARTPAGE, DEFAULTSETTING_PAGES, (Uint32*)pFlashdata);
	SPI_ReadPage(FAX_MAINTENANCE_STARTPAGE, FAX_MAINTENANCE_PAGES, (Uint32*)pFlashdata2);

	UnlockSPIMode();
	if (failure)
	{
	    PSPRINTF("%s: SPI_ReadPage failed for flash sector\n", __func__);
	}
	memcpy(buf,pFlashdata,1);
	
	if(*buf == 0xFF||gUIMain.bFirstPowerUP)
		SetFactoryDefault();
	else
		{
		memcpy(&gMFPSettingNvram,pFlashdata,sizeof(MFPSETTING));
		memcpy(&gUIMain.copysetting,&gMFPSettingNvram.Copy,sizeof(COPYSETTING));
		memcpy(&gUIMain.commonsetting,&gMFPSettingNvram.Common,sizeof(COMMONSETTING));
		memcpy(&gUIMain.faxsetting, &gMFPSettingNvram.Fax,sizeof(FAXSETTING));
		memcpy(&gUIMain.papersetting,&gMFPSettingNvram.Paper,sizeof(PAPERSETTING));
		memcpy(&gUIMain.scansetting,&gMFPSettingNvram.Scan,sizeof(SCANSETTING));
		/* Dynamic menu of Scan2App*/
		Scan2AppMenu_Init();

		gUIMain.pPhonebook = &phonebook;
		}

	memcpy(buf,pFlashdata2,1);
	
	if(*buf == 0xFF||gUIMain.bFirstPowerUP)
		SetDefaultFaxMaintenance();
	else
		memcpy(&FaxMaintenanceSetting,pFlashdata2,sizeof(FAX_MAINTENANCE));
		
	InitPhoneBook();
	
	gUIMain.UIstate = STANDBY;
	gUIMain.Scannerbusy = FALSE;
	gUIMain.TimeOutTimerEnable = TRUE;

⌨️ 快捷键说明

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