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

📄 zlg7289.c

📁 1) 复制libminigui-str-1.6.2.tar.gz至任意用户目录。 2) 解压此文件 tar zxvf libminigui-str-1.6.2.tar.gz 4) 将zl
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/kd.h>
#include <linux/h3600_ts.h>
#include <time.h>

#define KBD_DEVICE  "/dev/zlg7289"

//#define _DEBUG

#include "ial.h"
#include "zlg7289.h"
#define N_KEYS 128
/* for data reading from /dev/hs3600_ts */
#if 1
typedef struct {
    short b;
    short x;
    short y;
    short pad;
} POS;
#endif

static time_t last_time;
static unsigned char state[N_KEYS];
static unsigned char status1=0;	//	different number and alphabetic
static unsigned char status2=0;	//	different alphabetic1 .. alphabetic3 
static int ts = -1;
static int btn_fd = -1;
static unsigned char btn_state=0;

int key;

#if 1
static int mousex = 0;
static int mousey = 0;
static POS pos;
#endif

/************************  Low Level Input Operations **********************/
/*
 * Mouse operations -- Event
 */
#if 1
static int mouse_update(void)
{
    return 1;
}
static void mouse_getxy(int *x, int* y)
				
{
    *x = mousex;
    *y = mousey;
}
static int mouse_getbutton(void)
{
    return pos.b;
}
#endif
static int keyboard_update(void)
{
    int status;

    status = (btn_state & 0x80)? 0 : 1;
    key = btn_state & 0x7f;

	printf("key:%x\n",key);

	switch(key)
	{
	case 0x0D:	//上
		state[0] = status;
		break;
	case 0x0E:	//下
		state[1] = status;
		break;
	case 0x0F:	//左
		state[2] = status;
		break;
	case 0x13:	//右
		state[3] = status;
		break;
	case 0x3F:	//静音
		state[7] = status;
		break;
	case 0x35:
		state[5] = status;
		break;
	case 0x2E:
		state[6] = status;
		break;
	case 0x3E:	//手动/自动
		state[7] = status;
		break;
	case 0x36:
		state[8] = status;
		break;
	case 0x2F:
		state[9] = status;
		break;
	case 0x3D:	//隔离
		state[10] = status;
		break;
	case 0x37:
		state[11] = status;
		break;
	case 0x33:
		state[12] = status;
		break;
	case 0x3C:	//火警复位
		state[13] = status;
		break;
	case 0x3B:
		state[14] = status;
		break;
	case 0x34:
		state[15] = status;
		break;
	case 0x2D:	//ESC
		state[16] = status;
		break;
	case 0x23:	//2
		state[50] = status;
		break;
	case 0x1C:	//5
		state[53] = status;
		break;
	case 0x15:	//8
		state[56] = status;
		break;
	case 0x2C:	//1
		state[49] = status;
		break;
	case 0x24:	//3
		state[51] = status;
		break;
	case 0x1D:	//6
		state[54] = status;
		break;
	case 0x16:	//9
		state[5] = status;
		break;
	case 0x2B:	//DEL
		state[127] = status;
		break;
	case 0x25:	//4
		state[52] = status;
		break;
	case 0x1E:	//7
		state[55] = status;
		break;
	case 0x17:	//0
		state[48] = status;
		break;
	case 0x27:	//FN
		state[28] = status;
		break;
	case 0x26:	//SHIFT
		state[29] = status;
		break;
	case 0x1F:	//+-*/
		state[43] = status;
		break;
	case 0x1B:	//BACKSPACE
		state[32] = status;
		break;
	case 0x14:	//ENTER
		state[32] = status;
		break;
	}

	return N_KEYS;
}
static const char* keyboard_getstate(void)
{
	return (char *)state;
}
#ifdef _LITE_VERSION 
static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,
                struct timeval *timeout)
#else
static 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 ((which & IAL_KEYEVENT) && btn_fd >= 0){
        FD_SET (btn_fd, in);
#ifdef _LITE_VERSION
        if(btn_fd > maxfd) maxfd = btn_fd;
#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 1 
        if (ts >= 0 && FD_ISSET (ts, in)) {
            short data [4];
            FD_CLR (ts, in);
            read (ts, data, sizeof (data));
            if (data[0]) {
                mousex = pos.x = data[1];
                mousey = pos.y = data[2];
            }
#ifdef _DEBUG
            if (data[0]) {
                printf ("mouse down: pos.x = %d, pos.y = %d\n", pos.x, pos.y);
            }
#endif
            pos.b = (data[0] ? 4 : 0);
            retvalue |= IAL_MOUSEEVENT;
        }
#endif 
        if (btn_fd >= 0 && FD_ISSET(btn_fd, in)) {
            unsigned char key;
            FD_CLR(btn_fd, in);
            read(btn_fd, &key, sizeof(key));
#ifdef _DEBUG
	    printf("IAL:read key:0x%x \n",key);
#endif
	    	btn_state = key;
            retvalue |= IAL_KEYEVENT;
        }
    } else if (e < 0) {
        return -1;
    }
    return retvalue;
}

BOOL InitZLG7289Input (INPUT* input, const char* mdev, const char* mtype)
{
    printf("init ZLG7289 input ... \n");
    btn_fd = open (KBD_DEVICE, O_RDONLY);
    if (btn_fd < 0 ) {
        printf (stderr, "kb9200: Can not open button key!\n");
        return FALSE;
    }
#if 1
	printf("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
    input->update_keyboard = keyboard_update;
    input->get_keyboard_state = keyboard_getstate;
    input->set_leds = NULL;
    input->wait_event = wait_event;
#if 1
    mousex = 0;
    mousey = 0;
    pos.x = pos.y = pos.b = 0;
#endif
    
    return TRUE;
}

void TermZLG7289Input (void)
{
    if (ts >= 0)
        close(ts);
    if (btn_fd >= 0)
        close(btn_fd);
}
//#endif /* _IPAQ_IAL */

⌨️ 快捷键说明

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