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

📄 hi3510.c

📁 hi3510 minigui ial
💻 C
字号:
#include <string.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/poll.h>#include <linux/kd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "common.h"#ifdef _IAL_hi3510_h#include "misc.h"#include "ial.h"#include "hi3510.h"//#include "linux/h3600_ts.h"#define _MIND_MOUSE_		1#define _MIND_KEYBOARD_		0/* for data reading from /dev/hs3600_ts */typedef struct {	unsigned short b;	unsigned short x;	unsigned short y;	unsigned short pad;} POS;static unsigned char state [NR_KEYS];static int ts = -1;static int btn_fd = -1;static unsigned char btn_state=0;static int mousex = 0;static int mousey = 0;static POS pos;#define _DEBUG/************************ Low Level Input Operations **********************//** Mouse operations -- Event*/#if _MIND_MOUSE_static int mouse_update(void){	return 1;}static void mouse_getxy(int *x, int* y){#ifdef _DEBUG	printf ("mousex = %d, mousey = %d\n", mousex, mousey);#endif	if (mousex < 0) 	{		mousex = 0;	}		if (mousey < 0)	{		mousey = 0;	}#if 0		if (mousex > 319) 	{		mousex = 319;	}		if (mousey > 239) 	{		mousey = 239;	}#endif	*x = mousex;	*y = mousey;}static int mouse_getbutton(void){	return pos.b;}#endif#if _MIND_KEYBOARD_static int keyboard_update(void){	char *statinfo;	int status;	int key;	//Attention!	statinfo = (btn_state & KEY_RELEASED)? "UP":"DOWN";	status = (btn_state & KEY_RELEASED)? 0 : 1;	key = btn_state & KEY_NUM;#ifdef _DEBUG	fprintf(stderr, "key %d is %s", key, statinfo);#endif	switch (key)	{	case 1:		//state[H3600_SCANCODE_RECORD] = status;		state[SCANCODE_LEFTSHIFT] = status;		break;	case 2:		state[H3600_SCANCODE_CALENDAR] = status;		break;	case 3:		state[H3600_SCANCODE_CONTACTS] = status;		break;	case 4:		state[H3600_SCANCODE_Q] = status;		break;	case 5:		state[H3600_SCANCODE_START] = status;		break;	case 6:		state[H3600_SCANCODE_UP] = status;		break;	case 7:		state[H3600_SCANCODE_RIGHT] = status;		break;	case 8:		state[H3600_SCANCODE_LEFT] = status;		break;	case 9:		state[H3600_SCANCODE_DOWN] = status;		break;	case 10:		state[H3600_SCANCODE_ACTION] = status;		break;	case 11:		state[H3600_SCANCODE_SUSPEND] = status;		break;	}	return NR_KEYS;}static const char* keyboard_getstate(void){	return (char *)state;}#endif#ifdef _LITE_VERSIONstatic int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,struct timeval *timeout)#elsestatic int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,struct timeval *timeout)#endif{	fd_set rfds;	int retvalue = 0;	int e;		if (!in) 	{		in = &rfds;		FD_ZERO (in);	}		if ((which & IAL_MOUSEEVENT) && ts >= 0) 	{		FD_SET (ts, in);	#ifdef _LITE_VERSION		if (ts > maxfd) maxfd = ts;	#endif	}#if _MIND_KEYBOARD_		if ((which & IAL_KEYEVENT) && btn_fd >= 0)	{		FD_SET (btn_fd, in);	#ifdef _LITE_VERSION		if(btn_fd > maxfd) maxfd = btn_fd;	#endif	}#endif	#ifdef _LITE_VERSION	e = select (maxfd + 1, in, out, except, timeout) ;#else	e = select (FD_SETSIZE, in, out, except, timeout) ;#endif	if (e > 0) 	{		if (ts >= 0 && FD_ISSET (ts, in))		{			FD_CLR (ts, in);			pos.x=0;			pos.y=0;			// FIXME: maybe failed due to the struct alignment.			read (ts, &pos, sizeof (POS));			if (pos.b > 0) 			{				mousex = pos.x;				mousey = pos.y;			}	#ifdef _DEBUG			if (pos.b > 0) 			{				printf ("mouse down: pos.x = %d, pos.y = %d\n", pos.x, pos.y);			}	#endif			pos.b = ( pos.b > 0 ? 4:0);			retvalue |= IAL_MOUSEEVENT;		}			#if _MIND_KEYBOARD_		if (btn_fd >= 0 && FD_ISSET(btn_fd, in))		{			unsigned char key;			FD_CLR(btn_fd, in);			read(btn_fd, &key, sizeof(key));			btn_state = key;			retvalue |= IAL_KEYEVENT;		}	#endif		} 	else if (e < 0) 	{		return -1;	}	return retvalue;}BOOL InitHI3510Input (INPUT* input, const char* mdev, const char* mtype){#if _MIND_MOUSE_	ts = open ("/dev/misc/hi_touchscreen", O_RDONLY);		if (ts < 0)	{		fprintf (stderr, "HI3510: Can not open touch screen!\n");		return FALSE;	}#endif#if _MIND_KEYBOARD_	btn_fd = open ("/dev/h3600_key", O_RDONLY);	if (btn_fd < 0 ) 	{		fprintf (stderr, "HI3510: Can not open button key!\n");		return FALSE;	}#endif	#if _MIND_MOUSE_	input->update_mouse = mouse_update;	input->get_mouse_xy = mouse_getxy;	input->set_mouse_xy = NULL;	input->get_mouse_button = mouse_getbutton;	input->set_mouse_range = NULL;#endif#if _MIND_KEYBOARD_	input->update_keyboard = keyboard_update;	input->get_keyboard_state = keyboard_getstate;	mousex = 0;	mousey = 0;	pos.x = pos.y = pos.b = 0;#endif	input->set_leds = NULL;	input->wait_event = wait_event;	return TRUE;}void TermHI3510Input (void){	if (ts >= 0)	close(ts);	if (btn_fd >= 0)	close(btn_fd);dsadfadf }#endif /* _IAL_hi3510_h */

⌨️ 快捷键说明

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