<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Northern Nerd &#187; Ubuntu</title>
	<atom:link href="http://www.rantakokko.net/tapani/blog/tag/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rantakokko.net/tapani/blog</link>
	<description>Just another blogging geek</description>
	<lastBuildDate>Sun, 16 Aug 2009 16:17:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>LG L1730SF touch screen display in Ubuntu Linux 8.04 Hardy Heron, part 3</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/08/16/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-3/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/08/16/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-3/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 16:16:39 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[Hardy Heron]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[touch screen]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=189</guid>
		<description><![CDATA[In the 1st part we set up the drivers for the touch feature, and in the 2nd part we solved the weird jumpiness issue. Now we are ready to proceed to calibrating the display, and fine tuning the system for touch based usage in general. Calibrating the touch input The idea of the touch screen [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a title="1st part" href="http://www.rantakokko.net/tapani/blog/2009/04/29/lg-l1730sf-touch-screen-display-in-ubuntu-linux-804-hardy-heron/">1st part</a> we set up the drivers for the touch feature, and in the <a title="2nd part" href="http://www.rantakokko.net/tapani/blog/2009/08/10/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-2/">2nd part</a> we solved the weird jumpiness issue. Now we are ready to proceed to calibrating the display, and fine tuning the system for touch based usage in general.</p>
<h3>Calibrating the touch input</h3>
<p>The idea of the touch screen is that the user interface objects presented on the screen can be directly pointed at, using a pen or a finger. Ideally, when user sees even a single pixel at, say coordinates 100, 150 and then pushes the screen with a pen at this point exactly, the touch screen / mouse driver should register exactly the same coordinates and report them to the windowing engine.</p>
<p>However, in practice things are a bit different. For example, the resistive touch panel used e.g. in LG L1730SF is placed on top of the display panel. In real life things are not perfect, so there will be some offset in the display component framing, in the touch panel component framing, and in their relative placement on top of each other. Every manufactured device ends up being slightly different.</p>
<p>The result is that there will be some offset between the actual/perceived location of the touch, and the location reported to the windowing system that draws the mouse cursor and processes points and clicks. This is bad. For example, it can be very annoying if you are trying to hit a link on a web page, but always seem to miss it just a little!</p>
<p>Fortunately, this error can be fixed fairly well with a proper <em>calibration</em>. Calibration is a procedure based on showing a known location to be touched on the screen e.g. with an X mark, and then sampling the actual location that was touched. The difference between screen coordinates and mouse coordinates tells what kind of offset the particular display has. For example, when the user thinks he has touched precisely coordinates 100, 150 we may have received 108, 145 as mouse coordinates. Thus the difference is +8, -5. In order to correct the error, the offset can be removed by manipulating the mouse coordinates with the offset values found via calibration. This will be done already at the driver level, e.g. (+8, -5) could be subtracted from all input reported by the touch panel. The X windowing system would then get slightly different mouse coordinates that should match much better with the screen coordinates and perceived touch location.</p>
<p><span id="more-189"></span>Note that proper calibration is always somewhat user dependent, as there is a small distance between the touch panel and the surface of the image in the display device. Depending on the way the display is mounted (e.g. on a wall or table), the taller the person is the more angled is her view to the display. As a result, the farther away she actually touches from the location that she <em>thinks</em> she touches. It is like with shadows: if the sun shines right on top of an object there will be no shadow at all (precise touch), but from another angle a shadow will be cast (offset). In addition, when fingers are used for touching, users may have different preference on which part of the finger is the &#8220;center&#8221; point that should be registered as the touch location. E.g. is it the center of the area of the finger that touches the display (finger tip touch), or perhaps the location at the top boundary of the touch (fingernail touch). Nevertheless, the touch control cannot be very precise without personal calibration.</p>
<p>For proper calibration, one pair of sample values (x offset, y offset) is not enough &#8211; these correction factors must be taken separately for different areas of the display. In small devices, such as PDAs and mobile phones, it is very common to use 5 samples: 4 corners and the center of the screen. However, <em>Evtouch</em> uses nine calibration samples, as also centers of the edges of the screen are sampled. Based on the samples it then calculates the proper correction factor (i.e. the actual x,y offset to be subtracted from touch input is some kind of approximation based on the distance to a few nearest sampled calibration points).</p>
<p>Next, we will begin to figure out how to apply proper calibration value pairs (the 9 samples) to the <em>xorg.conf</em> file. They will be eventually listed as <em>Option</em>s in our touch screen section.</p>
<p>There are basically two methods. One is naturally manual trial and error based, where one tries to adjust a value and then tests whether it helped. However, due to large number of adjustable values (9 samples with two values = 18) and the approximation in the algorithm, this is laborious. The other method involves using a calibration tool, which is a simple software aimed for making the calibration as simple as touching a few spots on the screen. We&#8217;ll of course try the latter first and see whether it works for us.</p>
<p>Let&#8217;s first activate the calibration mode in <em>Evtouch.</em> In console, type</p>
<blockquote>
<pre>sudo nano /etc/X11/xorg.conf</pre>
</blockquote>
<p>Find the touchscreen section, and uncomment/write this:</p>
<blockquote>
<pre>Option   "Calibrate" "1"</pre>
</blockquote>
<p>This will turn calibration support on from <em>evtouch</em> driver module. You might want to remove <em>&#8220;CorePointer&#8221;</em> from touchscreen, and make sure that <em>&#8220;Configured mouse&#8221;</em> is enabled to allow mouse usage during calibration. Save and exit.</p>
<p>Next, we need to stop X:</p>
<blockquote>
<pre>sudo /etc/init.d/gdm stop</pre>
</blockquote>
<p>Continue in one of the consoles by pressing e.g. <em>CTRL+ALT+F2</em>. To begin calibration, first go here:</p>
<blockquote>
<pre>cd /usr/lib/xf86-input-evtouch</pre>
</blockquote>
<p>Before starting the calibration tool, we need to copy a bitmap file for empty cursor to file system root (!):</p>
<blockquote>
<pre>sudo cp /usr/share/xf86-input-evtouch/empty_cursor.xbm /</pre>
</blockquote>
<p>Then start the calibration tool as follows:</p>
<blockquote>
<pre>sudo ./calibrate.sh</pre>
</blockquote>
<p>A white screen with nine black crosses should appear. They are in the corners, middle of border lines, and in the center. Basic idea is that when you press the Enter key, one of the crosses turns red and you should click it as precisely as you can. Then the next one will turn red, and so on until all 9 have been tapped. Then the proper offset values will be printed, to be copied to your <em>xorg.conf</em> file.</p>
<p>However, as LG L1730SF has the touch panel mounted in rotated and swapped direction with respect to what is expected by <em>Evtouch</em>, the input data will not be what the calibration script expects. This is because our <em>xorg.conf</em> options <em>Rotate</em> and <em>SwapX/SwapY</em> do not seem to have effect here. As a result, when the calibration application marks left top X as red, and then you tap that position on the screen, the raw touch panel output will be very faw away from those screen coordinates. Thus, you cannot actually click the X mark that turns red, or you&#8217;ll get insanely large values that will never work.</p>
<p>One workaround is to simply click them <em>in a different order</em>. This is ok, as the calibration application only reports a list of offset values, which can be put to correct places in the <em>xorg.conf</em> file later. The expected tap order is this (i.e. left top corner first, right bottom corner last):</p>
<p>1    2    3<br />
4    5    6<br />
7    8    9</p>
<p>But you should instead click the crosses like this (i.e. right bottom corner first):</p>
<p>9    6    3<br />
8    5    2<br />
7    4    1</p>
<p>As you can see, this order is first Y swapped and then clockwise 90 degree rotated (which matches with <em>Rotate cw, SwapY On, SwapX Off</em> settings that we had to put in <em>xorg.conf</em> file for this display model).</p>
<p>Now you should get values that are close to zero, something like +-20 or lower. Just observe that when you tap, the red color moves to the next cross, but follow the order described above. It is a little confusing, I know! When you&#8217;re done, the calibration software shuts down and you can see the calibration values printed on the screen. You may need to do this a couple of times before you get it right. Now write down the values on a piece of paper or something.</p>
<p>After you&#8217;re done with the calibration tool, you can delete the cursor file:</p>
<blockquote>
<pre>sudo rm /empty_cursor.xbm</pre>
</blockquote>
<p><em>NOTE: In the calibration tool, you might have problems pressing the X marks because you cannot see them properly. You may need to adjust your display&#8217;s settings (to stretch the image) and setup the display configuration properly before calibration. In X, open terminal and write:</em></p>
<blockquote>
<pre><em>sudo displayconfig-gtk</em></pre>
</blockquote>
<p><em>Select </em><em>Model list and find </em><em>LG L1730SF. Check that the resolution is ok, then save to file by clicking the disk icon above, e.g. </em><em>/etc/X11/xorg.conf.new. Then open the file in console, and check that everything seems to be fine &#8211; you might want to comment out some modes and modelines for resolutions that are not supported by this display, i.e. higher than 1280&#215;1024, and uncomment Virtual resolutions, if any. Then make a backup copy and replace your current xorg.conf:</em></p>
<blockquote>
<pre><em>sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
sudo cp /etc/X11/xorg.conf.new /etc/X11/xorg.conf</em></pre>
</blockquote>
<p><em>Restart computer (or just X), and the display should be better configured and calibration now possible to do with the calibration tool.<br />
</em></p>
<p>You can copy the calibration values to your <em>xorg.conf</em> file to the touchscreen section as options, if they are reasonable they should look something like this:</p>
<blockquote>
<pre>Option          "x0"    "+15"
Option          "y0"    "-3"
Option          "x1"    "+6"
Option          "y1"    "-3"
Option          "x2"    "-12"
Option          "y2"    "-6"
Option          "x3"    "+12"
Option          "y3"    "-15"
Option          "x4"    "+6"
Option          "y4"    "-10"
Option          "x5"    "-8"
Option          "y5"    "-6"
Option          "x6"    "+6"
Option          "y6"    "0"
Option          "x7"    "0"
Option          "y7"    "-3"
Option          "x8"    "-6"
Option          "y8"    "-3"</pre>
</blockquote>
<p>Then change <em>Calibration </em>setting to <em>0</em> and restart the computer. Unfortunately, when you start to use X again you&#8217;ll likely notice that <em>Rotate</em> and <em>SwapX/SwapY</em> now work again and the calibration values got from the calibration script do not actually apply to the correct spots on the screen anymore (well, we expected that this would happen). With trial and error, I found this order to work with <em>Rotate cw, SwapY On, SwapX Off</em> settings (Y swapped with respect to how they were collected?):</p>
<p>2    5    8<br />
1    4    7<br />
0    3    6</p>
<p>Here o means x0, y0, 1 means x1, y1, and so on.</p>
<p>However, now that we have some pretty reasonable values and also know which of the nine calibration samples matches with which location on LG L1730SF&#8217;s screen, we can fine tune each spot separately via trial and error, as described next. Note that it is also possible to start from scratch with zero calibration by setting all calibration values in xorg.conf (x0-x8, y0-y8) to zero.</p>
<p>Begin with the corner marked 0 above (bottom left), and respective values x0, y0. Tap to center of the screen and then to corner 0 (left bottom corner) and observe where the cursor jumps. If the cursor is above the place you touched, you need to decrease x0 value (<em>Rotate</em> option swaps X and Y axels!). If the cursor is left to the place you touched, you need to decrease y0 value. The distance between the actual screen and the touch sensor is something like 5 mm, so you should try to look the screen as straight 90 degree angle as possible.</p>
<p>So in practise you open a console with <em>CTRL+ALT+F2</em>, login, load your xorg.conf file and then adjust one calibration value, and save the file. Then switch to GUI with <em>CTRL+ALT+F7</em> and restart X with <em>CTRL+ALT+BACKSPACE.</em> Now you can test the new value. Then switch back to console, change the value, and test again in GUI. Repeat this until you are satisfied.</p>
<p>Hmm, it shouldn&#8217;t be too hard to make at least a simple Gnome/KDE based tool that would get these swaps and rotations correctly, and record the offsets so that they could be directly copied to <em>xorg.conf</em>. Of course even better would be a possibility to try them out &#8220;live&#8221; without hopping between console and X.</p>
<p>Nevertheless, with these instructions you should get the touch feature&#8217;s offsets calibrated, and the good news is that you only need to do it once.</p>
<h3>Virtual keyboard</h3>
<p>After calibration is done, basically the system should be pretty usable. However, it is very common that setups with touch screen do not include a keyboard. Instead, a virtual keyboard is used. We will setup that next.</p>
<p>The default virtual keyboard for Gnome is GOK, but in fact it is quite complicated and &#8230; downright ugly. It is intended to support people with many kinds of  disabilities, and here all we want is some buttons on the screen to touch to write letters etc. A much nicer option is Florence (<a title="Florence virtual keyboard" href="http://florence.sourceforge.net/english.html">http://florence.sourceforge.net/english.html</a>). Unfortunately, there are no binaries available for Ubuntu, so we need to install it from source. First we need to satisfy some dependencies:</p>
<blockquote>
<pre>sudo apt-get install build-essential libxml2-dev libgconf2-dev libglade2-dev libatspi-dev libcairo2-dev libgnome2-dev librsvg2-dev</pre>
</blockquote>
<p>Now, let&#8217;s get the source code:</p>
<blockquote>
<pre>cd ~\Source
mkdir florence
cd florence
wget http://downloads.sourceforge.net/florence/florence-0.3.0.tar.bz2?modtime=1221508202&amp;big_mirror=0</pre>
</blockquote>
<p>Extract, build and install:</p>
<blockquote>
<pre>tar -xjvf florence-0.3.0.tar.bz2
cd florence-0.3.0
./configure --prefix=/usr
make
sudo make install</pre>
</blockquote>
<p>To start it, click <em>Applications-&gt;Universal Access-&gt;Florence Virtual Keyboard</em>. Or, in X open console and write <em>florence</em>. Click OK to enable accessibility and restart Gnome. When Gnome loads, restart Florence. Virtual keyboard now appears.</p>
<p>Florence manual also describes autostart option:<br />
<em> &#8220;If you prefer that Florence is launched at GNOME startup, choose the menu item System-&gt;Preferences-&gt;Sessions, click on the Startup programs tab, then click Add and enter /usr/bin/florence so Florence is launched with GNOME at next boot.&#8221;</em></p>
<p>To enable mouse as well, in <em>xorg.conf</em> uncomment <em>Configured Mouse</em> and comment <em>Core pointer</em> from touch screen.</p>
<p>In the desktop&#8217;s notificators area, a new icon appears for Florence (blue smiley). Click it with mouse&#8217;s right key and select <em>Preferences</em>. Edit the virtual keyboard settings as you wish. I disabled Arrows keypad, Numpad and Function keys, then zoomed to <em>36.0</em>. Note that you should zoom only to integer values, decimals will make the graphics distorted for mouse over effect. Leave Auto click to 0, or you will get doule clicks. Note: if you keep the virtual key pressed (not lift your finger), it will be repeated, as with physical keyboards.</p>
<p>You can also open console and run <em>gconf-editor</em>, then look for <em>apps-&gt;florence</em>, and edit settings. These are partially duplicate to what you can do from Florence&#8217;s Preferences dialog, but there&#8217;s more options! I set them as follows:</p>
<p><em>Behaviour:<br />
- always_on_screen = selected<br />
- auto_click = 0<br />
Colours:<br />
- activated = #F87F18<br />
- key = #000000<br />
- label = #D9C8A0<br />
- mouseover = #E6A43F<br />
- outline = #000000<br />
Layout:<br />
- extensions = Arrows<br />
- file = empty, although it can be found from /usr/share/florence/florence.layout<br />
Window:<br />
- decorated = not selected<br />
- shaped = selected<br />
- zoom = 34<br />
</em></p>
<p>These settings remove the window frame and keyboard background, resulting to keyboard keys only floating on top of the desktop, which is nice. The only problem is that whenever you reboot, Florence relocates the virtual keyboard to top part of the desktop, and since you don&#8217;t have window frame to grab, it is impossible to move it. As Gnome does not support remembering window locations (and they consider it application&#8217;s task to do &#8211; which I strongly disagree), currently the only option is to modify Florence to relocate it to a suitable position on the desktop. Unfortunately, it does not have a setting for this, so the only option is to modify source code:</p>
<blockquote>
<pre>cd ~\Source\florence\florence-0.3.0\src
cp florence.c florence.c.bak
sudo nano florence.c</pre>
</blockquote>
<p>Go to the end of the file, look for <em>main</em> function and the following line:</p>
<blockquote>
<pre> flo_screen_changed(GTK_WIDGET(florence-&gt;window), NULL, florence);</pre>
</blockquote>
<p>Then add these lines below it:</p>
<blockquote>
<pre> // Set initial position of the window to the bottom of the screen:</pre>
<pre> int screen_height=gdk_screen_get_height(gdk_screen_get_default());</pre>
<pre> int screen_width=gdk_screen_get_width(gdk_screen_get_default());</pre>
<pre> gtk_window_move(florence-&gt;window, (screen_width-florence-&gt;width)/2, screen_height-florence-&gt;height);</pre>
</blockquote>
<p>So these come just before this line:</p>
<blockquote>
<pre>gtk_widget_show(GTK_WIDGET(florence-&gt;window));</pre>
</blockquote>
<p>Now save and exit, then compile and install:</p>
<blockquote>
<pre>cd ..
./configure --prefix=/usr
make
sudo make install</pre>
</blockquote>
<p>Restart Florence, now the keyboard appears initially in the bottom of the screen. As holding your arm up makes your muscles ache rather quickly, I believe it is much better to organize the desktop so that user can keep her hand down in rest for most of the time, and even when typing with virtual keyboard the hand will not block the view to the other parts of the screen that are not covered by the virtual keyboard. Therefore, I prefer to have the keyboard located at the bottom of the screen.</p>
<p>Note: in case you don&#8217;t like that blue smiley icon, it is located in <em>/usr/share/icons/florence.svg</em>, you can create a new one with the same name. For example, in <em>/usr/share/icons/Human/scalable/devices/input-keyboard.svg</em> is a nice keyboard icon which you can take into use as follows:</p>
<blockquote>
<pre>cd /usr/share/icons/
cp florence.svg florence.svg.bak
sudo cp /usr/share/icons/Human/scalable/devices/input-keyboard.svg .
sudo mv input-keyboard.svg florence.svg</pre>
</blockquote>
<h3>Tuning the timings</h3>
<p>Modern desktops have been designed to be used with a keyboard and a mouse. A touch screen based setup typically has neither, as the keyboard can be replaced with a virtual keyboard (like we just did), and also the mouse can be emulated with touch. Well, almost! While a typical mouse nowadays has 2-dimensional pointing and at least 2 buttons and a scroll wheel, with touch there&#8217;s basically only a binary type input (pressure/no pressure) and its coordinates. This maps pretty well with a one-button mouse. How about the second mouse button? Scrolling? Dragging? These are all pretty much required capabilities, otherwise desktop usage becomes  somewhat handicapped.</p>
<p>The solution? Well, actually there isn&#8217;t any really good solution. Touch is touch, not a mouse, and you can&#8217;t get around that. The desktop should be designed again so that it can be easily used with touch, at finger tip level precision (not everyone likes the pen). In mobile phone size terminals this is already happening, but on Linux desktop we still need to wait a while to see what comes out of the netbook boom. Meanwhile, we have to manage somehow. One thing that we can utilize is <em>time</em>. An example: short press is left mouse click, long press is right mouse click. Or, long press enables dragging. Unfortunately, humans are not very good at timing at this level, so there really cannot be that much precision put into it. Forget multiple different length &#8220;buttons&#8221;, dealing with &#8220;short press&#8221; and &#8220;long press&#8221; is pretty much all you can get out of it.</p>
<p>This leads to an important decision: while the touch cannot properly emulate a mouse, we need to choose which features will be emulated and which will not be supported at all. Can your use case manage without the second mouse button? Without dragging? Does it still require scrolling, although not dragging? These can be pretty hard to decide some times.</p>
<p>Let&#8217;s take an example. Using a touch screen for <em>drawing </em>is quite obvious idea. And it can be fun, indeed &#8211; much more than drawing with a mouse. However, to be able to draw you must have a possibility to 1) move the pen without leaving a trail, and 2) move the pen leaving a trail. With touch screen, pretty much the only option is to emphasize dragging  type usage so that even very short presses quickly turn to dragging (=moving the pen leaving a trail). Then again, writing is almost always needed &#8211; you do want to save the picture and give it a name, don&#8217;t you? So you need to be able to use a virtual keyboard as well. When you press virtual keys, writing becomes difficult if the touch gestures are easily interpreted as dragging. When you need to write, you&#8217;d prefer that only very long presses turn dragging mode on. But these settings must be configured in <em>xorg.conf</em>, so you cannot change them for example whenever the virtual keyboard is brought visible (which would otherwise be a very good solution, by the way).</p>
<p>For typing with virtual keyboard, you could also consider high <em>MoveLimit</em> value in <em>xorg.conf</em>. For example, with &#8217;100&#8242;, typing is easy as the touch feature&#8217;s mouse emulation mode will not easily switch from tap to drag even if the finger does not stay precisely still, because it takes a fairly big movement until the mouse coordinates will change (remember the jumpiness problem, caused by two large value in this setting).</p>
<p>But on the other hand, clicking links on a web page may become more difficult this way: if you don&#8217;t hit the link straight at the first try, you have to tap <em>elsewhere</em> first to go beyond the move limit so that coordinates change enough, then you can try again at the original spot (otherwise you&#8217;ll just be tapping inside the move limit area and no movement appears). Value &#8217;50&#8242; is a nice compromise, and allows also dragging more precisely, as <em>MoveLimit</em> is applied also during dragging! (I think the driver should be improved so that it applies only when you are <em>beginning</em> a drag gesture; then it should be immediately disabled to allow smooth movement and precise &#8220;drop&#8221;.</p>
<p><em>Evtouch</em> supports timing based differentation in touch gestures. In <em>xorg.conf </em>you can define option <em>LongTouchTimer</em>. When it is set fairly long, such as &#8217;200&#8242;, drag mode will not be easily activated even if the finger rests on the virtual key a bit long. For beginner users it can be even longer, as they get easily confused of different modes. Another <em>xorg.conf </em>option, <em>TapTimer</em> should be set to a small value, so that clicks come quickly after tapping, e.g. &#8217;10&#8242; ms  will make virtual keyboards seem very responsive. For beginners, a slightly longer value may be justified.</p>
<p>In addition to short vs. long presses, there&#8217;s another trick for creating additional input mechanism: one-and-a-half tap. This is like a double click with a mouse, except that you do not release the finger after the second tap. While long press activates dragging, one-and-a-half tap is mainly used as the right mouse button click. However, you cannot simulate right button clicks with one-and-a-half style tap if the <em>TapTimer</em> value is too small, as you don&#8217;t have time for that &#8220;half&#8221; tap before the first gets reported as single (left) mouse click. Value &#8217;50&#8242; makes a noticeable lag when writing with virtual keyboards, still it is not enough for that second tap. Value &#8217;150&#8242; allows second mouse button emulation with one-and-a-half tap, but you still have to be quick and on the other hand, writing becomes somewhat slow. Therefore, if you can manage without that second button, I suggest keeping <em>TapTimer</em> value very short and forgetting the one-and-a-half tap completely. It is also difficult for beginner users, who do not expect that such a thing even exists.</p>
<p>The settings presented above emphasize click style behaviour, and are quite nice for beginners. They are also suitable for normal desktop use, although if you need the second mouse button you have to sacrifice responsiveness via adjusting <em>TapTimer</em> to a longer value.</p>
<p>If you primarily use the touch feature with fingers, you have to keep <em>MoveLimit</em> rather high. If you primarily use a pen for touch, try to set it lower as pen is much more precise and easier to keep steady.</p>
<p>For drawing etc. analog style control, <em>MoveLimit</em> must be small (even down to &#8217;1&#8242;) and you may need to set <em>LongTouchTimer</em> to a very small value, too &#8211; e.g. &#8217;20&#8242;. <em>TapTimer</em> should be set to very low, e.g. &#8217;10&#8242;. Clicking is still possible, but you&#8217;ll miss some of them quite often as they are interpreted as dragging. However, drawing with a painting program is quite nice, as you don&#8217;t have to first touch, then wait, then begin moving the finger/pen, but now you can pretty much draw like with a normal pen. However, although resistive touch panel like LG L1730 SF is quite precise and thus suitable for drawing, it requires some pressure and you need to learn to &#8220;keep the pen on the paper&#8221; steadily while drawing lines and curves, otherwise you&#8217;ll get dotted lines. These settings emphasize mouse drag style behaviour. The cursor follows the finger very rapidly and precisely, but clicking and typing is more difficult because you&#8217;ll miss some clicks much more often.</p>
<p>Note: I have set &#8220;Emulate3Buttons&#8221; option to &#8220;False&#8221;, as I don&#8217;t have any use for that and I believe that simplicity works better with touch feature; one should not try to emulate the mouse completely but focus on the benefit of direct pointing, with as little errors as possible, and with good preciseness and responsiveness.</p>
<p><em>As an example of some kind of compromize of the settings mentioned above, see my </em><em>xorg.conf file, which is attached into the end of the text.</em></p>
<h3>Automatic event channel mapping</h3>
<p>When you reboot the computer, or change the touch screen&#8217;s USB cable from one USB port to another, the event channel that gets mapped to touch feature may change. As the event channel must be fixed in your <em>xorg.conf</em> file, at random boots the touch feature may or may not work.</p>
<p>This can be fixed by adding a udev rule, which will automatically map the touch input to a certain virtual event channel.</p>
<blockquote>
<pre>sudo nano /etc/udev/rules.d/69-touchscreen.rules</pre>
</blockquote>
<p>Add this content if it isn&#8217;t already there:</p>
<blockquote>
<pre># udev.rules for touchscreens</pre>
<pre># ITM Touchscreens</pre>
<pre>SUBSYSTEMS=="usb" ATTRS{idVendor}=="0403" ATTRS{idProduct}=="f9e9", SYMLINK+="input/touch"</pre>
</blockquote>
<p>Save and exit. Then edit <em>xorg.conf</em> and replace fixed event channel with this new automatically mapped event channel:</p>
<blockquote>
<pre>Option          "Device"        "/dev/input/touch"</pre>
</blockquote>
<p>Save and exit. Reboot, and the touchscreen should still work. Also, when you type <em>ls /dev/input</em>, you should see <em>touch</em> somewhere in the output.</p>
<p>Note: you can find out the vendor and product id for example via <em>cat /proc/bus/input/devices</em>, which should output something like this:</p>
<blockquote>
<pre>I: Bus=0003 Vendor=0403 Product=f9e9 Version=0100</pre>
<pre>N: Name="ITM Inc USB Touch Panel"</pre>
<pre>P: Phys=usb-0000:00:0f.4-1/input0</pre>
<pre>S: Sysfs=/devices/pci0000:00/0000:00:0f.4/usb1/1-1/1-1:1.0/input/input9</pre>
<pre>U: Uniq=</pre>
<pre>H: Handlers=mouse2 event9</pre>
<pre>B: EV=b</pre>
<pre>B: KEY=400 0 0 0 0 0 0 0 0 0 0</pre>
<pre>B: ABS=1000003</pre>
</blockquote>
<p>Another, more verbose source is <em>udevinfo -a -p /class/input/input9</em>, where <em>input9</em> comes from the output of the previous command. Here is part of the output:</p>
<blockquote>
<pre>looking at parent device '/devices/pci0000:00/0000:00:0f.4/usb1/1-1':</pre>
<pre>    KERNELS=="1-1"</pre>
<pre>    SUBSYSTEMS=="usb"</pre>
<pre>    DRIVERS=="usb"</pre>
<pre>    ATTRS{dev}=="189:1"</pre>
<pre>    ATTRS{configuration}==""</pre>
<pre>    ATTRS{bNumInterfaces}==" 1"</pre>
<pre>    ATTRS{bConfigurationValue}=="1"</pre>
<pre>    ATTRS{bmAttributes}=="80"</pre>
<pre>    ATTRS{bMaxPower}=="100mA"</pre>
<pre>    ATTRS{urbnum}=="216"</pre>
<pre>    ATTRS{idVendor}=="0403"</pre>
<pre>    ATTRS{idProduct}=="f9e9"</pre>
<pre>    ATTRS{bcdDevice}=="0100"</pre>
<pre>    ATTRS{bDeviceClass}=="00"</pre>
<pre>    ATTRS{bDeviceSubClass}=="00"</pre>
<pre>    ATTRS{bDeviceProtocol}=="00"</pre>
<pre>    ATTRS{bNumConfigurations}=="1"</pre>
<pre>    ATTRS{bMaxPacketSize0}=="8"</pre>
<pre>    ATTRS{speed}=="12"</pre>
<pre>    ATTRS{busnum}=="1"</pre>
<pre>    ATTRS{devnum}=="2"</pre>
<pre>    ATTRS{version}==" 1.10"</pre>
<pre>    ATTRS{maxchild}=="0"</pre>
<pre>    ATTRS{quirks}=="0x0"</pre>
<pre>    ATTRS{authorized}=="1"</pre>
<pre>    ATTRS{manufacturer}=="ITM Inc"</pre>
<pre>    ATTRS{product}=="USB Touch Panel"</pre>
</blockquote>
<h3>Tuning Firefox for touch based browsing</h3>
<p>When you type text to Firefox&#8217;s address bar, it automatically (v. 3.0 onwards) shows a drop down list of possible matches. Unfortunately, this removes focus from virtual keyboard, and basically you need to type every letter twice to regain focus. Fix it as follows:</p>
<p>Write <em>about:config</em> into the address bar, press Enter. Press <em>&#8220;I&#8217;ll be carefull. I promise!&#8221;</em> button. Enter <em>browser.urlbar</em> in the Filter field. Change <em>browser.urlbar.maxRichResults</em> to 0. Change <em>browser.urlbar.search.timeout</em> to 3000. Restart firefox.</p>
<p>Other good firefox tweaks:</p>
<ul>
<li>Turn <em>browser.urlbar.clickSelectsAll</em> to True</li>
<li>Turn <em>general.smoothscroll</em> to True</li>
</ul>
<p>In addition to <em>about:config</em> properties, you can create two configuration files:</p>
<blockquote>
<pre>cd ~/.mozilla/firefox
ls</pre>
</blockquote>
<p>From list of files, check the one that ends <em>.default</em> and <em>cd</em> there. Then continue:</p>
<blockquote>
<pre>cd chrome
ls</pre>
</blockquote>
<p>This shows examples of configuration files.</p>
<blockquote>
<pre>cp userChrome-example.css userChrome.css
nano userChrome.css</pre>
</blockquote>
<p>Now edit the file, save, exit, restart Firefox and settings are enabled.</p>
<p>E.g. some possible settings for touch screen usage:</p>
<blockquote>
<pre>  /*</pre>
<pre>   * Make page URL font monospaced and bigger.</pre>
<pre>   */</pre>
<pre>  #urlbar{</pre>
<pre>      font-family: verdana !important;</pre>
<pre>      font-size: 15pt !important;</pre>
<pre>  }</pre>
<pre>  /*</pre>
<pre>   * Make bookmark sidebar font Verdana and bigger.</pre>
<pre>   */</pre>
<pre>  tree {</pre>
<pre>      font-family: verdana !important;</pre>
<pre>      font-size: 13pt !important;</pre>
<pre>  }</pre>
</blockquote>
<p>With these settings, it is easier to type new URL with virtual keyboard, and click existing bookmarks in the sidebar.</p>
<h3>Gnome scrollbars</h3>
<p>Scrollbars are much easier to use if you make them wider.</p>
<p>Create file <em>.gtkrc-2.0</em> into your home directory, then add these lines:</p>
<blockquote>
<pre>style "wide-scrollbars"
{
    GtkRange       ::slider_width      = 30
    GtkRange       ::stepper_size      = 30
}
class "GtkRange"  style "wide-scrollbars"</pre>
</blockquote>
<p>Save. Log out, log in and all scrollbars should be wider now.</p>
<h3>Miscellaneous tips</h3>
<ul>
<li>In Gnome&#8217;s file manager, change to &#8220;Single click to open items&#8221;.</li>
<li>Custom mouse pointer theme? Blank, except when you click -&gt; blinks once, and<br />
when you drag -&gt; visible hand.</li>
<li>When you boot the computer, Ubuntu will show the login screen. How to log in, if there is no keyboard? Virtual keyboard is not started and available yet. The   easiest way is to create an unprivileged, common user and make it auto-login. To add/remove/modify users, select System-&gt;Administration-&gt;Users and Groups, and create a user with low privileges. To enable auto-login: System-&gt;Administration-&gt;Login Window, then select Security tab, and select Enable Automatic Login, select user to log in. Close, and reboot. The user you selected should be automatically logged in.</li>
</ul>
<h3>My xorg.conf file</h3>
<p>Just for reference, this is my <em>xorg.conf</em> file:</p>
<blockquote>
<pre># xorg.conf (X.Org X Window System server configuration file)
#
# This file was generated by dexconf, the Debian X Configuration tool, using
# values from the debconf database.
#
# Edit this file with caution, and see the xorg.conf manual page.
# (Type "man xorg.conf" at the shell prompt.)
#
# This file is automatically updated on xserver-xorg package upgrades *only*
# if it has not been modified since the last upgrade of the xserver-xorg
# package.
#
# If you have edited this file but would like it to be automatically updated
# again, run the following command:
#   sudo dpkg-reconfigure -phigh xserver-xorg

Section "InputDevice"
        Identifier      "Generic Keyboard"
        Driver          "kbd"
        Option          "XkbRules"      "xorg"
        Option          "XkbModel"      "pc105"
        Option          "XkbLayout"     "fi"
EndSection

Section "InputDevice"
        Identifier      "Configured Mouse"
        Driver          "mouse"
        Option          "CorePointer"
EndSection

Section "InputDevice"
        Identifier      "TouchScreen"
        Driver          "evtouch"
        Option          "Device"        "/dev/input/touch"
        Option          "DeviceName"    "TouchScreen"
        Option          "MinX"  "340"
        Option          "MinY"  "200"
        Option          "MaxX"  "3850"
        Option          "MaxY"  "3950"
        Option          "x0"    "+15"
        Option          "y0"    "-3"
        Option          "x1"    "+6"
        Option          "y1"    "-3"
        Option          "x2"    "-12"
        Option          "y2"    "-6"
        Option          "x3"    "+12"
        Option          "y3"    "-15"
        Option          "x4"    "+6"
        Option          "y4"    "-10"
        Option          "x5"    "-8"
        Option          "y5"    "-6"
        Option          "x6"    "+6"
        Option          "y6"    "0"
        Option          "x7"    "0"
        Option          "y7"    "-3"
        Option          "x8"    "-6"
        Option          "y8"    "-3"
        Option          "ButtonNumber"  "2"
        Option          "ReportingMode" "Raw"
        Option          "Emulate3Buttons"       "False"
        Option          "Emulate3Timeout"       "50" #50
        Option          "DebugLevel"    "0"
        Option          "TapTimer"      "5"
        Option          "LongTouchTimer"        "200"
        Option          "MoveLimit"     "50"
        Option          "SendCoreEvents"        "On"
        Option          "Rotate"        "cw"
        Option          "SwapX" "Off"
        Option          "SwapY" "On"
        #Option         "ScreenNumber"  "0"
        #Option         "Calibrate"     "1"
EndSection

Section "InputDevice"
        Identifier      "dummy"
        Driver          "void"
        Option          "Device"        "/dev/input/mice"
EndSection

Section "Device"
        Identifier      "Configured Video Device"
        Boardname       "geode"
        Busid           "PCI:0:1:1"
        Driver          "geode"
        Screen  0
EndSection

Section "Monitor"
        Identifier      "Configured Monitor"
        Vendorname      "LG Electronics Inc."
        Modelname       "LG L1730SF"
        Horizsync       30.0-83.0
        Vertrefresh     56.0-75.0
  modeline  "640x480@60" 25.2 640 656 752 800 480 490 492 525 -vsync -hsync
  modeline  "640x480@72" 31.5 640 664 704 832 480 489 491 520 -vsync -hsync
  modeline  "640x480@75" 31.5 640 656 720 840 480 481 484 500 -vsync -hsync
  modeline  "800x600@56" 36.0 800 824 896 1024 600 601 603 625 +hsync +vsync
  modeline  "800x600@72" 50.0 800 856 976 1040 600 637 643 666 +hsync +vsync
  modeline  "800x600@75" 49.5 800 816 896 1056 600 601 604 625 +hsync +vsync
  modeline  "800x600@60" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync
  modeline  "832x624@75" 57.284 832 864 928 1152 624 625 628 667 -vsync -hsync
  modeline  "1024x768@75" 78.8 1024 1040 1136 1312 768 769 772 800 +hsync +vsync
  modeline  "1024x768@70" 75.0 1024 1048 1184 1328 768 771 777 806 -vsync -hsync
  modeline  "1024x768@60" 65.0 1024 1048 1184 1344 768 771 777 806 -vsync -hsync
  modeline  "1152x864@75" 108.0 1152 1216 1344 1600 864 865 868 900 +hsync +vsync
  modeline  "1280x1024@75" 135.0 1280 1296 1440 1688 1024 1025 1028 1066 +hsync +vsync
  modeline  "1280x960@60" 102.1 1280 1360 1496 1712 960 961 964 994 -hsync +vsync
  modeline  "1280x1024@60" 108.0 1280 1328 1440 1688 1024 1025 1028 1066 +hsync +vsync
  modeline  "1280x960@75" 129.86 1280 1368 1504 1728 960 961 964 1002 -hsync +vsync
#  modeline  "1400x1050@60" 122.61 1400 1488 1640 1880 1050 1051 1054 1087 -hsync +vsync
#  modeline  "1400x1050@75" 155.85 1400 1496 1648 1896 1050 1051 1054 1096 -hsync +vsync
#  modeline  "1600x1200@65" 175.5 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync
#  modeline  "1600x1200@60" 162.0 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync
#  modeline  "1792x1344@60" 204.8 1792 1920 2120 2448 1344 1345 1348 1394 -hsync +vsync
        Gamma   1.0
EndSection

Section "Screen"
        Identifier      "Default Screen"
        Monitor         "Configured Monitor"
        Device          "Configured Video Device"
        Defaultdepth    16
        SubSection "Display"
                Depth   16
                #Virtual        1792    1344
                Modes           "1280x1024@60"  "1280x960@75"   "1280x960@60"   "1280x1024@75"  "1152x864@75"   "1024x768@60"   "1024x768@70"   "1024x768@75$
        EndSubSection
EndSection

Section "ServerLayout"
        Identifier      "Default Layout"
  screen 0 "Default Screen" 0 0
        Inputdevice     "TouchScreen"   #"CorePointer"
        Inputdevice     "Configured mouse"
        #InputDevice    "dummy"
EndSection

Section "Module"
        Load            "glx"
        Load            "GLcore"
        Load            "v4l"
EndSection

Section "ServerFlags"
EndSection</pre>
</blockquote>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 3932px; width: 1px; height: 1px;">http://florence.sourceforge.net/english.html</div>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/08/16/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>LG L1730SF touch screen display in Ubuntu Linux 8.04 Hardy Heron, part 2</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/08/10/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-2/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/08/10/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-2/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 18:23:53 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[Evtouch]]></category>
		<category><![CDATA[Hardy Heron]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[touch screen]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=171</guid>
		<description><![CDATA[Let&#8217;s continue with setting up the touch feature. In the end of part 1, we managed to rotate and mirror the display properly and just started calibrating it, when we encountered a problem where the cursor at first does not seem to follow the finger, and then suddenly jumps ahead. Let&#8217;s solve that next. Note: [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s continue with setting up the touch feature. In the end of <a title="Part 1" href="http://www.rantakokko.net/tapani/blog/2009/04/29/lg-l1730sf-touch-screen-display-in-ubuntu-linux-804-hardy-heron/">part 1</a>, we managed to rotate and mirror the display properly and just started calibrating it, when we encountered a problem where the cursor at first does not seem to follow the finger, and then suddenly jumps ahead. Let&#8217;s solve that next.</p>
<p><strong>Note: You should only read this through, you don&#8217;t need to repeat everything I did. The actual solution is in the end of the text, so there&#8217;s what you need to do.</strong></p>
<p>Since we now have two drivers in the system for the touch feature, <em>usbtouchscreen</em> for the display device and <em>evtouch</em> for converting the input events to a suitable format for X, the first question that comes to mind is, which one of the drivers is causing the jumpiness? We should go to the source of the information first, i.e. <em>usbtouchscreen</em>.</p>
<p><span id="more-171"></span></p>
<p>When you move your finger on the screen, does the data that is output from the <em>usbtouchscreen</em> driver actually change continuously, or does it first stay the same and then suddenly change when the jump occurs? One test could be to type <em>sudo cat /dev/input/eventX</em>, where X represents the event number in your system (recall that you can use <em>cat /proc/bus/input/devices</em> to find it out), but its output is all gibberish. A better alternative is to use a tool that decrypts the event data to plain text. One suitable tool is <em>evtest</em>, which can be found in <em>dvb-utils</em> (yes, tools for watching TV!) package. That package is located in Ubuntu universe repository that we have already enabled. To install it, type</p>
<blockquote>
<pre>sudo apt-get install dvb-utils</pre>
</blockquote>
<p>Now you can observe the output of the driver as informative textual message by typing</p>
<blockquote>
<pre>sudo evtest /dev/input/eventX</pre>
</blockquote>
<p>(replace X with your event number).</p>
<p>This test reveals for example that 1) as long as you keep your finger on the screen, new data keeps coming in, 2) the display reports the pressure too, although it seems to me somewhat random, 3) when you keep your finger still, you&#8217;ll get mainly events with all fields zeros, whereas when you keep moving your finger, values seem to be more reasonable, and 4) the X and Y coordinate values are quite hard to pick from the information stream. Press CTRL+C to stop now.</p>
<p>To get a better idea of the actual coordinates, we can filter the output to only contain Y coordinates with the following command: <em> </em></p>
<blockquote>
<pre>sudo evtest /dev/input/eventX/ | grep Y</pre>
</blockquote>
<p>(replace X with your event number). However, when you are testing, remember that X and Y axels are swapped! When tapping the left edge, the values are near 3950. Right edge yields 200. You can use the same technique to observe the X axel (<em>grep X</em>). When tapping the bottom edge, I got values near 340, and when tapping the top edge, it was somewhere near 3850. These values are very useful for calibration (you can use them in your <em>xorg.conf</em> file), but what is even more important is that when you move your finger, the values seem to grow gradually and continuously. Now we can be sure that <em>usbtouchscreen</em> driver is working just fine, and <strong>the jumpiness problem is somehow caused by <em>evtouch</em></strong>.</p>
<p>When using the values from the previous step for calibration settings in the <em>xorg.conf</em> file (instead of the max range values 0, 4095), I got better coverage of the whole screen area with the touch control, although it is still jumpy. I calculated that there are 20 locations along X axel and also 20 locations along Y axel, or 20&#215;20 grid of which intersections the mouse cursor will stop. This is interesting: same amount of stops for both axels, although the screen is not square! Another thing is that when you draw back and forth for a couple of times, possibly sometimes lifting your finger for a while, the cursor does not return to exactly same spots on the screen (you can test that easily with a piece of paper, do not use a marker pen on your screen <img src='http://www.rantakokko.net/tapani/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . In other words, the grid is not fixed but seems to drift a little. This also means that it does not start from 0 coordinate points at the sides of the screen. So, what is going on here? We need to dive in to <em>evtouch&#8230;</em></p>
<h3>Evtouch torn open</h3>
<p>Next, we can try to find out more about the <em>evtouch</em> driver to learn why it makes the cursor to jump. In console, type command <em> </em></p>
<blockquote>
<pre>sudo updatedb</pre>
</blockquote>
<p>and then <em> </em></p>
<blockquote>
<pre>locate evtouch</pre>
</blockquote>
<p>to find out what files have been installed to the system that include the term <em>evtouch</em>. This reveals for example that there is some readme files in <em>/usr/share/doc/xserver-xorg-input-evtouch</em> folder, which describe the calibration procedure etc. &#8211; we will get back to that later. It also reveals that the Debian style package that contained the driver has been cached in the system here: <em>/var/cache/apt/archives/xserver-xorg-input-evtouch_0.8.7-3ubuntu1_i386.deb</em>. The package itself can be manipulated with <em>dpkg-deb</em> tool to list its contents:</p>
<blockquote>
<pre>dpkg-deb --contents /var/cache/apt/archives/xserver-xorg-input-evtouch_0.8.7-3ubuntu1_i386.deb</pre>
</blockquote>
<p>This reveals that in addition to readme etc. informational files, the driver package contains these files:</p>
<ul>
<li><em>calibrate.sh</em> and <em>ev_calibrate</em> scripts in <em>/usr/lib/xf86-input-evtouch</em></li>
<li><em>evtouch_drv.so</em> driver in <em>/usr/lib/xorg/modules/input</em></li>
<li><em>empty_cursor.xbm</em> image in <em>/usr/share/xf86-input-evtouch</em></li>
</ul>
<p>However, anything in these files could not reveal what is causing the jumpiness. So, once again, let&#8217;s look at the source code.</p>
<p>You can download source code for <em>evtouch</em> driver from <a title="Evtouch source code" href="http://www.conan.de/touchscreen/evtouch.html"><em>http://www.conan.de/touchscreen/evtouch.html</em></a>. At the bottom of the page, there are many download links. Use this one: <em>X driver sources V0.8.7      xf86-input-evtouch-0.8.7.tar.bz2</em>. Download the package and extract it somewhere so that you can look at the files that it contains. There are a lot of files, but only a few with .h and .c filename extensions; these are the source files. As files related to calibration are not necessary for normal operation, you are left with these four files: <em>evtouch.h, evtouch.c, libtouch.h, </em>and <em>libtouch.c. </em>So, there are basically two modules: one is the actual driver, the other contains a state machine for converting taps to mouse clicks. Also, there is <em>INSTALL.txt</em> file that describes a) how to compile the driver and install it, and b) how to turn debug printing on. Let&#8217;s do these steps next, so that we can begin testing and modifying the driver.</p>
<p>First, because we&#8217;re going to compile the driver, we need the build tools:</p>
<blockquote>
<pre>sudo apt-get build-essential</pre>
</blockquote>
<p>Let&#8217;s also download and extract the driver source package to a suitable folder:</p>
<blockquote>
<pre>cd ~</pre>
<pre>mkdir Source</pre>
<pre>cd Source</pre>
<pre>mkdir evtouch</pre>
<pre>cd evtouch</pre>
<pre>wget http://www.conan.de/touchscreen/xf86-input-evtouch-0.8.7.tar.bz2</pre>
<pre>tar -xjf xf86-input-evtouch-0.8.7.tar.bz2</pre>
<pre>cd xf86-input-evtouch-0.8.7</pre>
</blockquote>
<p><em>INSTALL.txt</em>, which contains instructions for compiling and installing from source, says that we need to have sources also for XFree86. However, in Ubuntu we have X.org, which is a newer fork of XFree86 (you can read more about this here: <a title="X.org vs. XFree86" href="http://ubuntuforums.org/showthread.php?t=87794">http://ubuntuforums.org/showthread.php?t=87794</a>). The installation instructions seem somewhat outdated, so we will not follow them exactly. To check X.org version, you can type this:</p>
<blockquote>
<pre>cat /var/log/Xorg.0.log | grep "X.Org X Server"</pre>
</blockquote>
<p>I got this line: <em>X.Org X Server 1.4.0.90</em>. Note that the debug output of the driver will go to this same file, <em>/var/log/Xorg.0.log</em> &#8211; we&#8217;ll come back to that later. Assuming you are still in the folder that contains the driver source files, type</p>
<blockquote>
<pre>./configure</pre>
</blockquote>
<p>to prepare for building the driver. You may get errors, for example: <em>No package &#8216;xorg-server&#8217; found</em>, <em>No package &#8216;xproto&#8217; found</em>. To solve these, you need to install related source packages and try to configure the driver again:</p>
<blockquote>
<pre>sudo apt-get install xserver-xorg-dev
./configure</pre>
</blockquote>
<p>This time I got no errors and a ready makefile as output:<br />
<em> config.status: creating Makefile<br />
config.status: creating config.h<br />
config.status: executing depfiles commands<br />
</em></p>
<p>Next, let&#8217;s compile the driver with debug output and raw packets output turned on:</p>
<blockquote>
<pre>make DEBUG=y LOGRAW=y</pre>
</blockquote>
<p>Unfortunately, I got compilation errors: <em>evtouch.c: In function &#8216;DeviceOn&#8217;: evtouch.c:495: error: invalid use of void expression</em>. If you google around, you&#8217;ll notice that other people have had the same problem, apparently because the driver is compatible with Xorg 6.8.x and we have 7.3 in Ubuntu Hardy Heron. Someone even went on to create a new driver (<a title="Another touch driver for X.org" href="http://www.plop.at/en/touchscreen.html">http://www.plop.at/en/touchscreen.html</a>), I haven&#8217;t tested that as currently I prefer to get the most common driver, <em>evtouch</em> to work.</p>
<p>So, let&#8217;s fix the error. Line 495 contains this text: <em> </em></p>
<blockquote>
<pre>DBG (9, XisbTrace (priv-&gt;buffer, 1));</pre>
</blockquote>
<p>We can see that it is used for debugging with a debug macro. If you run</p>
<blockquote>
<pre>grep DGB *</pre>
</blockquote>
<p>in the driver&#8217;s source folder, you can see that <em>DBG</em> macro is defined in <em>libtouch.c</em> file:</p>
<blockquote>
<pre> #define DBG(lvl, f) {if ((lvl) &lt;= debug_level) f;}</pre>
</blockquote>
<p>This means that if the given number is at most the same contained in <em>debug_level</em> variable, we should run the given function <em>f</em>. We don&#8217;t need to debug the contents of the buffer, so we can safely comment it out as follows:</p>
<blockquote>
<pre>// #define DBG(lvl, f) {if ((lvl) &lt;= debug_level) f;}</pre>
</blockquote>
<p>Now we can compile again:</p>
<blockquote>
<pre>make DEBUG=y LOGRAW=y</pre>
</blockquote>
<p>and it succeeds without errors. Next, type</p>
<blockquote>
<pre>sudo make install</pre>
</blockquote>
<p>to install the newly compiled driver.</p>
<p>We need to make sure that X will begin to use our own, compiled driver. Recall that we installed the binary release already, <em>evtouch_drv.so</em> driver located in <em>/usr/lib/xorg/modules/input</em>. We will rename that as follows:</p>
<blockquote>
<pre>cd /usr/lib/xorg/modules/input
sudo mv sudo mv evtouch_drv.so evtouch_drv.so.orig</pre>
</blockquote>
<p>Then press <em>CTRL+ALT+F7</em> to go to X, and restart it with <em>CTRL+ALT+BACKSPACE</em>. In my case, the touch feature stopped working now, so I checked the errors:</p>
<blockquote>
<pre>cat /var/log/Xorg.0.log | grep EE</pre>
</blockquote>
<p>Which revealed this:</p>
<blockquote>
<pre>(EE) Failed to load module "evtouch" (module does not exist, 0)
(EE) Failed to load module "void" (module does not exist, 0)</pre>
<pre>(EE) No Input driver matching `evtouch'</pre>
<pre>(EE) No Input driver matching `void'</pre>
</blockquote>
<p>Apparently, the installation script did not install the driver to correct location. With</p>
<blockquote>
<pre>sudo updatedb</pre>
<pre>locate evtouch_drv.so</pre>
</blockquote>
<p>you can see that it went to here: <em>/usr/local/lib/xorg/modules/input/evtouch_drv.so</em>. So, lets copy that to correct place:</p>
<blockquote>
<pre> sudo mv /usr/local/lib/xorg/modules/input/evtouch_drv.so /usr/lib/xorg/modules/input/evtouch_drv.so</pre>
</blockquote>
<p>Now, try to restart X again. For some reason, Ubuntu switched to safe mode in graphics, and began to use <em>usbtouchscreen</em> without <em>evtouch</em>. Apparently, there is something wrong with the driver, although the source code is supposed to be the latest version. To get rid of the safemode, I had to boot the computer. I wanted to see if <em>DEBUG=y</em> <em>LOGRAW=y</em> parameters had any problems, so I built the driver again and tested it without them as follows:</p>
<blockquote>
<pre> make clean
 ./configure
 make
 sudo make install
 sudo mv /usr/local/lib/xorg/modules/input/evtouch_drv.so /usr/lib/xorg/modules/input/evtouch_drv.so</pre>
</blockquote>
<p>In X, <em>CTRL+ALT+BACKSPACE</em> restulted again to failsafe mode. Apparently, the driver that is compiled directly from source does not work properly as-is. This is getting pretty laborious now.</p>
<h3>Get patched</h3>
<p>Next, I found out that there are many patches available for the driver in Debian&#8217;s (Ubuntu is based on Debian) packages: <a title="Debian's Evtouch patches" href="http://git.debian.org/?p=pkg-xorg/driver/xserver-xorg-input-evtouch.git;a=tree;f=debian/patches;hb=HEAD">http://git.debian.org/?p=pkg-xorg/driver/xserver-xorg-input-evtouch.git;a=tree;f=debian/patches;hb=HEAD</a></p>
<p>The file <em>series</em> contains this information:</p>
<blockquote>
<pre> 1 #02-buttonless-device.patch</pre>
<pre> 2 #03_fix_compile_warns.patch</pre>
<pre> 3 04_include_xf86_ansic_h.patch</pre>
<pre> 4 #05_build_with_1_4.patch</pre>
<pre> 5 06_xf86-input-evtouch-0.8.7-misc.patch</pre>
<pre> 6 07_random_fixes_for_06.patch</pre>
</blockquote>
<p>So I decided to merge the patches 04, 06 and 07 to the source code that I loaded from <em>evtouch</em> module&#8217;s home page, after reviewing the comments in patch files. Especially patch 06 seemed promising with this comment in it: <em>Changed code to compile a working driver for both XInput ABI 0.x and 2.0 (Xorg 1.4.0)</em>. Recall that Hardy Heron&#8217;s X server version is 1.4.0.90. I loaded the raw patch files with a web browser, copied them to <em>evtouch</em> driver&#8217;s source folder and applied them like this:</p>
<blockquote>
<pre>patch -p1 &lt; debian_patches_04_include_xf86_ansic_h.patch
patch -p1 &lt; debian_patches_06_xf86-input-evtouch-0.8.7-misc.patch</pre>
</blockquote>
<p>Now I got an error saying: <em>1 out of 22 hunks FAILED &#8212; saving rejects to file evtouch.c.rej</em>. With <em>cat evtouch.c.rej</em> I saw that this change was related to that one line with improper <em>DBG</em> macro usage, which we commented out ourself. No problem, continue:</p>
<blockquote>
<pre>patch -p1 &lt; debian_patches_07_random_fixes_for_06.patch</pre>
</blockquote>
<p>After applying the patches, I recompiled and tried again. I also learned from Debian packages that I don&#8217;t need to manually copy the driver to correct location, if I give the path in configuration step as follows:</p>
<blockquote>
<pre> make clean
 ./configure --prefix=/usr
 make
 sudo make install</pre>
</blockquote>
<p>In X, give <em>CTRL+ALT+BACKSPACE</em>. This time it did not go to failsafe mode, and the touchscreen worked just like with the pre-built driver version &#8211; jumpy.</p>
<p>Now that we have a working setup for building the driver, we can begin modifying it. First thing is to rebuild with debug and raw output:</p>
<blockquote>
<pre>make clean
 ./configure --prefix=/usr
 make DEBUG=y LOGRAW=y
 sudo make install</pre>
</blockquote>
<p>In X, give <em>CTRL+ALT+BACKSPACE</em>. The touchscreen works as earlier, and there is no debug information. Apparently, because I did not raise the debug level! Do it like this: in <em>evtouch.c</em>, line 109:</p>
<blockquote>
<pre>static int debug_level = 3;</pre>
</blockquote>
<p>i.e. use higher value than 0, at least 2. The higher the value, the more information you get into the log file. However, after recompilation the debug information still did not appear! It seems that the parameters <em>DEBUG=y</em> and <em>LOGRAW=y</em> do now work and <em>INSTALL.txt</em> really is outdated. For example, if you do <em>grep LOGRAW *</em>, you&#8217;ll see that the parameter is only mentioned in <em>INSTALL.txt</em> file &#8211; so how could it work. However, the <em>DBGOUT</em> macros are in place in the source files, so we can manually turn the debug printing and raw logging on as follows: in file <em>evtouch.h</em>, just below line <em>#define _evtouch_H_</em>, add these two lines:</p>
<blockquote>
<pre> #define EVDBG
 #define LOG_RAW_PACKET</pre>
</blockquote>
<p>Recompile, install and test as usual. This time, debug information appears into the log file. You can view it easily like this:</p>
<blockquote>
<pre>less /var/log/Xorg.0.log</pre>
</blockquote>
<h3>Reading the log</h3>
<p>As you use the touchscreen, new information is added to the file, and this command prints it on the screen so that you can view it easily:</p>
<blockquote>
<pre> tail -f /var/log/Xorg.0.log</pre>
</blockquote>
<p>Let&#8217;s see if we can find out anything from debug information. I could see that the screen resolution and desktop size were recognized correctly, and the viewport was initialized ok. To observe if jumpiness is already in the input, I used this command:</p>
<blockquote>
<pre>tail -f /var/log/Xorg.0.log | grep FIRST</pre>
</blockquote>
<p>and swiped the screen slowly with my finger from left to right &#8211; and I could clearly see how the number first stayed the same and then suddenly jumped! The other alternative would have been input is ok, but calibration goes wrong. Anyway, I moved my finger slowly up, then back down, observing and writing down the numbers. The jump was about 200, most typically 198 (these are not screen pixels, but values from the touch screen. This appeared to be the same for both X and Y axels. <strong>Warning: the size of the file <em>/var/log/Xorg.0.log</em> grows pretty fast to tens of megabytes with logging, don&#8217;t play around too long (it grows mostly when you touch the screen).</strong></p>
<p>Next question is: what happens to the data before this step? It was alright in the event channel where data was pushed from <em>usbtouchscreen</em>. This debug print comes from function <em>ConvertProc</em>, and these are parameter values that are printed directly, without modification. Thus they are wrong before given to <em>ConvertProc</em>. So, who calls <em>ConvertProc</em> function? Its interesting that in the original, unpatched driver version it does not seem to be called at all in <em>evtouch.c</em> file&#8217;s functions. However, in the patched version, there are new functions in the end of the file, and it is called from there. Since there are 4 functions and I don&#8217;t know which one is called, I added</p>
<blockquote>
<pre>DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);</pre>
</blockquote>
<p>in the beginning of each of these functions, and rebuild the driver. It turned out that when you tap the screen, many one of these gets called. And when you trace the data path<br />
backwards, next you get <em>ReadInput</em> function. There is a debug print function that prints the input event&#8217;s basic information: type, code and value. When you do this</p>
<blockquote>
<pre>tail -f /var/log/Xorg.0.log | grep ReadInput</pre>
</blockquote>
<p>you can observe what data comes in. When you tap the screen, many lines are printed onto the screen:</p>
<p><em>EVTouch: ReadInput type:01 code: 0x014a value:1<br />
EVTouch: ReadInput type:03 code: 0&#215;0000 value:2086<br />
EVTouch: ReadInput type:03 code: 0&#215;0001 value:2153<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:214<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:215<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:216<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:217<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:218<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:219<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:220<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:221<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:222<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:223<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:224<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:226<br />
EVTouch: ReadInput type:00 code: 0&#215;0000 value:0<br />
EVTouch: ReadInput type:03 code: 0&#215;0018 value:227<br />
&#8230;<br />
</em><br />
When I looked at the data, I noticed the first 3 lines: the first one probably is some kind of initiator (screen tapped), the next two are the coordinates from the touch sensor. What is the rest of the data? Why there is so much of it? Then I got it: the values close to 200 are the pressure data. There are many of them because you can keep pressing the same spot on the screen, but alter the pressure. Sampling is fast, so even from a short tap you get many, many samples. Next, try this:</p>
<blockquote>
<pre>tail -f /var/log/Xorg.0.log | grep "ReadInput type:03 code: 0x0000"</pre>
</blockquote>
<p>When you move your finger across the screen, the values are changing just fine &#8211; no jumpiness. Then why doesn&#8217;t the cursor move as it should?</p>
<h3>Move limit!</h3>
<p>When looking at the code, I noticed that the <em>EVTouchProcessAbs</em> function does not store the X and Y values, if they don&#8217;t differ enough from previously set values, and there is a variable for this limit, it is called <em>move_limit</em> in the code. This did not exist in the original driver, it was added in one of the patches (that otherwise made the driver to work with this Xorg version). In function <em>EVTouchPreInit</em>, this value is initialized in code to <em>180</em>, and it stays in that value UNLESS you configure it differently in your <em>xorg.conf</em> file. Of course, you need to KNOW that such a value exist. And you need to KNOW that the version of the driver that you get with Ubuntu is NOT the original one, but a patched version where many new features have been added. This is just one of them.</p>
<p>Now you can set the debug_level back to 0, and remove debug definitions from <em>evtouch.h</em> file to disable debugging. Recompile and apply.</p>
<p><strong>So, finally to fix the issue: you do not need to compile the driver at all, just use the one provided with Ubuntu, and edit your <em>xorg.conf</em> file as follows:</strong></p>
<blockquote>
<pre>sudo nano /etc/X11/xorg.conf</pre>
</blockquote>
<p>Then go to the touch screen section and add this parameter:</p>
<blockquote>
<pre>Option         "MoveLimit"     "180"</pre>
</blockquote>
<p>But change the value to smaller! In fact, I found the original patch from the web and there in comments the author explains his <em>xorg.conf</em> file and has used value <em>18</em> (!) there, but in code it is set to 180! And, I even found a bug created for Debian about too high default value: <a title="Debian Evtouch default value bug" href="http://lists.debian.org/debian-x/2008/06/msg01287.html">http://lists.debian.org/debian-x/2008/06/msg01287.html</a></p>
<p>So, in the end, the solution was really simple, it was just a configuration bug. But it took quite a lot of work and some crazy stubbornness to find this out.</p>
<p>In <a title="3rd part" href="http://www.rantakokko.net/tapani/blog/2009/08/16/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-3/">part 3</a>, we will finally continue to fine-tuning the calibration of the touch feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/08/10/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Arduino in Eagle schematics with Ubuntu Linux</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/05/28/using-arduino-in-eagle-schematics-with-ubuntu-linux/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/05/28/using-arduino-in-eagle-schematics-with-ubuntu-linux/#comments</comments>
		<pubDate>Thu, 28 May 2009 20:49:55 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Eagle]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=76</guid>
		<description><![CDATA[In electronics projects it is a common task to draw schematic of a circuit that you have designed. For simple circuits, it may be tempting to draw them on paper with a pencil. However, CAD programs are definetely worth learning! One of the best tools is Eagle, which runs on Windows, Mac and Linux. There [...]]]></description>
			<content:encoded><![CDATA[<p><em>In electronics projects it is a common task to draw schematic of a circuit that you have designed. For simple circuits, it may be tempting to draw them on paper with a pencil. However, CAD programs are definetely worth learning! One of the best tools is Eagle, which runs on Windows, Mac and Linux. There is even a freeware Light version available for hobby projects. This article briefly explains how you can use Eagle on Ubuntu Linux for drawing schematics especially for your own Arduino projects.</em></p>
<h3>Installing Eagle on Ubuntu Linux</h3>
<p>Obviously the first step is to install Eagle on your Ubuntu Linux computer.</p>
<p>The easiest way to install Eagle in Ubuntu is via Applications-&gt;Add/Remove&#8230;, where you can simply type &#8220;Eagle&#8221; in the search box to find <em>Eagle</em> from Ubuntu software repository. In Ubuntu 8.04, Eagle is located in the <em>multiverse</em> repository, which must be enabled before installation.</p>
<p>Unfortunately, the version in Ubuntu repository is rather old: 4.16r2-1. You probably want to install the latest version, which can be downloaded with a web browser directly from Cadsoft: <a title="Eagle download page" href="http://www.cadsoft.de/download.htm">http://www.cadsoft.de/download.htm</a>. You should choose the Linux version, right click the download link, and select &#8220;Save Link As&#8230;&#8221;. After downloading is finished, you can install the package (the file you downloaded, e.g. &#8220;eagle-lin-5.6.0.run&#8221;) by opening a console and running the installation script as follows:</p>
<blockquote>
<pre>sh eagle-lin-5.6.0.run</pre>
</blockquote>
<p><span id="more-76"></span>Extracting the package contents takes a while, then a graphical installation wizard appears. You can accept the defaults and begin installation, unless you want to change the installation directory first. After copying the files the wizard requests a license file. Just select &#8220;Run as Freeware&#8221;, and the setup is then complete.</p>
<p>For your convenience, you might want to add a shortcut in the Ubuntu application menu as follows:</p>
<ul>
<li>Select System-&gt;Preferences-&gt;Main Menu</li>
<li>Select Applications-&gt;Programming</li>
<li>Click button &#8220;New Item&#8221;</li>
<li>Settings: For Name type &#8220;Eagle 5.6.0&#8243;, for Command click Browse&#8230; and go to [Eagle installation directory]\bin, then select file named <em>eagle</em></li>
<li>Click OK</li>
<li>New item should be visible now, and even the Eagle icon in place</li>
<li>Click Close</li>
</ul>
<p>Now you can start using Eagle by simply selecting Applications-&gt;Programming-&gt;Eagle 5.6.0.</p>
<h3>Creating schematics for Arduino projects</h3>
<p>When you start Eagle, first a window titled &#8220;Control Panel&#8221; opens. To draw a new schematic, select File-&gt;New-&gt;Schematic. Another window opens, this is the place to draw your circuit design.</p>
<p>The basic idea is to add components from different component libraries, organize them on the drawing area and make the necessary wiring connections.</p>
<p>You can add new items into your design by clicking the Add button in the toolbar on your left. For Arduino projects, you should be able to use a chip from Atmel category. However, I couldn&#8217;t find Atmega168 that is used in Arduino Diecimila, although Atmega169 was there.</p>
<p>You can get a suitable model from Rob Faludi: <a title="Arduino model for Eagle" href="http://www.faludi.com/2008/10/07/arduino-avr-library-for-eagle-layout-editor/">http://www.faludi.com/2008/10/07/arduino-avr-library-for-eagle-layout-editor/</a>. Download the model with a web browser, and extract it to [Eagle installation directory]\lbr. Then back in Eagle, select Library-&gt;Use, browse for Arduino-AVR.lbr file, and open it. Now you can click Add button from the Eagle toolbar again, new Arduino-AVR section is visible in the component list and Atmega168 variants are there. Select the model you want to use, and click OK. Place the component in the center of the design area, and continue adding more components and wiring them together.</p>
<p>Happy designing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/05/28/using-arduino-in-eagle-schematics-with-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>LG L1730SF touch screen display in Ubuntu Linux 8.04 Hardy Heron, Part 1</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/04/29/lg-l1730sf-touch-screen-display-in-ubuntu-linux-804-hardy-heron/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/04/29/lg-l1730sf-touch-screen-display-in-ubuntu-linux-804-hardy-heron/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 21:23:12 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[Hardy Heron]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[touch screen]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=14</guid>
		<description><![CDATA[A few years ago I bought a 17&#8243; touch screen display device LG L1730SF. The product itself was nice, and very affordable at the time. However, it wasn&#8217;t easy at all to get it working with Ubuntu Linux 6.06 Dapper Drake. I wrote a somewhat detailed instructions about my setup and published them on these [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-19" title="LG L1730SF touch screen in Ubuntu Linux" src="http://www.rantakokko.net/tapani/blog/wp-content/uploads/2009/04/01042007-300x225.jpg" alt="LG L1730SF touch screen in Ubuntu Linux" width="300" height="225" /><em>A few years ago I bought a 17&#8243; touch screen display device LG L1730SF. The product itself was nice, and very affordable at the time. However, it wasn&#8217;t easy at all to get it working with Ubuntu Linux 6.06 Dapper Drake. I wrote a somewhat detailed instructions about my setup and published them on these web pages. To my surprise, the article got many positive comments and questions even several years after. Apparently touch screens in Linux was a hot issue (at least to geeks like me) and there was not enough information available for troubleshooting.</em></p>
<p><em>In August 2008 I went through it all again after updating to Ubuntu Linux 8.04 Hardy Heron. However, this time I was better prepared, having a few years of experience on Ubuntu. This article brings the instructions more up-to-date and answers some questions I didn&#8217;t have a clue about at the first time. Although Hardy is already a year old and major computer manufacturers are publishing computers with built-in multi-touch capabilities almost daily, I still think these instructions should be valid for all DIY guys for a few years, since it is a long term support (LTS) version of Ubuntu.</em></p>
<p><em>Note: I have written this article 8 months later from my memos. It was not straightforward to get the touch feature working, thus some unnecessary adventures had to be made. However, I decided to include them all here so that others can learn from my mistakes. Moreover, with a complex issue like this I think it is better to elaborate too much than too little &#8211; you can easily skip the chapters you don&#8217;t care about. I have also tried to explain what I am trying to do and why at each step, as many Linux/Ubuntu newbies need these things to be explained so that they can learn (I went through that myself a few years ago). As a result, the article is quite long and you don&#8217;t actually need to perform all the steps that I describe. These steps are marked in the text.</em></p>
<h2>Introduction</h2>
<p>In this article I assume that you have already setup Ubuntu Linux 8.04 Hardy Heron to your computer using keyboard, mouse and another display device. I will focus on explaining how to configure the system to operate with LG L1730SF display and its touch feature. Note that a keyboard and a mouse should be connected to the computer when you are going through the setup according to this guide. After you&#8217;re finished you can use the computer without them via the touch feature and virtual keyboard.<span id="more-14"></span></p>
<h2>First boot</h2>
<p>Make sure that the computer is shut down and remove the power cables from both the computer and the display device. LG L1730SF touch screen display has three cables: a power cable, an analog VGA cable for graphics, and a serial/USB cable for the touch feature. Connect the VGA cable to the computer, but do not connect the USB cable yet. Attach the power cables again, and start the computer.</p>
<p>You should see some textual messages on the screen while the computer is loading the Ubuntu Linux operating system. In case the display contains mainly garbage, you need to adjust the screen resolution and refresh rate for the Linux console to values that are suitable for your display. Usually the default settings work fine, but I have found that with LG L1730SF some tuning is needed. If this is the case, read on &#8211; otherwise you can skip the rest of this chapter.</p>
<h3>Adjusting console screen resolution</h3>
<p>Before the computer begins to load Ubuntu Linux operating system, a boot loader is run (usually Grub). In order to change console settings so that they become effective before the operating system is booted, you need to edit the boot loader&#8217;s configuration file, and then reboot the computer. Here&#8217;s how to do it.</p>
<p>First, you need console access to the computer having problems with its display. In case the computer eventually loads normal Linux desktop, you can access console from there. If not, you have a couple of options. For example, in case you have already setup an SSH server, you can SSH it from another computer. If you don&#8217;t have remote access, the easiest way is to simply use another display temporarily, i.e. reboot the computer with the other display connected to it.</p>
<p>When you have gained access to the console, type this to open the Grub configuration file in a text editor:</p>
<blockquote>
<pre>sudo nano /boot/grub/menu.lst</pre>
</blockquote>
<p>Look for a line that begins like this:</p>
<blockquote>
<pre># defoptions=</pre>
</blockquote>
<p>Add the following to the end of the line:</p>
<blockquote>
<pre>vga=791</pre>
</blockquote>
<p>This number is a code given for a specific console screen resolution (1024&#215;768). For other alternatives, see <a title="Linux video modes" href="http://en.wikipedia.org/wiki/VESA_BIOS_Extensions">http://en.wikipedia.org/wiki/VESA_BIOS_Extensions.</a> You may also delete the word <em>splash</em> if you wish to get textual messages during boot procedure instead of a progress bar.</p>
<p>Note: Do not uncomment the line! Whenever a new kernel is released and you update your computer with Update Manager, a script called <em>update-grub</em> will be run. It modifies this file to include a new boot option for the new kernel (and in fact makes that the default in the list, if not prevented by settings). Despite of the comment character, the settings listed here will become effective for the new kernel configuration.</p>
<p>In case you want to apply the settings to only some boot alternatives in the boot menu, you can instead do this:</p>
<p>Look for a line that describes that boot configuration. It might be something like this:</p>
<blockquote>
<pre> kernel /boot/vmlinuz-2.6.24-19-generic root=/dev/sda1 ro quiet splash</pre>
</blockquote>
<p>Add another parameter to set the screen resolution. I have successfully used <em>vga=0&#215;317</em> or <em>vga=791</em> (they are the same thing) with LG L1730SF to setup console to 1024&#215;768 resolution. Here&#8217;s an example of what you need to do. This is what I used to have there:</p>
<blockquote>
<pre>title Ubuntu 8.04.1, kernel 2.6.24-19-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-19-generic root=/dev/sda1 ro quiet splash
initrd /boot/initrd.img-2.6.24-19-generic quiet</pre>
</blockquote>
<p>I changed the line that begins with the word <em>kernel</em> to look like this:</p>
<blockquote>
<pre> kernel /boot/vmlinuz-2.6.24-19-generic root=/dev/sda1 ro quiet splash vga=0x317</pre>
</blockquote>
<p>Note that if you configure this only for a specific item in the boot list, whenever the kernel gets updated you may need to apply the setting again! To avoid that, use the option described above (<em>defoptions</em>).</p>
<p>When you&#8217;re done editing the file, save it by pressing <em>CTRL+O</em>, and exit by pressing <em>CTRL+X</em>. Reboot the computer with LG L1730SF connected to it. The console screens should appear nicely now.</p>
<p><!--more--></p>
<h2>USB connection</h2>
<p>Now we will begin to configure the system for the touch feature. Note that the tricks explained here may be helpful with troubleshooting other hardware problems too. First, we need to find out if and how the computer recognizes the display device via the USB interface.</p>
<p>Begin by logging in to Ubuntu. Then open console, and write this command:</p>
<blockquote>
<pre>lsusb</pre>
</blockquote>
<p>You should see a list of USB devices currently attached to the computer, for example your USB mouse and keyboard should be there.</p>
<p>Connect the USB cable of the touch screen display to the computer, wait 10 seconds, and write the command <em>lsusb</em> again. Now you should see an additional line in the list. In the case of LG L1730SF, it is something that includes text <em>Future Technology Devices International, Ltd</em>. This device is the touch screen part of your display, now connected to your computer via the USB bus.</p>
<p>Try touching the display now. You&#8217;ll probably notice that whenever you tap the screen, the mouse pointer moves &#8211; but not quite as you expect it to: X and Y axles are swapped! For example, if you drag your finger on the screen from left side to right side, the mouse cursor will move from down to up. And if you drag from down to up, cursor will move from left to right.</p>
<p>Nevertheless, now we know that the touch hardware is found by Ubuntu Linux and the touch panel itself works. Of course, the software side still needs some work before the system becomes usable.</p>
<h2><!--more-->Driver name</h2>
<p>In console, type this command to get a list of all input devices in the system:</p>
<blockquote>
<pre> cat /proc/bus/input/devices</pre>
</blockquote>
<p>The list contains various information about each input device. One of them should have this name: <em>ITM Inc USB Touch Panel</em>. When you have found that from the list, check the line below it that begins with <em>Sysfs=</em>&#8230; In the end of that line, you should see something like <em>/input/input14</em> (the number may vary). Write down that number, it tells to which input channel/file the touch screen is currently mapped to.</p>
<p>Now we can find out the name of the driver with these commands:</p>
<blockquote>
<pre>udevinfo -a -p /class/input/input14 | grep DRIVER</pre>
</blockquote>
<p>NOTE: replace the number &#8220;14&#8243; with the number you wrote down in the previous step. You&#8217;ll see a chain of drivers attached to that input device (your touch screen). In the old days, the driver was called <em>itmtouch</em>. Now it is <em>usbtouchscreen</em>, a combined driver that includes support for many brands and models. You should see that driver listed here.</p>
<p>Another method to find out the driver is to look for a kernel module (driver) by its name. Still in console, you could type</p>
<blockquote>
<pre>lsmod | grep touch</pre>
</blockquote>
<p>As a result, you should see something like this:</p>
<blockquote>
<pre>usbtouchscreen        11652 0</pre>
<pre>usbcore            146028 5 usbtouchscreen,usbhid,ehci_hcd,ohci_hcd</pre>
</blockquote>
<p>Basically all computer hardware needs a driver. A driver communicates with the hardware equipment, and provides applications access to the device via the operating system&#8217;s kernel. In Linux, most of the device drivers are implemented as dynamically loadable kernel modules. Above, the command <em>lsmod</em> lists currently loaded modules, and the rest of the line <em>| grep touch</em> filters this list by passing through only lines that contain the word <em>touch</em>. We can filter the list like this because we are looking for touch screen drivers only and guessed that the word <em>touch</em> is likely included in the name of the driver module.</p>
<p>Now we know that the driver associated with the touch screen is called <em>usbtouchscreen</em> and it is currently loaded.</p>
<p><!--more--></p>
<h2>Swapping X and Y</h2>
<p><strong>NOTE: This is a dead end &#8211; read this chapter through without doing anything!</strong></p>
<p>Our first problem is to somehow swap X and Y axels, as they seem to be reversed. First place to look for is the driver, <em>usbtouchscreen</em>. Maybe it can be configured?</p>
<p>Many kernel modules have parameters that can be set when the module is loaded. In order to find out if <em>usbtouchscreen</em> module has some, we can for example check it from the source code! A very helpful site for tasks like this is <a title="The Linux Cross Reference" href="http://lxr.linux.no/">http://lxr.linux.no/</a>, which hosts The Linux Cross Reference. By clicking through to the correct category, you&#8217;ll find the source code for <em>usbtouchscreen</em> module in an easily readable format. Here&#8217;s a direct link for <em>usbtouchscreen.c</em> source code file used in kernel version 2.6.27.4: <a title="usbtouchscreen module source code" href="http://lxr.linux.no/linux+v2.6.27.4/drivers/input/touchscreen/usbtouchscreen.c">http://lxr.linux.no/linux+v2.6.27.4/drivers/input/touchscreen/usbtouchscreen.c</a>.</p>
<p>From the source code file you can find this line (line 60):</p>
<blockquote>
<pre>module_param(swap_xy, bool, 0644);</pre>
</blockquote>
<p>It means that <em>usbtouchscreen</em> module has a parameter called <em>swap_xy</em>, of boolean type (on/off). Clearly it can be used for swapping X and Y axles &#8211; isn&#8217;t this exactly what we need?</p>
<p>We can try to use the parameter. In console, type this to unload the driver module:</p>
<blockquote>
<pre>sudo rmmod usbtouchscreen</pre>
</blockquote>
<p>After executing this command, the driver module gets unloaded and the touch feature does not work anymore. You can check that by tapping the screen (the mouse cursor won&#8217;t move), and also with command <em>lsmod | grep touch</em>, which yields nothing.</p>
<p>In order to reload the module with some new parameters, we first need to know where the module is located in the file system. Begin with this command:</p>
<blockquote>
<pre>sudo updatedb</pre>
</blockquote>
<p>It updates the database that is used in searching for files. After it has finished, look for the driver from the file system:</p>
<blockquote>
<pre>locate usbtouchscreen</pre>
</blockquote>
<p>In response, you should get something like this:</p>
<blockquote>
<pre>/lib/modules/2.6.24-19-generic/kernel/drivers/input/touchscreen/usbtouchscreen.ko</pre>
</blockquote>
<p>This is the location of the driver module. Now that we know where it is, we can reload it with <em>swap_xy</em> parameter by typing this command (modify the path to reflect yours):</p>
<blockquote>
<pre>sudo insmod /lib/modules/2.6.24-19-generic/kernel/drivers/input/touchscreen/usbtouchscreen.ko swap_xy=1</pre>
</blockquote>
<p>Now, when you tap the screen, you should notice a couple of things. First, the mouse cursor moves again. Second, it moves differently than it used to: when you drag your finger from left side to right side, the cursor moves along the horizontal direction, not vertical as it used to. The swap parameter worked!</p>
<p>Unfortunately, it doesn&#8217;t seem to help enough. Now we&#8217;ll notice that the axles are <em>mirrored</em>, i.e. when you tap the left side of the display, the cursor appears to the right side, and when you tap up, cursor goes down. Moreover, if you try to tap in the center of the screen, you&#8217;ll notice that there&#8217;s quite a lot of offset in the cursor&#8217;s location. As this does not seem to work well enough, you can now simply reboot the computer to get rid of the <em>swap_xy</em> parameter.</p>
<h3>What next?</h3>
<p>Since the <em>usbtouchscreen</em> module does not have enough parameters to allow proper configuration, we need something more. Basically there are two options:</p>
<p>Option 1: we could modify the driver to accept more parameters, i.e. not only swapping the axles but also mirroring them, as well as support for some kind of basic calibration. This alternative involves programming. Moreover, it does not seem to be a very good solution to begin configuring a driver like this. For example, consider what happens if you have multiple touch screen devices connected to the same computer &#8211; you should be able to calibrate them separately, but this is not possible with kernel module parameters if the displays happen to use the same driver package (note that <em>usbtouchscreen</em> module contains support for multiple models and brands). The benefits of this option are that the system would be simple (just one driver module) and the configuration would be rather easy to do (i.e. find working parameters with some simple calibration tool or trial and error, then put the parameters to a configuration file that is used for setting parameters to kernel module that will be automatically loaded).</p>
<p>Option 2: use some middleware component in between the driver and X windowing system. I.e. do not map the output of the touch screen driver directly to mouse movements, but use another layer in between, which can be configured properly and easily. Since we are in the open source world, of course that has been already done: <em>Evtouch</em>, the Linux touchscreen driver for X, does exactly that. Here&#8217;s a link to its homepage: <a title="Evtouch home page" href="http://www.conan.de/touchscreen/evtouch.html">http://www.conan.de/touchscreen/evtouch.html</a></p>
<h2><!--more-->Evtouch &#8211; touchscreen driver for X</h2>
<h3>Installation</h3>
<p>Unlike the driver <em>usbtouchscreen</em>, Evtouch is not automatically installed when you first plug in the USB cable of the touch screen. That must be done before we can continue. The easiest way to install it would be from Ubuntu&#8217;s software repositories, in case it is there. We can check that easily by going to <a title="Ubuntu software packages" href="http://packages.ubuntu.com">http://packages.ubuntu.com</a>, and entering <em>evtouch</em> to the search field. Remember to change &#8220;Distribution&#8221; to &#8220;Hardy&#8221; before you click the search button, as we want to search for a package intended to Ubuntu 8.04 Hardy Heron. The result of the search:</p>
<blockquote><p>hardy (x11): Touchscreen-Driver for X.Org/XFree86 server [universe] 0.8.7-3ubuntu1: amd64 i386</p></blockquote>
<p>This means that version 0.8.7 exists in the <em>universe</em> repository for i386 and amd64 systems. From the search results you can also see that it is called there <em>xserver-xorg-input-evtouch</em>. But is this the newest version? We can check that from <em>evtouch</em> home page: <a title="Evtouch home page" href="http://www.conan.de/touchscreen/evtouch.html">http://www.conan.de/touchscreen/evtouch.html</a>.  (At the time I did my setup, it was the newest version.)</p>
<p>Not all Ubuntu&#8217;s software repositories are enabled by default. You must enable <em>universe</em> repository, if you haven&#8217;t already done that. In console, type</p>
<blockquote>
<pre>sudo nano /etc/apt/sources.list</pre>
</blockquote>
<p>Then uncomment all lines that end with the word &#8220;universe&#8221;. Save (CTRL+O) and exit (CTRL+X).</p>
<p>To sync your local cache with the repositories, type</p>
<blockquote>
<pre>sudo apt-get update</pre>
</blockquote>
<p>Now you should be able to install software from <em>universe</em> repository.</p>
<p>To finally install <em>evtouch</em>, give this command in the console:</p>
<blockquote>
<pre>sudo apt-get install xserver-xorg-input-evtouch</pre>
</blockquote>
<p>If everything goes fine, <em>evtouch</em> is now installed.</p>
<h3>Configuring X</h3>
<p>Next we need to configure X to use <em>evtouch</em> for the touch feature, instead of the default mouse driver. This requires editing X windowing system&#8217;s configuration file. As it is possible to make mistakes that prevent X from working, before continuing make a backup copy of the current X configuration file:</p>
<blockquote>
<pre>sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak</pre>
</blockquote>
<p>Basic instructions on how to configure X to use <em>evtouch</em> can be found from <em>evtouch</em> module&#8217;s home page (recall <a title="Evtouch home page" href="http://www.conan.de/touchscreen/evtouch.html">http://www.conan.de/touchscreen/evtouch.html</a>). To begin editing X configuration file, in console type</p>
<blockquote>
<pre>sudo nano /etc/X11/xorg.conf</pre>
</blockquote>
<p>Search the file for <em>Section &#8220;InputDevice&#8221;</em>, which contains a line <em>Identifier &#8220;Configured Mouse&#8221;</em>. After this section, add these new lines:</p>
<blockquote>
<pre>Section "InputDevice"
   Identifier "touchscreen"
   Driver "evtouch"
   Option "Device" "/dev/input/event1"
   Option "DeviceName" "touchscreen"
   Option "MinX" "98"
   Option "MinY" "43"
   Option "MaxX" "940"
   Option "MaxY" "925"
   Option "ReportingMode" "Raw"
   Option "Emulate3Buttons"
   Option "Emulate3Timeout" "50"
   Option "SendCoreEvents" "On"
EndSection</pre>
</blockquote>
<p>Then, look for <em>Section &#8220;ServerLayout&#8221;</em>. Add this line inside that section:</p>
<blockquote>
<pre>InputDevice "touchscreen" "CorePointer"</pre>
</blockquote>
<p>Then save (CTRL+O) and exit (CTRL+X).</p>
<p>Now we have added a new input device, which controls the mouse pointer in X. The device is called <em>touchscreen</em> and it uses <em>evtouch</em> driver. In addition, multiple options are used to configure it.</p>
<p>In order to test the new settings, you need to restart X. The easiest way to do that is to first save all open files and then press these buttons together: <em>CTRL+ALT+BACKSPACE</em>. X will restart, and then you can log in again. After logging in, you&#8217;ll probably notice two things: you&#8217;re mouse doesn&#8217;t work  anymore, and when you tap the touch screen, the pointer seems to disappear and the Trash folder opens! If you look carefully, you might see part of the pointer on top of the trash can icon in the lower right corner of the screen &#8211; that explains why the Trash folder opens after tapping the screen! If you move your finger near the lower right corner of the screen, you should see the mouse cursor moving on the desktop. However, X and Y axles are swapped. In addition, when you begin moving your finger on the screen,  the cursor first doesn&#8217;t move at all, and then jumps several hundred pixels forward.</p>
<p>Clearly we need to adjust the settings from the given defaults. Now that the pointer is out of control with touch (and mouse doesn&#8217;t work either), the easiest way to do the editing is with one of the text based consoles. Press together <em>CTRL+ALT+F2</em> to open one of them, then log in and begin editing X configuration file by typing</p>
<blockquote>
<pre>sudo nano /etc/X11/xorg.conf</pre>
</blockquote>
<p>Go to the touch screen section you added earlier, and add a new option after other touch options:</p>
<blockquote>
<pre>Option "Rotate" "ccw"</pre>
</blockquote>
<p>This will swap X and Y axels by making <em>evtouch</em> think that the display is pivoted 90 degrees counter-clockwise. Write changes with CTRL+O, but do <em>not</em> exit from the editor. Instead, press <em>CTRL+ALT+F7</em> to return to X, and then press <em>CTRL+ALT+BACKSPACE</em> to restart it. When the login screen appears, you do not necessarily need to log in &#8211; you can test the touch feature right away by tapping the login screen. When you tap near the lower right corner, you can see that X and Y axles are now correct, but Y axle is mirrored.</p>
<p>Go back to xorg.conf file by pressing <em>CTRL+ALT+F2</em>. In case you use value <em>cw</em> instead of <em>ccw</em>, <em>evtouch</em> assumes that the screen is pivoted 90 degrees clockwise, and then X axle will be mirrored&#8230; We need to use another option to purposely mirror one of the axles. You can leave rotation to <em>ccw</em> and try to fix the Y axle by adding another option in the end of our options list:</p>
<blockquote>
<pre>Option "SwapY" "On"</pre>
</blockquote>
<p>However, now you&#8217;ll see that in fact it swapped the X axle! This is due to the order in which <em>Rotate</em> and <em>SwapY</em> commands are applied. To make it really work, you can use for example <em>cw</em> in <em>Rotate</em> option and <em>SwapY</em>, but <em>ccw</em> in <em>Rotate</em> and <em>SwapX</em> should be fine too.</p>
<h3>Calibrating touch</h3>
<p>Now we&#8217;ve got X and Y configured as they should be, but the calibration is still way off target. You probably already noticed the calibration settings within the list of options we added to the X configuration file. In order to have some idea what the values to be used for calibration might be, we can go back to look at the source code of <em>usbtouchscreen.c</em> driver (<a title="usbtouchscreen module source code" href="http://lxr.linux.no/linux+v2.6.27.4/drivers/input/touchscreen/usbtouchscreen.c">http://lxr.linux.no/linux+v2.6.27.4/drivers/input/touchscreen/usbtouchscreen.c</a>). Search for text <em>[DEVTYPE_ITM]</em>, and you&#8217;ll find that for X axel the minimum configuration values are set to 0 and the maximum values to 0xFFF. The latter means that 12 bits are used per axel, which yields 4096 different values. However, as 0 is also included to the range, you can actually set the calibration value somewhere between 0 and 4095. Compared to this, the setting values  found from <em>evtouch</em> modules home page seem rather small.</p>
<p>Try to set the calibration values in xorg.conf as follows: use 0 for MinX and MinY, and 4095 for MaxX and MaxY. These are the bounds for the calibration values. With these values, you should see that the touch feature becomes almost usable! The pointer appears pretty close to the spot you tap everywhere on the screen. However, calibration is not yet precise, and there seems to be one major hurdle left: when you drag your finger on the screen, the cursor first doesn&#8217;t move, and then jumps forward. This problem has not disappeared, although the jumps are now much shorter as in our previous attempts. It seems like there&#8217;s some kind of a <em>grid</em>, and the cursor gets attached to the nearest invisible grid line.</p>
<p>In case you are planning to build somekind of a simple user interface with only a few buttons, you could basically work around the problem by hiding the mouse cursor and using some very big buttons. However, I want to be able to control the cursor precisely, so that it can be used for example for drawing. Before going through more precise calibration, this &#8220;jumpiness&#8221; issue needs to be resolved.</p>
<p>Read the 2nd part to solve the jumpiness issue from <a title="Part 2" href="http://www.rantakokko.net/tapani/blog/2009/08/10/lg-l1730sf-touch-screen-display-in-ubuntu-linux-8-04-hardy-heron-part-2/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/04/29/lg-l1730sf-touch-screen-display-in-ubuntu-linux-804-hardy-heron/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
