📄 touchserial.c
字号:
}
#else
SYSCALL(local->fd = open(priv->input_dev, O_RDWR|O_NDELAY, 0));
if (local->fd < 0) {
Error("Unable to open Elographics touchscreen device");
return !Success;
}
DBG(3, ErrorF("Try to see if the link is at the specified rate\n"));
memset(&termios_tty, 0, sizeof(termios_tty));
termios_tty.c_cflag = priv->link_speed | CS8 | CREAD | CLOCAL;
termios_tty.c_cc[VMIN] = 1;
SYSCALL(result = tcsetattr(local->fd, TCSANOW, &termios_tty));
if (result < 0) {
Error("Unable to configure Elographics touchscreen port");
goto not_success;
}
#endif
/*
* Try to see if the link is at the specified rate and
* ask the controller to report various infos.
*/
memset(req, 0, ELO_PACKET_SIZE);
req[1] = tolower(ELO_PARAMETER);
if (xf86EloSendQuery(req, reply, local->fd) != Success) {
priv->is_a_2310 = 1;
ErrorF("Not at the specified rate or model 2310, will continue\n");
}
/*
* Ask the controller to report various infos.
*/
memset(req, 0, ELO_PACKET_SIZE);
req[1] = tolower(ELO_ID);
if (xf86EloSendQuery(req, reply, local->fd) == Success) {
xf86EloPrintIdent(reply, priv);
}
else {
ErrorF("Unable to ask Elographics touchscreen identification\n");
goto not_success;
}
/*
* Set the operating mode: Stream, no scaling, no calibration,
* no range checking, no trim, tracking enabled.
*/
memset(req, 0, ELO_PACKET_SIZE);
req[1] = ELO_MODE;
req[3] = ELO_TOUCH_MODE | ELO_STREAM_MODE | ELO_UNTOUCH_MODE;
req[4] = ELO_TRACKING_MODE;
if (xf86EloSendControl(req, local->fd) != Success) {
ErrorF("Unable to change Elographics touchscreen operating mode\n");
goto not_success;
}
#ifndef XFREE86_V4
/*
* Check if the report delay is compatible with the selected
* link speed and reset it otherwise.
*/
for (i = 0; i < sizeof(LinkSpeedValues)/sizeof(LinkParameterStruct); i++) {
if (LinkSpeedValues[i].speed == priv->link_speed) {
if (LinkSpeedValues[i].delay > priv->report_delay) {
ErrorF("Changing report delay from %d ms to %d ms to comply with link speed\n",
priv->report_delay*10, LinkSpeedValues[i].delay*10);
priv->report_delay = LinkSpeedValues[i].delay;
}
}
}
#endif
/*
* Set the touch reports timings from configuration data.
*/
memset(req, 0, ELO_PACKET_SIZE);
req[1] = ELO_REPORT;
req[2] = priv->untouch_delay;
req[3] = priv->report_delay;
if (xf86EloSendControl(req, local->fd) != Success) {
ErrorF("Unable to change Elographics touchscreen reports timings\n");
not_success:
SYSCALL(close(local->fd));
local->fd = -1;
return !Success;
}
#ifdef XFREE86_V4
xf86AddEnabledDevice(local);
#else
AddEnabledDevice(local->fd);
#endif
dev->public.on = TRUE;
}
DBG(2, ErrorF("Done\n"));
return Success;
/*
* Deactivate the device. After this, the device will not emit
* events until a subsequent DEVICE_ON. Thus, we can momentarily
* close the port.
*/
case DEVICE_OFF:
DBG(2, ErrorF("Elographics touchscreen off...\n"));
dev->public.on = FALSE;
if (local->fd >= 0) {
#ifdef XFREE86_V4
xf86RemoveEnabledDevice(local);
#else
RemoveEnabledDevice(local->fd);
#endif
}
SYSCALL(close(local->fd));
local->fd = -1;
DBG(2, ErrorF("Done\n"));
return Success;
/*
* Final close before server exit. This is used during server shutdown.
* Close the port and free all the resources.
*/
case DEVICE_CLOSE:
DBG(2, ErrorF("Elographics touchscreen close...\n"));
dev->public.on = FALSE;
if (local->fd >= 0) {
RemoveEnabledDevice(local->fd);
}
SYSCALL(close(local->fd));
local->fd = -1;
DBG(2, ErrorF("Done\n"));
return Success;
default:
ErrorF("unsupported mode=%d\n", mode);
return !Success;
}
}
/*
***************************************************************************
*
* xf86EloAllocate --
*
***************************************************************************
*/
static LocalDevicePtr
#ifndef XFREE86_V4
xf86EloAllocate(void)
#else
xf86EloAllocate(InputDriverPtr drv)
#endif
{
#ifndef XFREE86_V4
LocalDevicePtr local = (LocalDevicePtr) xalloc(sizeof(LocalDeviceRec));
#else
LocalDevicePtr local = xf86AllocateInput(drv, 0);
#endif
EloPrivatePtr priv = (EloPrivatePtr) xalloc(sizeof(EloPrivateRec));
if (!local) {
if (priv) {
xfree(priv);
}
return NULL;
}
if (!priv) {
if (local) {
xfree(local);
}
return NULL;
}
#ifdef XFREE86_V4
priv->input_dev = strdup(ELO_PORT);
#else
priv->input_dev = ELO_PORT;
priv->link_speed = ELO_LINK_SPEED;
#endif
priv->min_x = 0;
priv->max_x = 3000;
priv->min_y = 0;
priv->max_y = 3000;
priv->untouch_delay = ELO_UNTOUCH_DELAY;
priv->report_delay = ELO_REPORT_DELAY;
priv->screen_no = 0;
priv->screen_width = -1;
priv->screen_height = -1;
priv->inited = 0;
priv->is_a_2310 = 0;
priv->checksum = ELO_INIT_CHECKSUM;
priv->packet_buf_p = 0;
priv->swap_axes = 0;
local->name = XI_TOUCHSCREEN;
local->flags = 0 /* XI86_NO_OPEN_ON_INIT */;
#ifndef XFREE86_V4
#if !defined(sun) || defined(i386)
local->device_config = xf86EloConfig;
#endif
#endif
local->device_control = xf86EloControl;
local->read_input = xf86EloReadInput;
local->control_proc = NULL;
local->close_proc = NULL;
local->switch_mode = NULL;
local->conversion_proc = xf86EloConvert;
local->reverse_conversion_proc = NULL;
local->fd = -1;
local->atom = 0;
local->dev = NULL;
local->private = priv;
local->type_name = "Elographics TouchScreen";
local->history_size = 0;
return local;
}
#ifndef XFREE86_V4
/*
***************************************************************************
*
* Elographics device association --
*
***************************************************************************
*/
DeviceAssocRec elographics_assoc =
{
"elographics", /* config_section_name */
xf86EloAllocate /* device_allocate */
};
#ifdef DYNAMIC_MODULE
/*
***************************************************************************
*
* entry point of dynamic loading
*
***************************************************************************
*/
int
#ifndef DLSYM_BUG
init_module(unsigned long server_version)
#else
init_xf86Elo(unsigned long server_version)
#endif
{
xf86AddDeviceAssoc(&elographics_assoc);
if (server_version != XF86_VERSION_CURRENT) {
ErrorF("Warning: Elographics module compiled for version%s\n", XF86_VERSION);
return 0;
}
else {
return 1;
}
}
#endif
#else /* XFREE86_V4 */
static void
xf86EloUninit(InputDriverPtr drv,
LocalDevicePtr local,
int flags)
{
EloPrivatePtr priv = (EloPrivatePtr) local->private;
xf86EloControl(local->dev, DEVICE_OFF);
xfree(priv->input_dev);
xfree(priv);
xfree(local->name);
xfree(local);
xf86DeleteInput(local, 0);
}
static const char *default_options[] = {
"BaudRate", "9600",
"StopBits", "1",
"DataBits", "8",
"Parity", "None",
"Vmin", "10",
"Vtime", "1",
"FlowControl", "None",
NULL
};
static InputInfoPtr
xf86EloInit(InputDriverPtr drv,
IDevPtr dev,
int flags)
{
LocalDevicePtr local=NULL;
EloPrivatePtr priv=NULL;
char *str;
int portrait = 0;
local = xf86EloAllocate(drv);
if (!local) {
return NULL;
}
priv = local->private;
local->conf_idev = dev;
xf86CollectInputOptions(local, default_options, NULL);
/* Process the common options. */
xf86ProcessCommonOptions(local, local->options);
str = xf86FindOptionValue(local->options, "Device");
if (!str) {
xf86Msg(X_ERROR, "%s: No Device specified in Elographics module config.\n",
dev->identifier);
if (priv) {
if (priv->input_dev) {
xfree(priv->input_dev);
}
xfree(priv);
}
xfree(local);
return NULL;
}
priv->input_dev = strdup(str);
local->name = xf86SetStrOption(local->options, "DeviceName", XI_TOUCHSCREEN);
xf86Msg(X_CONFIG, "Elographics X device name: %s\n", local->name);
priv->screen_no = xf86SetIntOption(local->options, "ScreenNo", 0);
xf86Msg(X_CONFIG, "Elographics associated screen: %d\n", priv->screen_no);
priv->untouch_delay = xf86SetIntOption(local->options, "UntouchDelay", ELO_UNTOUCH_DELAY);
xf86Msg(X_CONFIG, "Elographics untouch delay: %d ms\n", priv->untouch_delay*10);
priv->report_delay = xf86SetIntOption(local->options, "ReportDelay", ELO_REPORT_DELAY);
xf86Msg(X_CONFIG, "Elographics report delay: %d ms\n", priv->report_delay*10);
priv->max_x = xf86SetIntOption(local->options, "MaximumXPosition", 3000);
xf86Msg(X_CONFIG, "Elographics maximum x position: %d\n", priv->max_x);
priv->min_x = xf86SetIntOption(local->options, "MinimumXPosition", 0);
xf86Msg(X_CONFIG, "Elographics minimum x position: %d\n", priv->min_x);
priv->max_y = xf86SetIntOption(local->options, "MaximumYPosition", 3000);
xf86Msg(X_CONFIG, "Elographics maximum y position: %d\n", priv->max_y);
priv->min_y = xf86SetIntOption(local->options, "MinimumYPosition", 0);
xf86Msg(X_CONFIG, "Elographics minimum y position: %d\n", priv->min_y);
priv->swap_axes = xf86SetBoolOption(local->options, "SwapXY", 0);
if (priv->swap_axes) {
xf86Msg(X_CONFIG, "Elographics device will work with X and Y axes swapped\n");
}
debug_level = xf86SetIntOption(local->options, "DebugLevel", 0);
if (debug_level) {
#if DEBUG
xf86Msg(X_CONFIG, "Elographics debug level sets to %d\n", debug_level);
#else
xf86Msg(X_INFO, "Elographics debug not available\n");
#endif
}
str = xf86SetStrOption(local->options, "PortraitMode", "Landscape");
if (strcmp(str, "Portrait") == 0) {
portrait = 1;
}
else if (strcmp(str, "PortraitCCW") == 0) {
portrait = -1;
}
else if (strcmp(str, "Landscape") != 0) {
xf86Msg(X_ERROR, "Elographics portrait mode should be: Portrait, Landscape or PortraitCCW");
str = "Landscape";
}
xf86Msg(X_CONFIG, "Elographics device will work in %s mode\n", str);
if (priv->max_x - priv->min_x <= 0) {
xf86Msg(X_INFO, "Elographics: reverse x mode (minimum x position >= maximum x position)\n");
}
if (priv->max_y - priv->min_y <= 0) {
xf86Msg(X_INFO, "Elographics: reverse y mode (minimum y position >= maximum y position)\n");
}
if (portrait == 1) {
/*
* Portrait Clockwise: reverse Y axis and exchange X and Y.
*/
int tmp;
tmp = priv->min_y;
priv->min_y = priv->max_y;
priv->max_y = tmp;
priv->swap_axes = (priv->swap_axes==0) ? 1 : 0;
}
else if (portrait == -1) {
/*
* Portrait Counter Clockwise: reverse X axis and exchange X and Y.
*/
int tmp;
tmp = priv->min_x;
priv->min_x = priv->max_x;
priv->max_x = tmp;
priv->swap_axes = (priv->swap_axes==0) ? 1 : 0;
}
/* mark the device configured */
local->flags |= XI86_CONFIGURED;
return local;
}
#ifdef XFree86LOADER
static
#endif
InputDriverRec ELO = {
1, /* driver version */
"elographics", /* driver name */
NULL, /* identify */
xf86EloInit, /* pre-init */
xf86EloUninit, /* un-init */
NULL, /* module */
0 /* ref count */
};
static pointer
Plug(pointer module,
pointer options,
int *errmaj,
int *errmin)
{
xf86AddInputDriver(&ELO, module, 0);
return module;
}
static void
Unplug(pointer p)
{
DBG(1, ErrorF("EloUnplug\n"));
}
static XF86ModuleVersionInfo version_rec = {
"elographics",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XF86_VERSION_CURRENT,
1, 0, 0,
ABI_CLASS_XINPUT,
ABI_XINPUT_VERSION,
MOD_CLASS_XINPUT,
{ 0, 0, 0, 0 }
};
/*
* This is the entry point in the module. The name
* is setup after the pattern <module_name>ModuleData.
* Do not change it.
*/
XF86ModuleData elographicsModuleData = { &version_rec, Plug, Unplug };
#endif /* XFREE86_V4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -