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

📄 kbd_lirc.c

📁 the embedded GUI for SamSung s3c2410 cpu based board.is microwindows0.90
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Microwindows IR remote control keyboard driver * Written by Koninklijke Philips Electronics N.V. * * Based on the Microwindows /dev/tty console scancode * keyboard driver for Linux * Copyright (c) 2000 Greg Haerr <greg@censoft.com> *  * Portions contributed by Koninklijke Philips Electronics N.V. * These portions are Copyright 2002-2003 Koninklijke Philips Electronics * N.V.  All Rights Reserved.  These portions are licensed under the * terms of the Mozilla Public License, version 1.1, or, at your * option, the GNU General Public License version 2.0.  Please see * the file "ChangeLog" for documentation regarding these * contributions. * * * This driver uses the LIRC protocol, which is a de-facto standard * for IR remote controls on Linux. * * There are several parts to this driver: * - Low-level I/O and parsing functions, in mwlirc.c and mwlirc.h * - Generic functions, at the top of this file. * - Several drivers, one for each supported remote control, near the *   bottom of this file. */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <sys/ioctl.h>#include "mwtypes.h"#include "device.h"#include "mwlirc.h"static int LIRC_Open(KBDDEVICE * pkd);static void LIRC_Close(void);static void LIRC_GetModifierInfo(MWKEYMOD * modifiers,				 MWKEYMOD * curmodifiers);static int LIRC_Read(MWKEY * kbuf, MWKEYMOD * modifiers,		     MWSCANCODE * scancode);static void LIRC_UpdateKeyState(MWBOOL isDown, MWKEY mwkey);static int remoteKeyboardHandler(mwlirc_keystroke * event, MWKEY * kbuf,				 MWSCANCODE * pscancode);static int remoteControlHandler(mwlirc_keystroke * event, MWKEY * kbuf,				MWSCANCODE * pscancode);KBDDEVICE kbddev = {	LIRC_Open,	LIRC_Close,	LIRC_GetModifierInfo,	LIRC_Read,	NULL};/* If a driver wants to press & release a button at once, it should set * these to the release event, and then just return the press event. */static MWKEY LIRC_pending_keyrelease_ch = 0;static MWSCANCODE LIRC_pending_keyrelease_scan = 0;/* The global keymod state */static MWKEYMOD LIRC_keymod = 0;typedef int (*remoteHandler_t) (mwlirc_keystroke * event, MWKEY * kbuf,				MWSCANCODE * pscancode);typedef struct remoteDriver_t_{	const char *name;	remoteHandler_t handler;}remoteDriver_t;/* * List of remote control names. */static remoteDriver_t remoteDrivers[] = {	{"remote", remoteControlHandler},	{"keyboard", remoteKeyboardHandler},	{NULL, NULL}};static int LIRC_fd = -1;/* * Open the remote control. */static intLIRC_Open(KBDDEVICE * pkd){	int fd = mwlirc_init(MWLIRC_NONBLOCK);	LIRC_pending_keyrelease_ch = 0;	LIRC_pending_keyrelease_scan = 0;	LIRC_keymod = 0;	LIRC_fd = fd;	return fd;}/* * Close the keyboard. * This resets the terminal modes. */static voidLIRC_Close(void){	LIRC_fd = -1;	mwlirc_close();}/* Update the internal keyboard state */static voidLIRC_UpdateKeyState(MWBOOL isDown, MWKEY mwkey){	MWKEYMOD changebit = 0;	switch (mwkey) {	case MWKEY_NUMLOCK:		if (!isDown)			LIRC_keymod ^= MWKMOD_NUM;		return;	case MWKEY_CAPSLOCK:		if (!isDown)			LIRC_keymod ^= MWKMOD_CAPS;		return;	case MWKEY_LCTRL:		changebit = MWKMOD_LCTRL;		break;	case MWKEY_RCTRL:		changebit = MWKMOD_RCTRL;		break;	case MWKEY_LSHIFT:		changebit = MWKMOD_LSHIFT;		break;	case MWKEY_RSHIFT:		changebit = MWKMOD_RSHIFT;		break;	case MWKEY_LALT:		changebit = MWKMOD_LALT;		break;	case MWKEY_RALT:		changebit = MWKMOD_RALT;		break;	case MWKEY_LMETA:		changebit = MWKMOD_LMETA;		break;	case MWKEY_RMETA:		changebit = MWKMOD_RMETA;		break;	case MWKEY_ALTGR:		changebit = MWKMOD_ALTGR;		break;	default:		return;	}	if (isDown)		LIRC_keymod |= changebit;	else		LIRC_keymod &= ~changebit;}/* * Return the possible modifiers and current modifiers for the keyboard. */static voidLIRC_GetModifierInfo(MWKEYMOD * modifiers, MWKEYMOD * curmodifiers){	if (modifiers)		*modifiers = MWKMOD_NUM | MWKMOD_CAPS			| MWKMOD_LCTRL			| MWKMOD_LSHIFT | MWKMOD_RSHIFT			| MWKMOD_LALT | MWKMOD_RALT			| MWKMOD_LMETA | MWKMOD_RMETA;	if (curmodifiers)		*curmodifiers = LIRC_keymod;}/* * This reads one keystroke from the keyboard, and the current state of * the modifier keys (ALT, SHIFT, etc).  Returns -1 on error, 0 if no data * is ready, 1 on a keypress, and 2 on keyrelease. * This is a non-blocking call. */static intLIRC_Read(MWKEY * kbuf, MWKEYMOD * modifiers, MWSCANCODE * pscancode){	mwlirc_keystroke event[1];	int err;	const remoteDriver_t *driver;	int result = 0;	if (LIRC_pending_keyrelease_ch != 0) {		*kbuf = LIRC_pending_keyrelease_ch;		*modifiers = LIRC_keymod;		*pscancode = LIRC_pending_keyrelease_scan;		LIRC_pending_keyrelease_ch = 0;		LIRC_pending_keyrelease_scan = 0;		return 2;	}	do {		/*printf("Calling mwlirc_read_keystroke()\n");*/		err = mwlirc_read_keystroke_norepeat(event);		/*printf("Called  mwlirc_read_keystroke() - %d\n", err);*/		if (err != 0) {			return (err == MWLIRC_ERROR_AGAIN) ? 0 : -1;		}		driver = remoteDrivers;		while ((driver->name)		       && (0 != strcmp(driver->name, event->rc))) {			driver++;		}		if (driver->name) {			/*printf("LIRC_Read() - processing remote '%s', key '%s'\n", event->rc, event->name);*/			result = driver->handler(event, kbuf, pscancode);		} else {			printf("LIRC_Read() - Unrecognized remote control '%s'. (Key '%s')\n", event->rc, event->name);		}	}	while (result == 0);	*modifiers = LIRC_keymod;	return (result == 3 ? 0 : result);}/* ************************************************************************ *//* * End of generic IR code                                               * *//* ************************************************************************ *//* ************************************************************************ *//* * Start of IR keyboard driver                                          * *//* ************************************************************************ *//* * To use this driver, you must follow the following conventions * when allocating key names in LIRC. * * Key names always end in one of these symbols: *     '\' - Keypressed. *     '^' - Keyreleased. * The rest of the symbol must be one of the strings defined in keyboardKeys, * or one of these specials: *     "fn"  - "Fn" key * * The name of this remote is "keyboard" */typedef struct keyboardKey_t_{	MWBOOL isDown;	const char *name;	const MWKEY normal;	const MWKEY shift;	const MWKEY num;	const MWKEY fn;}keyboardKey_t;static keyboardKey_t keyboardKeys[] = {// Row 1	{0, "ESCAPE", MWKEY_ESCAPE, MWKEY_ESCAPE, MWKEY_ESCAPE, 0},	{0, "F1", MWKEY_F1, MWKEY_F1, MWKEY_F1, MWKEY_F11},	{0, "F2", MWKEY_F2, MWKEY_F2, MWKEY_F2, MWKEY_F12},	{0, "F3", MWKEY_F3, MWKEY_F3, MWKEY_F3, 0},	{0, "F4", MWKEY_F4, MWKEY_F4, MWKEY_F4, 0},	{0, "F5", MWKEY_F5, MWKEY_F5, MWKEY_F5, 0},	{0, "F6", MWKEY_F6, MWKEY_F6, MWKEY_F6, 0},	{0, "F7", MWKEY_F7, MWKEY_F7, MWKEY_F7, 0},	{0, "F8", MWKEY_F8, MWKEY_F8, MWKEY_F8, 0},	{0, "F9", MWKEY_F9, MWKEY_F9, MWKEY_F9, 0},	{0, "F10", MWKEY_F10, MWKEY_F10, MWKEY_F10, 0},	{0, "NUMLOCK", MWKEY_NUMLOCK, MWKEY_NUMLOCK, MWKEY_NUMLOCK,	 MWKEY_NUMLOCK},	{0, "PRINT", MWKEY_PRINT, MWKEY_PRINT, MWKEY_PRINT, 0},	{0, "SCROLLOCK", MWKEY_SCROLLOCK, MWKEY_SCROLLOCK, MWKEY_SCROLLOCK,	 0},	{0, "PAUSE", MWKEY_PAUSE, MWKEY_PAUSE, MWKEY_PAUSE, 0},	{0, "INSERT", MWKEY_INSERT, MWKEY_INSERT, MWKEY_INSERT, 0},/*	{ 0, "PAUSE",     MWKEY_PAUSE,     MWKEY_PAUSE,     MWKEY_PAUSE,     0 }, */// Row 2	{0, "1", '1', '!', 0, 0},	{0, "2", '2', '@', 0, 0},	{0, "3", '3', '#', 0, 0},	{0, "4", '4', '$', 0, 0},	{0, "5", '5', '%', 0, 0},	{0, "6", '6', '^', 0, 0},	{0, "7", '7', '&', '7', '7'},	{0, "8", '8', '*', '8', '8'},

⌨️ 快捷键说明

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