📄 xf86onetouch.c
字号:
} if (cmd & OTLED_RECALIBRATE) { /* xf86OnetouchProc( (DeviceIntPtr)local, DEVICE_ON); */ if (local->fd < 0) return; tcflush(local->fd, TCIFLUSH); /* flush pending input */ /* double-enable is fine, so we can do it always */ AddEnabledDevice(local->fd); xf86OnetouchReadCalib(priv, 1); /* ptr->public.on = TRUE; */ } if (cmd & OTLED_OFF) { if (local->fd >= 0) RemoveEnabledDevice(local->fd); } if (cmd & OTLED_BUTTON1) { priv->onetButton = 0; } if (cmd & OTLED_BUTTON2) { priv->onetButton = 1; } if (cmd & OTLED_BUTTON3) { priv->onetButton = 2; } if (cmd & OTLED_BUTTON2ONCE) { priv->onetButton = -1; } if (cmd & OTLED_BUTTON3ONCE) { priv->onetButton = -2; }}/* *************************************************************************** * xf86OnetouchOpen * Open and initialize the panel, as well as probe for any needed data. *************************************************************************** */#define WAIT(t) \ err = xf86WaitForInput(-1, ((t) * 1000)); \ if (err == -1) { \ ErrorF("Onetouch select error : %s\n", strerror(errno)); \ return !Success; \ }static Boolxf86OnetouchOpen(LocalDevicePtr local){ OnetouchDevicePtr priv = (OnetouchDevicePtr)local->private; DBG(1, ErrorF("opening %s (calibration file is \"%s\")\n", priv->onetDevice, priv->onetConfig)); xf86OnetouchReadCalib(priv, 1); priv->onetDlen = ONETOUCH_SERIAL_DLEN; local->fd = xf86OpenSerial(local->options); if (local->fd == -1) { Error(priv->onetDevice); return !Success; } DBG(2, ErrorF("%s opened as fd %d\n", priv->onetDevice, local->fd)); DBG(1, ErrorF("initializing Onetouch touch screen\n")); /* Hmm... close it, so it doens't say anything before we're ready */ /* FIXME */ /* Clear any pending input */ tcflush(local->fd, TCIFLUSH); if (xf86Verbose) ErrorF("%s Onetouch touch screen\n", XCONFIG_PROBED); return Success;}/*** xf86OnetouchOpenDevice** Opens and initializes the device driver stuff*/static intxf86OnetouchOpenDevice(DeviceIntPtr ptr){ LocalDevicePtr local = (LocalDevicePtr)ptr->public.devicePrivate; if (xf86OnetouchOpen(local) != Success) { if (local->fd >= 0) { SYSCALL(close(local->fd)); } local->fd = -1; } /* Initialize the axes */ InitValuatorAxisStruct(ptr, 0, /* X */ 0, ONETOUCH_MAXCOORD, /* min, max val */ 500000, /* resolution */ 0, 500000); /* min, max_res */ InitValuatorAxisStruct(ptr, 1, /* Y */ 0, ONETOUCH_MAXCOORD, /* min, max val */ 500000, /* resolution */ 0, 500000); /* min, max_res */ /* Register led feedback */ if (InitLedFeedbackClassDeviceStruct(ptr, xf86OnetouchLeds) == FALSE) DBG(0, ErrorF("Onetouch: can't initialize the feedback structure\n")); return (local->fd != -1);}/* ################################################# *//*** xf86OnetouchProc** Handle requests to do stuff to the driver.** In order to allow for calibration, the function is called (with DEVICE_OFF** and DEVICE_ON commands) also by xf86OnetouchChangeControl.*/static intxf86OnetouchProc(DeviceIntPtr ptr, int what){ CARD8 map[25]; /* 25? */ int nbaxes; int nbbuttons; int loop; LocalDevicePtr local = (LocalDevicePtr)ptr->public.devicePrivate; OnetouchDevicePtr priv = (OnetouchDevicePtr)PRIVATE(ptr); DBG(2, ErrorF("BEGIN xf86OnetouchProc dev=0x%x priv=0x%x what=%d\n", ptr, priv, what)); switch (what) { case DEVICE_INIT: DBG(1, ErrorF("xf86OnetouchProc ptr=0x%x what=INIT\n", ptr)); nbaxes = 2; /* X, Y */ nbbuttons = 3; /* three buttons, thanks to an helper app */ for(loop=1; loop<=nbbuttons; loop++) map[loop] = loop; if (InitButtonClassDeviceStruct(ptr, nbbuttons, map) == FALSE) { ErrorF("unable to allocate Button class device\n"); return !Success; } if (InitFocusClassDeviceStruct(ptr) == FALSE) { ErrorF("unable to init Focus class device\n"); return !Success; } /* * Use default (?) feedback stuff. * I'll use device feedback controls to change parameters at * run time. */ if (InitPtrFeedbackClassDeviceStruct(ptr, xf86OnetouchControlProc) == FALSE) { ErrorF("unable to init ptr feedback\n"); return !Success; } if (InitProximityClassDeviceStruct(ptr) == FALSE) { ErrorF("unable to init proximity class device\n"); return !Success; } if (InitValuatorClassDeviceStruct(ptr, nbaxes, xf86GetMotionEvents, local->history_size, Absolute) == FALSE) { ErrorF("unable to allocate Valuator class device\n"); return !Success; } /* allocate the motion history buffer if needed */ xf86MotionHistoryAllocate(local); /* open the device to gather informations */ xf86OnetouchOpenDevice(ptr); break; case DEVICE_ON: DBG(1, ErrorF("xf86OnetouchProc ptr=0x%x what=ON\n", ptr)); if ((local->fd < 0) && (!xf86OnetouchOpenDevice(ptr))) { return !Success; } tcflush(local->fd, TCIFLUSH); /* flush pending input */ AddEnabledDevice(local->fd); ptr->public.on = TRUE; break; case DEVICE_OFF: DBG(1, ErrorF("xf86OnetouchProc ptr=0x%x what=OFF\n", ptr)); if (local->fd >= 0) RemoveEnabledDevice(local->fd); ptr->public.on = FALSE; break; case DEVICE_CLOSE: DBG(1, ErrorF("xf86OnetouchProc ptr=0x%x what=CLOSE\n", ptr)); SYSCALL(close(local->fd)); local->fd = -1; break; default: ErrorF("unsupported mode=%d\n", what); return !Success; break; } DBG(2, ErrorF("END xf86OnetouchProc Success what=%d dev=0x%x priv=0x%x\n", what, ptr, priv)); return Success;}/*** xf86OnetouchClose** It... Uh... Closes the physical device?*/static voidxf86OnetouchClose(LocalDevicePtr local){ if (local->fd >= 0) { SYSCALL(close(local->fd)); } local->fd = -1;}/*** xf86OnetouchSwitchMode** Switches the mode. Only absolute is allowed.*/static intxf86OnetouchSwitchMode(ClientPtr client, DeviceIntPtr dev, int mode){ DBG(3, ErrorF("xf86OnetouchSwitchMode dev=0x%x mode=%d\n", dev, mode)); switch(mode) { case Absolute: break; default: DBG(1, ErrorF("xf86OnetouchSwitchMode dev=0x%x invalid mode=%d\n", dev, mode)); return BadMatch; } return Success;}/*** xf86OnetouchAllocate** Allocates the device structures for the Onetouch Touch Screen.*/static LocalDevicePtrxf86OnetouchAllocate(){ LocalDevicePtr local = xf86AllocateInput(gnzDrv, 0); OnetouchDevicePtr priv = (OnetouchDevicePtr)xalloc(sizeof(OnetouchDeviceRec)); local->name = XI_NAME; local->type_name = "Onetouch Touch Screen"; local->flags = 0; /*XI86_NO_OPEN_ON_INIT;*/ local->device_control = xf86OnetouchProc; local->read_input = xf86OnetouchReadInput; local->close_proc = xf86OnetouchClose; local->switch_mode = xf86OnetouchSwitchMode; local->conversion_proc = xf86OnetouchConvert; /* reverse_conversion is only used by relative devices (for warp events) */ local->reverse_conversion_proc = NULL; local->fd = -1; local->atom = 0; local->dev = NULL; local->private = priv; local->private_flags = 0; local->history_size = 0; priv->onetDevice = ""; /* device file name */ priv->onetConfig = ONETOUCH_DEFAULT_CFGFILE; priv->onetDlen = 0; /* unknown */ priv->onetBaud = 9600; priv->onetSmooth = 9; /* quite smooth */ priv->onetAvgX = -1; /* previous (avg) X position */ priv->onetAvgY = -1; /* previous (avg) Y position */ priv->onetPrevButton = 0; /* previous buttons state */ priv->flags = FLAG_WAS_UP; /* first event is button-down */ priv->onetBytes = 0; /* number of bytes read */ priv->onetButton = 0; priv->onetTappingDelay = ONETOUCH_DEFAULT_TAPPING_DELAY; xf86getsecs(&priv->onetUpSec, &priv->onetUpUsec); priv->timer = NULL; return local;}/*** Onetouch device association** Device section name and allocation function.*/DeviceAssocRec onetouch_assoc ={ ONETOUCH_SECTION_NAME, /* config_section_name */ xf86OnetouchAllocate /* device_allocate */};/* * xf86OnetUninit -- * * called when the driver is unloaded. */static voidxf86OnetUninit(InputDriverPtr drv, LocalDevicePtr local, int flags){ OnetouchDevicePtr priv = (OnetouchDevicePtr) local->private; DBG(1, ErrorF("xf86OnetUninit\n")); xf86OnetouchProc(local->dev, DEVICE_OFF); xfree (priv); xf86DeleteInput(local, 0);}/* * xf86OnetInit -- * * called when the module subsection is found in XF86Config */static InputInfoPtrxf86OnetInit(InputDriverPtr drv, IDevPtr dev, int flags){ LocalDevicePtr local = NULL; LocalDevicePtr fakeLocal = NULL; OnetouchDevicePtr priv = NULL; gnzDrv = drv; /* used by xf86OnetouchAllocate() */ fakeLocal = (LocalDevicePtr) xcalloc(1, sizeof(LocalDeviceRec)); if (!fakeLocal) return NULL; fakeLocal->conf_idev = dev; /* Force default serial port options to exist because the serial init * phasis is based on those values. */ xf86CollectInputOptions(fakeLocal, default_options, NULL); local = xf86OnetouchAllocate(); if (!local) { xf86Msg(X_ERROR, "%s: Can't allocate touchscreen data\n", dev->identifier); goto SetupProc_fail; } priv = (OnetouchDevicePtr)(local->private); local->options = fakeLocal->options; local->conf_idev = dev; local->name = dev->identifier; xf86OptionListReport( local->options ); xfree(fakeLocal); fakeLocal = NULL; /* Device name is mandatory */ priv->onetDevice = xf86FindOptionValue(local->options, "Device"); if (!priv->onetDevice) { xf86Msg(X_ERROR, "%s: `Device' not specified\n", dev->identifier); goto SetupProc_fail; } xf86ProcessCommonOptions(local, local->options); priv->onetSmooth = xf86SetIntOption(local->options, "Smoothness", 9); priv->onetJitterDelay = xf86SetIntOption(local->options, "JitterDelay", ONETOUCH_DEFAULT_JITTER_DELAY ); priv->onetTappingDelay = xf86SetIntOption(local->options, "TappingDelay", ONETOUCH_DEFAULT_TAPPING_DELAY ); debug_level = xf86SetIntOption(local->options, "DebugLevel", 0); /* FIXME: configuration file */ /* mark the device configured */ local->flags |= XI86_POINTER_CAPABLE | XI86_CONFIGURED; return (local); SetupProc_fail: if (priv) xfree(priv); if (local) xfree(local); return NULL;}#ifdef XFree86LOADERstatic#endifInputDriverRec ONETOUCH = { 1, /* driver version */ "onetouch", /* driver name */ NULL, /* identify */ xf86OnetInit, /* pre-init */ xf86OnetUninit, /* un-init */ NULL, /* module */ 0 /* ref count */};/* *************************************************************************** * * Dynamic loading functions * *************************************************************************** */#ifdef XFree86LOADER/* * xf86OnetUnplug -- * * called when the module subsection is found in XF86Config */static voidxf86OnetUnplug(pointer p){ DBG(1, ErrorF("xf86OnetUnplug\n"));}/* * xf86OnetPlug -- * * called when the module subsection is found in XF86Config */static pointerxf86OnetPlug(pointer module, pointer options, int *errmaj, int *errmin){ DBG(1, ErrorF("xf86OnetPlug\n")); xf86AddInputDriver(&ONETOUCH, module, 0); return module;}static XF86ModuleVersionInfo xf86OnetVersionRec ={ "onetouch", "Alessandro Rubini and Automata S.p.A. (Cannon group)", MODINFOSTRING1, MODINFOSTRING2, XF86_VERSION_CURRENT, 1, 2, 0, /* VERSION */ ABI_CLASS_XINPUT, ABI_XINPUT_VERSION, MOD_CLASS_XINPUT, {0, 0, 0, 0} /* signature, to be patched into the file by */ /* a tool */};XF86ModuleData onetouchModuleData = {&xf86OnetVersionRec, xf86OnetPlug, xf86OnetUnplug};#endif /* XFree86LOADER *//* end of xf86Onetouch.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -