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

📄 uiwin_thd.c

📁 嵌入工linux开发的源码
💻 C
字号:
/* the first version of window is support TICKERS only*/
#include <pr2k.h>
#include <uiwnd.h>
#include <uiPen_Hdr.h>
#include <battery.h>

#include <filesys.h>
//#include <FatSys.h>
//#include <FatDrv.h>

#include <database.h>
#include <stdio.h>
#include <sys/config.h>
#include <sys/syscall.h>
#include <sys/loadap.h>
#include <sysvar.h>
#include <uiAlarm.h>

#ifdef __WIN32__
#include <Machine\Init_Hw.h>
//#include <eprom.h>
//#include <smartcard.h>
#endif

#ifndef __WIN32__
#include <pendrv.h>
/* tong
extern unsigned char LCD_Adjusted;
#else
#define PEN_READY	1
static unsigned char LCD_Adjusted = PEN_READY;
*/
#endif

#ifdef __WIN32__
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

#endif

#ifdef _DEBUG            

//#define _DEBUG_WINTHREAD_
#endif

int giPenUpCount=0,giPenDownCount=0,giPenMoveCount=0;

#define WINTHREAD_MESSAGE_QUEUE_SIZE	200
#define SYS_FILE_APWELCOMESECOND "ApWelcomeSecond.abs"
/**************************************************************
Global Variable
**************************************************************/
/* message queue for windows thread (windows manager) */
TGuiMessageQueue* SysMsgQueue;

#ifndef __WIN32__
extern void systemShutDown(void);
#endif


extern PF_VOID gaKeyHandler[];
extern void guiKeyEventHandler(int key);
extern void guiTouchpadEventHandler(WORD msg, short x, short y);
extern TGuiMessageQueue * _guiAllocateMessageQueue(short nMaxMessageNo);

extern int gEnableELAuteOn;

/**************************************************************
Internal Routine
**************************************************************/
static void guiWelcome(void);
static void updateSysInfo(short type);

#ifdef __WIN32__
void fs_test(void);
int OpenEmuNFsh();
#endif

typedef  void (* PF_APWELCOME)(void);

#ifdef __WIN32__
PF_APWELCOME gp_fApWelcomeFirst=0;
PF_APWELCOME gp_fApWelcomeSecond=0;

DLL_EXP(void) GetApWelcomeFirstPtr(PF_APWELCOME  pf)
{
	gp_fApWelcomeFirst=pf;
}

DLL_EXP(void) GetApWelcomeSecondPtr(PF_APWELCOME  pf)
{
	gp_fApWelcomeSecond=pf;
}

#else
extern void ApWelcomeFirst(void);
extern void ApWelcomeSecond(void);
#endif

/*                     
#ifndef __WIN32__ 
int ramdisk_init(unsigned long size, int useExist);
int myStrLen(unsigned char *src);
char *myStrCpy(char *to, const char *from);
int iCompareChar(unsigned char char1, unsigned char char2);
void OnlyForLink()
{
	void *pOutFun[5] = {myStrCpy, iCompareChar, myStrLen, ramdisk_init, guiQueryLanguageType};

}
#endif
*/

// 处理开机後的欢迎画面, 会依硬体制造商不同而有所差异
static void guiWelcome(void)
{
	char msg[30];
	short x,y;
	int pen_Adjusted,hFile,len;                                                          
                     

	//sysTime  tTime;

#ifdef __WIN32__
//	_mkdir("c:\\NandFlash");
	OpenEmuNFsh();
#endif

#ifdef _DEBUG_WINTHREAD_
		printStringLn("NF_FileSys_Init begin");
#endif

	//IrDA_Init();	                    
	
	//if (fs_init() != 0)

	//jasonxxx	if(NF_FileSys_Init()<0)
//#ifdef __WIN32__
		//if(NF_FileSys_Init()<0)
//#else
	printf("NAND_init\n\r");

	if(FileSys_init() !=0)
//#endif
	{
		printf("Init FileSys fails");
		while (1);
	}
	printf("NAND_init_OK\n\r");

#ifdef _DEBUG_WINTHREAD_
		printStringLn("load system variable");
#endif          


	hFile=fs_open(szFileName_SysVar,O_RDONLY);
	if(hFile<0)
	{
		sys_SaveSysVar();
	}
	else
	{
		fs_close(hFile);
		sys_LoadSysVar();
	}


#ifdef _DEBUG_WINTHREAD_
	printStringLn("font init begin");
#endif
	// init font engine
	guiInitFont();	//Add because simple chinese;

#ifndef __WIN32__
#if defined(AR2001)&&(AR2001==2)
	setAdmitIdleTime(180);
	//setAdmitIdleTime(600);
	lcd_SetContrast(0x80);
	lcd_SaveContrast();
	//pen_AdjustPos();
#else
	sys_GetSysVar_Integer(SYSVAR_INTEGER_PEN_Adjusted,&pen_Adjusted);
	if(pen_GetStatus()==TOUCH_PEN_DOWN||pen_Adjusted != PEN_READY)
	{
		setAdmitIdleTime(180);
		setAdmitBackLightTime(60);  // by zhangxp
		el_SetWorkMode(3);
		//setAdmitIdleTime(600);
		lcd_SetContrast(0x80);
		lcd_SaveContrast();
		pen_AdjustPos();
	}
	else
	{
		restoreAdmitIdleTime();
		lcd_RestoreContrast();
		pen_ResestoreStatus();         
		el_RestoreStatus();
	}     
#endif
	
	//el_RestoreStatus();   
	                   

	//nfshEraseAllBlock();     
	//CF_Format();
/*
#else
	epromInit();
	CardInit();
*/	
#endif

    guiClearBlock(0,0,0,GUI_SCREEN_WIDTH-1,GUI_SCREEN_HEIGHT,GUI_WHITE,REPLACE_STYLE);

#ifdef __WIN32__
	if(gp_fApWelcomeFirst!=0)
	{
		gp_fApWelcomeFirst();
	}
#else
	ApWelcomeFirst();
#endif

#ifdef _DEBUG_WINTHREAD_
	printStringLn("database init begin");
#endif
	// Initial Database
    if (db_initDatabaseSys() != 1)
    {
    	printStringLn("database init error!");
		while(1);
    }

#ifdef _DEBUG_WINTHREAD_
		printStringLn("keyboard init begin");
#endif
	guiKbd_Init();	//initialize keyboard;

	guiRestoreCustomAreaCallback();


	//call ApWelcome;
#ifdef __WIN32__
	if(gp_fApWelcomeSecond!=0)
	{
		gp_fApWelcomeSecond();
	}
	Sleep(1000);
#else
	hFile=fs_open(SYS_FILE_APWELCOMESECOND,O_RDONLY);
	if(hFile<0)
	{
		ApWelcomeSecond();
	}
	else
	{
		len=fs_filelength(hFile);
		if(len>0)
		{
			fs_read(hFile,(unsigned char *)DLOAD_AP_START_ADDR,len);
			((PF_APWELCOME)DLOAD_AP_START_ADDR)();
	
		}
		fs_close(hFile);
	}
#endif
	{
		extern int    TouchSoundStatus;
		unsigned int buzzOn, volume;
		
		sys_GetSysVar_Integer(SYSVAR_INTEGER_MUSIC_VOLUME, (int *)&volume);
#ifndef __WIN32__
		set_volume(volume);
#endif
		sys_GetSysVar_Integer(SYSVAR_INTEGER_BUZZ_ON, (int *)&buzzOn);
		TouchSoundStatus=buzzOn;
	}
#ifdef _DEBUG_WINTHREAD_
	printStringLn("init ok");
#endif
}

static void updateSysInfo(short type)
{
	sysInfoBoxEventHandling();
}

/**************************************************************
Windows Manager (Window thread)
**************************************************************/
DLL_EXP(userThread) winThread(void)
{
//	int hFile;
    TTEXTEDIT* pFOCUStxtfield;
	HNDL hTimer_InfoBox = NULL, hTimer_Battery = NULL;
	TGuiMessage tempMessage;
	int i,n;    

	unsigned short test;

	int sysMenuCounter = 0;

#ifdef _SYS_INFO_BOX
	TWindow *fakeWin2;   // TGuiTimer needs window structure
#endif


	//GetStructSize();           // delete it

	/* allocate window thread's message queue */
	SysMsgQueue = _guiAllocateMessageQueue(WINTHREAD_MESSAGE_QUEUE_SIZE);

	/* initialize Graph mode */
	guiInitialGraphMode();

#ifdef _DEBUG_WINTHREAD_
	SprintStringLn("guiWelcome starts");
#endif
	for (i=0;i<GUI_MAX_KEY_NUMBER;i++)
		gaKeyHandler[i]=NULL;
	guiWelcome();
#ifdef _DEBUG_WINTHREAD_
	SprintStringLn("guiWelcome done!");
#endif

#ifdef _SYS_INFO_BOX
#ifdef GUI_INIT_DEBUG
	SprintStringLn("initialize sysinfo box");
#endif
#ifndef __WIN32__
	SetHWStatusWarm();
#endif

	// wake-up every 1 second
	fakeWin2 = (TWindow *)sc_malloc(sizeof(TWindow));

	fakeWin2->messageQueue = SysMsgQueue;
	hTimer_InfoBox = gui_allocateTimer() ;
	hTimer_Battery = gui_allocateTimer() ;

	/* Kevin test */
	//gui_startTimer(hTimer_InfoBox, 32*60, 32*60, (HNDL)fakeWin2) ;
	gui_startTimer(hTimer_InfoBox, 32*5, 32*5, (HNDL)fakeWin2) ;//1  5 sec
	//gui_startTimer(hTimer_InfoBox, 32, 32, (HNDL)fakeWin2) ;//1  1 sec

	gui_startTimer(hTimer_Battery, 16, 16, (HNDL)fakeWin2) ;//1  0.5 sec

#endif

	//启动系统闹铃thread
#ifdef GUI_INIT_DEBUG
	SprintStringLn("pdaInitAlarm");
#endif
//tong	pdaInitAlarm();

	init_AlarmLinklist();    //by zhangxueping

#ifdef GUI_INIT_DEBUG
	SprintStringLn("winthd message loop");
#endif

	/*
	for(i=0; i<100; i++)
	{
	test = GetBatteryVoltage();
	}
	*/
	// message loop of windows thread

	//伏
	//guiShowString(0, (char *)"ヱ", 2, 2, GUI_BLACK, 0);	// 显示编码

	while (1)
	{
		if(guiDequeue( SysMsgQueue, &tempMessage ) != -1)
		{
			//SpeedPLL();

			switch( tempMessage.messageType )
			{

#ifdef GUI_KEY_INPUT

			case WIN_KEY_HIT :
				if(tempMessage.handle!=(HNDL)gpTopWindow)
				{
					break;
				}

				// defined in key_hdr.c
				guiKeyEventHandler(tempMessage.x);
				break;

#endif // #ifdef GUI_KEY_INPUT

#ifdef GUI_PEN_INPUT

			case WIN_PEN_DOWN:
			case WIN_PEN_UP:
			case WIN_PEN_MOVE:
				if(tempMessage.handle!=(HNDL)gpTopWindow)
				{
					break;
				}
#if 0
				{
					char disBuffer[64];
					switch(tempMessage.messageType)
					{
						case WIN_PEN_DOWN:
							giPenDownCount++;
							break;
						case WIN_PEN_UP:
						giPenUpCount++;
						case WIN_PEN_MOVE:
						giPenMoveCount++;
					}
					
					sprintf(disBuffer,"down:%d,up:%d,move:%d       ",giPenDownCount,giPenUpCount,giPenMoveCount);
					guiShowString(0,disBuffer,10,145,GUI_BLACK,FONT_NON_TRANSPARENT);
					
					
				}
#endif				                  
/*
				if((gEnableELAuteOn)&&!backlightOn)
				{
					turnOnBackLight();
				}				
*/
	//tong 0521 test !!!!!!			sc_disableInt();
				guiTouchpadEventHandler(tempMessage.messageType, tempMessage.x, tempMessage.y);
	//tong 0521 test !!!!!!			sc_enableInt();
				break;

#endif //#ifdef GUI_PEN_INPUT

			case SYS_SHUTDOWN :
#ifndef __WIN32__
				systemShutDown();
#endif

#ifdef _SYS_INFO_BOX
				/*=========================================
				systemShutDown 是driver提供的功能用来
				将CPU切入省电模式 机器会停止执行 一旦
				恢复执行後 必须自动更新画面时间!
				===========================================*/
				updateSysInfo(0);
#endif
				break;

			case WIN_CHAR_INPUT :

				if(gpTopWindow == NULL)
					break ;

				// 取得被focus的editor, 将所输入的字元传给它
				{
				HNDL editorHandle ;

				editorHandle = guiTextEdit_QueryFocus() ;
				if(editorHandle == 0)
				{
					break;
				}
				pFOCUStxtfield = ( TTEXTEDIT *)editorHandle;
				if(pFOCUStxtfield->base.actionFun!=NULL)
				{
#if 0
					char disBuffer[32];
					sprintf(disBuffer,"x:%X,y:%X",tempMessage.x,tempMessage.y);
					printStringXY(0,20,disBuffer);
#endif
					pFOCUStxtfield->base.actionFun(editorHandle, KEY_CODE, tempMessage.x, tempMessage.y );
				}
				}
				break ;

			case SYS_UPDATE_INFOBOX :
				updateSysInfo(tempMessage.x);
				break;
                

			case TIMER_TIMEOUT:
				if(tempMessage.handle == (HNDL)hTimer_Battery)
				{
					InfoBox_GetBatt();
				}
#ifdef _SYS_INFO_BOX
				if(tempMessage.handle == (HNDL)hTimer_InfoBox)
				{
					updateSysInfo(0);
				}
#endif  // _SYS_INFO_BOX

				break;
			default:
				break;

            }   // end of switch(tempMessage.messageType)
        }   // end of if (result!=-1)
    }   // end of loop while(1)
	sc_exit() ;
}

⌨️ 快捷键说明

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