?? comminput.c
字號:
/*** $Id: comminput.c,v 1.5 2005/02/03 01:06:53 xwyan Exp $**** comminput.c: Common Input Engine for eCos, uC/OS-II, VxWorks, ...** ** Copyright (C) 2004 Feynman Software**** Created by Zhong Shuyi, 2004/02/29*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include "common.h"#include "minigui.h"#include "misc.h"#include "ial.h"#include "comminput.h"#include "i2c.h"int fd_zlg7290 = -1;//////////////////////////////////////////////////////////////////////////////// COMM_IAL相關函數聲明 (在comm_drive.c中實現)extern int comm_ts_getdata (short *x, short *y, short *button);extern int comm_kb_getdata (short *key, short *status);extern int comm_wait_for_input(void);/////////////////////////////////////////////////////////////////////////////// 引擎所所需要的變量static int MOUSEX = 50, MOUSEY = 50, MOUSEBUTTON = 0; // 鼠標static short KEYCODE = 0, KEYSTATUS = 0; // 按鍵// 通知底層引擎更新鼠標信息 (返回1)static int mouse_update (void){ return 1; }// 獲得最新的鼠標(x,y)坐標值static void mouse_getxy (int *x, int* y){ *x = MOUSEX; *y = MOUSEY;}// 獲取鼠標按鈕狀態// 該函數的返回值可以是IAL_MOUSE_LEFTBUTTON(表示左鍵按下)、// IAL_MOUSE_MIDDLEBUTTON(表示中鍵按下)、IAL_MOUSE_RIGHTBUTTON// (表示右鍵按下)等值"或"的結果。static int mouse_getbutton (void){ return MOUSEBUTTON;}/////////////////////////////////////////////////////////////////////////////static unsigned char kbd_state[NR_KEYS]; // 鍵盤狀態緩沖區// 通知底層引擎更新鍵盤信息 (更改kbd_state數組,表明有按鍵)static int keyboard_update (void){ kbd_state[KEYCODE] = KEYSTATUS; return KEYCODE + 1;}// 獲取鍵盤狀態,返回一個字符數組(包括多個按鍵的狀態),其中包含以掃描碼索引的鍵盤按鍵狀態。static const char* keyboard_getstate (void){ return kbd_state;}/////////////////////////////////////////////////////////////////////////////static int wait_event( int which, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout){ int retvalue = 0; retvalue = comm_wait_for_input (); // 查詢鍵盤或鼠標事件(需要掛起任務) if (retvalue & IAL_MOUSEEVENT) // 鼠標事件 { // 如果是觸摸屏,則有button按鍵時才會更新MOUSEX、MOUSEY comm_ts_getdata (&MOUSEX, &MOUSEY, &MOUSEBUTTON); retvalue = IAL_MOUSEEVENT; } else { if (retvalue & IAL_KEYEVENT) // 鍵盤事件 { comm_kb_getdata (&KEYCODE, &KEYSTATUS); if (kbd_state[KEYCODE] == KEYSTATUS) return -1; retvalue = IAL_KEYEVENT; } else { retvalue = -1; } } return(retvalue);}/////////////////////////////////////////////////////////////////////////////// 輸入引擎的初始化函數。該函數負責對INPUT結構的其它成員賦值。BOOL InitCOMMInput (INPUT* input, const char* mdev, const char* mtype){ // 在此函數調用之前必須初始化輸入設備硬件。 // (可以在此調用初始化函數) fd_zlg7290 = open("/dev/zlg7290", O_RDWR); if(fd_zlg7290 == -1) { fprintf(stderr, "Cann't open file: /dev/zlg7290 !!!\n"); return(FALSE); } ioctl(fd_zlg7290, I2C_SET_CLH, ((11059200 / 30000) + 1) / 2); ioctl(fd_zlg7290, I2C_SET_CLL, (11059200 / 30000) / 2); 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; // 設置鼠標的活動范圍。 input->suspend_mouse= NULL; input->resume_mouse = NULL; input->update_keyboard = keyboard_update; input->get_keyboard_state = keyboard_getstate; input->suspend_keyboard = NULL; // 暫停鍵盤設備的讀取,用于虛擬控制臺切換。 input->resume_keyboard = NULL; // 繼續鍵盤設備讀取,用于虛擬控制臺切換。 input->set_leds = NULL; // 設置鍵盤的鎖定LED。 input->wait_event = wait_event; // 上層調用該函數等待底層引擎上發生輸入事件 return(TRUE);}// 輸入引擎的終止清除函數void TermCOMMInput (void){ if (fd_zlg7290 >= 0) close(fd_zlg7290);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -