?? uglpckbd.c
字號:
/* uglPcKbd.c - PC (AT) type keyboard device support *//* Copyright 1999-2003 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01l,18jun03,jlb Updated for Tornado 2.201k,16nov01,msr Fixed SPR #70054: formatter loses key events.01j,25jul01,gav Back out AltGr.01i,25jul01,gav Added AltGr support to keyboard mapping.22dec00,pkr Added handling of AltGr on german keyboard01h,01feb01,jlb Do not convert key to control value when ctrl mod present (Java)01g,10nov00,jlb Do not compile keyboard mappings when config changes01f,09nov00,jlb Fixed num lock processing (SPR 62143)01e,23oct00,wdf Changed copyright date.01d,24feb00,msr Updated for event service API.01c,18jan00,jlb Modified to have the init function to add the device01b,12jan00,jlb Set the virtual console number01a,16dec99,jlb writtenDESCRIPTIONThis file provides the PC At type keyboard protocol support for UGL. Ithas a single global entry point <uglPcKbdInit> which initializes thePC keyboard. The initialization function opens the specifiedI/O device, sets it to the proper mode, and registers the device formatter, control, and destroy functions.This keyboard handler uses a keyboard driver to control the physicaldevice. The keyboard must be either a PC At 101/102 keyboard ora PS2 type keyboard that is set up to operate with scan code set 1.*/#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <ctype.h>#include <ioLib.h>#include <stdio.h>#include <drv/serial/pcConsole.h>#include <ugl/uglos.h>#include <ugl/uglmem.h>#include <ugl/uglinput.h>#include <ugl/uglevent.h>#include <ugl/uglucode.h>#include <ugl/driver/keyboard/uglpckbd.h>/* Forward references */UGL_LOCAL UGL_STATUS uglPcKbdInfo (UGL_INPUT_DEVICE * pDevice, UGL_DEVICE_REQ devRequest, void * arg);UGL_LOCAL UGL_STATUS uglPcKbdDestroy (UGL_INPUT_DEVICE * pDevice);UGL_LOCAL UGL_STATUS uglPcKbdFormatter (UGL_INPUT_DEVICE * pDevice, UGL_EVENT * pEvent);UGL_LOCAL UGL_UINT16 MapKeyValue(UGL_UINT16 keyValue, UGL_UINT32 modifiers);/******************************************************************************** uglPcKbdInit - initialize the PC AT keyboard** This routine initializes the PC keyboard for operation with UGL. The* keyboard attached to the device <pDevName> is opened and set in the* proper mode to function with UGL. It creates a device entry for the * input sercice <inSvcId>.** After the proper mode is set it fills in the formatter, control, and* destroy function pointers in the device descriptor and allocates device * specific control data.* * RETURNS: input device identifier assigned to keyboard when success;* otherwise UGL_NULL** ERRNO: N/A** SEE ALSO: uglPcKbdDestroy()*/UGL_INPUT_DEVICE_ID uglPcKbdInit ( char * pDevName, /* name of the device */ UGL_EVENT_SERVICE_ID eventServiceId /* event service */ ) { UGL_PC_KEYBOARD * pKbdData; char * tmp; int virtualConsole; UGL_INPUT_DEVICE * pDevice; /* Create the device */ pDevice = uglInputDeviceAdd (eventServiceId); if (pDevice == UGL_NULL) return (UGL_NULL); /* open the device */ pDevice->fd = open (pDevName, 0, 0); if (pDevice->fd >= 0) { if ((tmp = rindex(pDevName,(int)'/')) != 0) { /* set the proper virtual console as the active */ sscanf(tmp+1,"%d",&virtualConsole); ioctl(pDevice->fd, CONIOCURCONSOLE,virtualConsole); } /* set the device type as a keyboard */ pDevice->deviceType = UGL_DEVICE_KEYBOARD; /* device was opened, initialize */ ioctl (pDevice->fd, FIOSETOPTIONS, OPT_RAW); ioctl (pDevice->fd, FIOFLUSH,0); ioctl (pDevice->fd, CONIOCONVERTSCAN, FALSE); /* set up function pointers for device */ pDevice->format = uglPcKbdFormatter; pDevice->destroy = uglPcKbdDestroy; pDevice->info = uglPcKbdInfo; /* set device local data */ pKbdData = pDevice->data = UGL_MALLOC (sizeof(UGL_PC_KEYBOARD)); pKbdData->ledValue = 0; pKbdData->extendedKey = FALSE; pKbdData->ledControl = TRUE; ioctl (pDevice->fd, CONIOLEDS, pKbdData->ledValue); } else return (UGL_NULL); return ((UGL_INPUT_DEVICE_ID) pDevice); }/******************************************************************************** uglPcKbdPtrInfo - control the keyboard operations** This routine obtains information from the device and sets new information* within the device. For the PC keyboard, the following operations are * provided:**\is*\i LED mode (UGL_DEVICE_SET_LED_CONTROL)* Allow an application to control the LED state*\i set LED states (UGL_DEVICE_SET_LED)* Turn on/off an LED*\i get LED states (UGL_DEVICE_GET_LED)* Get the current setting of the keyboard LEDs*\ie** RETURNS: UGL_STATUS_OK** ERRNO: N/A** SEE ALSO: uglPcKbdInit()**/UGL_LOCAL UGL_STATUS uglPcKbdInfo ( UGL_INPUT_DEVICE * pDevice, /* device control structure */ UGL_DEVICE_REQ request, /* request to perform */ void * arg /* argument for request */ ) { UGL_PC_KEYBOARD * pKbdData = (UGL_PC_KEYBOARD *) pDevice->data; switch (request) { case UGL_DEVICE_SET_LED_CONTROL: /* set app/LED control */ pKbdData->ledControl = (UGL_BOOL)arg; break; case UGL_DEVICE_SET_LED: /* set LEDs */ pKbdData->ledValue = (UGL_UINT32) arg; ioctl (pDevice->fd, CONIOLEDS, (int) arg); break; case UGL_DEVICE_GET_LED: /* get state of LEDs */ *(int *)arg = pKbdData->ledValue; break; default: break; } return UGL_STATUS_OK; }/******************************************************************************** uglPcKbdDestroy - destory the device** This device terminates operations on a PC (AT) type keyboard. It closes the* device and frees all resources.** RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the operation fails.** ERRNO: N/A** SEE ALSO: uglPcKbdInit()**/UGL_LOCAL UGL_STATUS uglPcKbdDestroy ( UGL_INPUT_DEVICE * pDevice /* device control structure */ ) { /* close the device */ close (pDevice->fd); /* free local storage */ UGL_FREE (pDevice->data); return UGL_STATUS_OK; }/******************************************************************************** uglPcKbdFormatter - format keyboard input data to input event** This routine handles formatting of input device data into an appropriate* event. The scan code from the keyboard is read and processed to * approporately update state modifiers (ALT, CTRL, SHIFT) and update LED* states. An input event is generated that contains the updated modifier* states, the scan code, and the corresponding Unicode value.** RETURNS: UGL_STATUS_OK, when a packet was recieved* UGL_STATUS_DROP** ERRNO: N/A** SEE ALSO: uglMsPtrInit()*/UGL_LOCAL UGL_STATUS uglPcKbdFormatter ( UGL_INPUT_DEVICE * pDevice, /* device info */ UGL_EVENT * pEvent /* event to build */ ) { UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)pEvent; UGL_BOOL keyDown; UGL_UINT32 modifiers = 0; UGL_UINT32 newLedValue; unsigned short scanCode = 0; unsigned char atScanCode; int readCnt = 1; UGL_STATUS status = UGL_STATUS_DROP; UGL_PC_KEYBOARD * pKbdData = (UGL_PC_KEYBOARD *) pDevice->data; UGL_EVENT_SERVICE * pService = pDevice->pService; /* Get data until no more data is present */ while (readCnt != 0) { ioctl (pDevice->fd, FIONREAD, (int) &readCnt); if (readCnt > 0) readCnt = read(pDevice->fd, &atScanCode, 1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -