Linux 电子书 (基于linux-3.9.7 QT210)

移植韦东山电子书 到QT210上

由于QT210采用的电容屏,修该了上下翻屏时,触摸的算法,并去掉了tslib

#include <config.h>
#include <input_manager.h>
#include <stdlib.h>
#include <fcntl.h>
#include <draw.h>


static int giXres;
static int giYres;

static int t_fd;
/* ×¢Òâ: ÓÉÓÚÒªÓõ½LCDµÄ·Ö±æÂÊ, ´Ëº¯ÊýÒªÔÚSelectAndInitDisplayÖ®ºóµ÷Óà */
static int TouchScreenDevInit(void)
{
	if((t_fd = open(TSP_DEVICE_NAME, O_RDWR)) < 0)
	{
		DBG_PRINTF("Fail to open");
		return -1;
	} 

	if (GetDispResolution(&giXres, &giYres))
	{
		return -1;
	}

	return 0;
}

static int TouchScreenDevExit(void)
{
	return 0;
}


static int isOutOfdelayms(unsigned int delay, struct timeval *ptPreTime, struct timeval *ptNowTime)
{
	int iPreMs;
	int iNowMs;
	
	iPreMs = ptPreTime->tv_sec * 1000 + ptPreTime->tv_usec / 1000;
	iNowMs = ptNowTime->tv_sec * 1000 + ptNowTime->tv_usec / 1000;

	return (iNowMs > iPreMs + delay);
}

static int TouchScreenGetInputEvent(PT_InputEvent ptInputEvent)
{
	int iRet;
	int event_chang = 0;
	struct tsp_event tsp_value;
	struct tsp_code tsp_code;
	static struct timeval tPreTime;
	static struct timeval tResTime;


	tsp_code.y = 0;
	tsp_code.isPress = 0;
	while (1)
	{
		for(;;)
		{
			
				iRet = read(t_fd, &tsp_value, sizeof(struct tsp_event)); /* Èç¹ûÎÞÊý¾ÝÔòÐÝÃß */
				
				if (iRet < 0)
				{
					return -1;
				}
		/*
#define EV_SYN			0x00
#define EV_KEY			0x01
#define EV_REL			0x02
#define EV_ABS			0x03

#define ABS_X			0x00
#define ABS_Y			0x01
#define BTN_TOUCH		0x14a
		*/
				switch(tsp_value.type)
				{
					case EV_ABS:
						if(tsp_value.code == ABS_Y)
							tsp_code.y = tsp_value.value;
						
						if(tsp_value.code == ABS_X)
							tsp_code.x = tsp_value.value;
								
						tsp_code.time = tsp_value.time;
						break;
					case EV_KEY:
						if(tsp_value.code == BTN_TOUCH)
							tsp_code.isPress = tsp_value.value;
						
						//remember the time when press.
						if(tsp_code.isPress)
							tPreTime = tsp_value.time;
						else
							{
								tResTime = tsp_value.time;
								if((tPreTime.tv_sec != tResTime.tv_sec) || (tPreTime.tv_usec != tResTime.tv_usec))
								event_chang = 1;
								else
								event_chang = 0;
							}
						
						break;


					default:
						break;

				}
				if((tsp_code.isPress == 0) && (event_chang == 1))
					break;
			}
	printf("x:%4d,y:%4d,event_chang:%d\n",tsp_code.x, tsp_code.y, event_chang);
		

	if (event_chang && isOutOfdelayms(70,&tPreTime, &tResTime))
	{
		ptInputEvent->tTime = tResTime;
		ptInputEvent->iType = INPUT_TYPE_TOUCHSCREEN;
		event_chang = 0;
		if (tsp_code.y < giYres/3)
		{
			ptInputEvent->iVal = INPUT_VALUE_UP;
		}
		else if (tsp_code.y > 2*giYres/3)
		{
			ptInputEvent->iVal = INPUT_VALUE_DOWN;
		}
		else
		{
			ptInputEvent->iVal = INPUT_VALUE_UNKNOWN;
		}
		return 0;
		
	}
		else
		{
			return -1;
		}
	}

	return 0;
}


static T_InputOpr g_tTouchScreenOpr = {
	.name          = "touchscreen",
	.DeviceInit    = TouchScreenDevInit,
	.DeviceExit    = TouchScreenDevExit,
	.GetInputEvent = TouchScreenGetInputEvent,
};

int TouchScreenInit(void)
{
	return RegisterInputOpr(&g_tTouchScreenOpr);
}


这是效果:

./show_file -s 30 -d fb -f ./simsun.ttc gun.txt

Linux 电子书 (基于linux-3.9.7 QT210)_第1张图片


代码链接:http://download.csdn.net/detail/liujia2100/5816293



你可能感兴趣的:(Linux 电子书 (基于linux-3.9.7 QT210))