📄 uglabtts.c
字号:
/* uglabtts.c - UGL Assabet Touch Screen Handler *//* Copyright 1999-2003 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01d,18jun03,jlb Update to Tornado 2.201c,16nov01,msr Fixed SPR #67628: fd not reset to zero.01b,23oct00,wdf Changed copyright date.01a,28mar00,rfm Created*//*DESCRIPTIONThis file provides the Assabet touch screen protocol support for UGL. Ithas a single global entry point <uglAssabetTsInit> which initializes thetouch screen device. The initialization function opens the specifiedI/O device, sets it to the proper mode, and registers the device formatter, control, and destroy functions.*/#include <stdlib.h>#include <string.h>#include <ioLib.h>#include <ugl/uglos.h>#include <ugl/uglmem.h>#include <ugl/uglinput.h>#include <ugl/uglevent.h>/* typedefs */typedef struct ugl_assabet_ts_pointer { UGL_UINT16 oldButton; /* old button state */ int prevX; int prevY; int mult_x; int mult_y; int delta_x; int delta_y;} UGL_ASSABET_TS_POINTER;typedef struct assabet_ts_packet { unsigned char sync; unsigned char penStatus; int x; int y; } ASSABET_TS_PACKET;#define ASSABET_PEN_DOWN 5#define ASSABET_PEN_UP 6#define ASSABET_TS_SYNC 0xA5#define UGL_ASSABET_TS_MULT_X (383)#define UGL_ASSABET_TS_MULT_Y (284)#define UGL_ASSABET_TS_DELTA_X (-69)#define UGL_ASSABET_TS_DELTA_Y (-85)/* Forward references */UGL_LOCAL UGL_STATUS uglAssabetTsFormatter (UGL_INPUT_DEVICE * pDevice, UGL_EVENT * pEvent);UGL_LOCAL UGL_STATUS uglAssabetTsInfo (UGL_INPUT_DEVICE * pDevice, UGL_DEVICE_REQ devRequest, void * arg);UGL_LOCAL UGL_STATUS uglAssabetTsDestroy ( UGL_INPUT_DEVICE * pDevice );/********************************************************************************* uglAssabetTsInit - initialize the touch screen device** This routine initializes the touch screen on the Assabet for use with UGL. * It opens the device <pDevName> and sets it to the proper mode. It creates a * device entry for the input service <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: UGL_STATUS_OK, if sucessful initialization or UGL_STATUS_ERROR* when device ecould not be initialized** ERRNO: N/A** SEE ALSO: uglAssabetTsDestroy()**/UGL_INPUT_DEVICE_ID uglAssabetTsInit ( char * pDevName, /* name of device */ UGL_EVENT_SERVICE_ID eventServiceId /* input service that device is assigned */ ) { UGL_ASSABET_TS_POINTER * pAssabetTsData; 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) { /* identify as relative pointer device type */ pDevice->deviceType = UGL_DEVICE_POINTER_ABSOLUTE; /* set up function pointers for device */ pDevice->format = uglAssabetTsFormatter; pDevice->destroy = uglAssabetTsDestroy; pDevice->info = uglAssabetTsInfo; /* set device local data */ pAssabetTsData = pDevice->data = UGL_MALLOC (sizeof(UGL_ASSABET_TS_POINTER)); pAssabetTsData->oldButton = 0; pAssabetTsData->mult_x = UGL_ASSABET_TS_MULT_X; pAssabetTsData->mult_y = UGL_ASSABET_TS_MULT_Y; pAssabetTsData->delta_x = UGL_ASSABET_TS_DELTA_X; pAssabetTsData->delta_y = UGL_ASSABET_TS_DELTA_Y; } else return (UGL_NULL); return ((UGL_INPUT_DEVICE_ID) pDevice); }/********************************************************************************* uglAssabetTsInfo - obtain/set information for device** This routine obtains information from the device and sets new information* for the device. For the Assabet touch screen pointer, there are no control * operations.** RETURNS: UGL_STATUS_OK** ERRNO: N/A** SEE ALSO: uglAssabetTsInit()**/UGL_LOCAL UGL_STATUS uglAssabetTsInfo ( UGL_INPUT_DEVICE * pDevice, /* device control structure */ UGL_DEVICE_REQ request, /* request to perform */ void * arg /* argument for request */ ) { if(pDevice == UGL_NULL) return(UGL_STATUS_ERROR); switch (request) { case UGL_DEVICE_GET_POINTER_TYPE: { if(arg != UGL_NULL) { *(int *)arg = UGL_DEVICE_POINTER_TYPE_TOUCH_SCREEN; return(UGL_STATUS_OK); } else { return(UGL_STATUS_ERROR); } } break; default: { return (UGL_STATUS_ERROR); } } return (UGL_STATUS_OK); }/********************************************************************************* uglAssabetTsDestroy - destory the assabet touch screen device ** This device terminates operations on a Assabet Touch Screen pointer. 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: uglAssabetTsInit()**/UGL_LOCAL UGL_STATUS uglAssabetTsDestroy ( UGL_INPUT_DEVICE * pDevice /* device control structure */ ) { /* close the device */ close (pDevice->fd); pDevice->fd = 0; /* free local storage */ UGL_FREE (pDevice->data); return UGL_STATUS_OK; }/******************************************************************************** uglAssabetTsFormatter - format touch screen input data to an input event** This routine handles formatting of input device data into an apprpriate* event. The Assabet Touch Screen packet consists is defined in * ugl/bspExt/assabetTs.h. Upon receipt of the packet, it is decoded into * an UGL input event. The only fields within the input event that are filled * in are the new button state, which buttons changed state, and the abs x and* abs y. The other fields within the input event are completed by the input * service prior to posting the event to the input queue.** RETURNS: UGL_STATUS_OK, when a packet was received and an input event * is ready, UGL_STATUS_EVENT_NOT_READY when an input event is not* ready, or UGL_STATUS_DROP when the event had been dropped** ERRNO: N/A** SEE ALSO: uglAssabetTsInit()**/UGL_LOCAL UGL_STATUS uglAssabetTsFormatter ( UGL_INPUT_DEVICE * pDevice, /* device control structure */ UGL_EVENT * pEvent /* event to build */ ) { UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)pEvent; UGL_ASSABET_TS_POINTER * pAssabetTsData = (UGL_ASSABET_TS_POINTER *) pDevice->data; ASSABET_TS_PACKET packet; int x, y; if(read(pDevice->fd, (char *)&packet, sizeof(ASSABET_TS_PACKET)) == sizeof(ASSABET_TS_PACKET)) { if(packet.sync != ASSABET_TS_SYNC) return (UGL_STATUS_EVENT_NOT_READY); /* Correct coordinates for calibration values */ x = (packet.x + pAssabetTsData->delta_x) * pAssabetTsData->mult_x / 1000; y = (packet.y + pAssabetTsData->delta_y) * pAssabetTsData->mult_y / 1000; x = 320 - x; y = 240 - y;#ifdef DEBUG printf("packet.x = %d\n", packet.x); printf("packet.y = %d\n", packet.y);#endif pAssabetTsData->prevX = x; pAssabetTsData->prevY = y; /* build input event */ pInputEvent->header.type = UGL_EVENT_TYPE_POINTER; pInputEvent->header.category = UGL_EVENT_CATEGORY_INPUT; if (packet.penStatus == ASSABET_PEN_DOWN) { pInputEvent->type.pointer.buttonState = UGL_POINTER_BUTTON1; } else { pInputEvent->type.pointer.buttonState = 0; } pInputEvent->type.pointer.buttonChange = (pInputEvent->type.pointer.buttonState ^ pAssabetTsData->oldButton); pAssabetTsData->oldButton = pInputEvent->type.pointer.buttonState; pInputEvent->x = pAssabetTsData->prevX; pInputEvent->y = pAssabetTsData->prevY; return(UGL_STATUS_OK); } return (UGL_STATUS_EVENT_NOT_READY); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -