<?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/Linux</title>
	<atom:link href="http://www.rantakokko.net/tapani/blog/category/ubuntu-linux/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>How to create a free audio link over the Internet using an old PC, Ubuntu Linux and Icecast streaming software</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/06/08/how-to-create-a-free-audio-link-over-the-internet-using-an-old-pc-ubuntu-linux-and-icecast-streaming-software/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/06/08/how-to-create-a-free-audio-link-over-the-internet-using-an-old-pc-ubuntu-linux-and-icecast-streaming-software/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 18:23:01 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[audio link]]></category>
		<category><![CDATA[Icecast]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[old PC]]></category>
		<category><![CDATA[streaming]]></category>
		<category><![CDATA[Ubuntu 8.04 Hardy Heron]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=133</guid>
		<description><![CDATA[The purpose of this article is to help you in creating a reliable and free one-way audio link over the Internet. The primary use case is to enable low-cost transmission of radio program from radio station premises to a remote broadcasting tower. The method explained here is suitable for other one-way transmission needs as well, [...]]]></description>
			<content:encoded><![CDATA[<address>The purpose of this article is to help you in creating a reliable and free one-way audio link over the Internet. The primary use case is to enable low-cost transmission of radio program from radio station premises to a remote broadcasting tower. The method explained here is suitable for other one-way transmission needs as well, but due to long latency it cannot be used for two-way conversations (use e.g. Skype instead). Streaming live audio signal from one computer to another can be accomplished even with old low-cost computer hardware and free open source software, which makes the setup very affordable and enables interesting use cases.</address>
<h2>Abstract</h2>
<p>There are many different needs for sending an audible signal from one location to another. The technology that works in one use case may not work well in another. We can divide the applications into two main categories:</p>
<p>The applications in the first category are aimed for enabling <em>conversations</em> over long distances. Telephone calls and teleconferences are perfect examples. Within this category the sound quality is not the top priority, but low latency can be considered a must. Both closed and open source software solutions exist, the most well-known being Skype.</p>
<p>The applications in the second category are aimed for <em>broadcasting</em> an audio signal from a single source to a larger audience, which in general does not need to be able to communicate back to the source (i.e. the audience listens only). Within this category the sound quality is an important enabler for long listening periods, whereas long latency can be usually tolerated well. Both closed and open source software solutions exist, for example Shoutcast and Icecast.</p>
<p>The setup described in this article is intended to be a one-way pipe for high quality live audio signal. Therefore, these instructions are likely useful in use cases that fall to the second category.</p>
<p><span id="more-133"></span></p>
<h2>Introduction</h2>
<p>In this article, audio streaming over the Internet network is applied to a radio station that needs to send its program to a remote transmitter tower. This new setup will replace current expensive ISDN connection with a lower cost version as follows: An old PC will be located in the radio tower&#8217;s cabin and used as a server computer that receives live audio stream over an Internet connection, and plays it back. The audio signal from the server PC&#8217;s sound card is routed to a radio transmitter device and further to an antenna. The program source comes from a client computer that sends the audio signal to the server over the Internet. It can be for example a laptop equipped with a microphone and a CD/MP3 player software.</p>
<p>As Internet radio is nowadays a rather well established concept, it is not a surprise that mature software solutions exist for setting up own Internet radio station. One of them is Icecast, an open source server software for streaming multimedia. In this article, Icecast is used in the server computer as a connection point where audio content can be streamed to from other locations. However, instead of sharing the audio stream to hundreds of listeners via the Internet &#8211; as is usually done with Icecast &#8211; here it is played back immediately on the server computer&#8217;s own sound card and further routed as an analog audio signal. In order to play the audio with the server computer, also an Icecast compatible client software needs to be running on the server, here Ogg123 is used as a player. This way, whatever audio content is streamed to the server, it can be immediately and automatically played back to the audience. Ices2 and Edcast are examples of applications that can be used as a the streaming source, running on the client computer. Both support Ogg Vorbis and MP3 encoding, among others. There are in fact quite many packing algorithms. Ogg Vorbis is used in this article because it is both free and provides very good audio quality.</p>
<p>This kind of setup makes transmitting radio program from various local events simple: one can setup the equipment at the radio tower so that the devices can be turned on remotely e.g. with an SMS from a mobile phone, then open a connection to the server computer from a laptop over the Internet, and begin broadcasting real radio program to the listeners from wherever one happens to be.</p>
<h2>What is needed</h2>
<p>The main building blocks of the system are these:</p>
<ol>
<li>An old PC that can be dedicated to act as an audio link server computer in the receiving end</li>
<li>Ubuntu Linux 8.04 Server as an operating system for the server computer</li>
<li>Icecast 2 as a streaming software backend for the server computer</li>
<li>Ogg123 as an audio stream player for the server computer</li>
<li>Ogg Vorbis audio encoder and decoder for audio data packing (client side) and unpacking (server side)</li>
<li>A Linux or a Windows computer to act as the client computer in the sending end</li>
<li>Ices2 (Linux) or Edcast (Windows) as audio streaming application for the client computer</li>
</ol>
<p>Naturally also broadband network connection is needed for both the server and the client computer. Various audio equipment, such as microphones, mixers, CD players, headphones and monitors might be necessary, depending on your use case.</p>
<h2>The Setup</h2>
<h3>1. Selecting the server computer</h3>
<p>One should begin with selecting and acquiring a PC that will be used as the backend server for the Internet audio link. This computer does not need to be a new, fancy dream machine with all the latest and greatest &#8211; on the contrary; it should be a simple, decent and reliable work horse that can be dedicated to this one task. What we are looking for is a typical home or office PC made somewhere 1997 or later. You can probably find one for free either from your own garage, or by asking your friends and relatives. I got a suitable computer from my sister&#8217;s husband, who was going to throw it away. As an example of adequate machine, see the specifications of that computer below.</p>
<ul>
<li> Intel Pentium MMX 166 MHz processor</li>
<li>64 MB memory</li>
<li>2 GB hard drive</li>
<li>ATI Rage II+ display adapter</li>
<li>Creative SB Live sound card</li>
<li>CD-ROM drive</li>
</ul>
<h3>2. Preparing the server computer hardware</h3>
<p>The first task is to check that the computer is adequate for the purpose we are going to use it. The requirements are somewhat dependent on the chosen Linux version. Since we are using Ubuntu 8.04 Server in this article, I think the computer should have at least 120 MHz Pentium processor (tested to work), 64 megabytes of RAM (tested to work) and a gigabyte or more of hard drive space (Ubuntu installation alone will require ~400 megabytes). It <em>must</em> have a sound card and a network card. Note that keyboard, display and CD-ROM drive are useful only during the initial setup phase, as the computer can be managed remotely over the network connection later on. Mouse is not needed at all, nor is the horse power for running a graphical desktop environment.</p>
<p>If the computer is to be placed into a remote location where it cannot be easily accessed after the initial setup is done, I think it is reasonable to clean it now while it is available. I also recommend taking notes and photographs of the components, especially how they are connected, as this information may turn invaluable later on when you are doing some remote management over an Internet connection. For example, the preparation tasks might include these:</p>
<ul>
<li>Turn power off from the rear power source switch, remove all external cords from the computer and open the computer case.</li>
<li>Remove dust e.g. with a vacuum cleaner (be careful), then make sure that all parts and cables are firmly attached inside and that there are no loose parts.</li>
<li>Organize cables etc. so that the air can flow through the case with ease and check that all fans work properly by temporarily attaching power cord and turning the computer on for a short period (then turn it off and remove the power cord again).</li>
<li>Take a few photographs of the interior (in case you need to check something later or give guidance to someone else from a remote location) &#8211; try to get pictures where one can see some details of the components and how they are attached, for example to which IDE ports hard drive and CD-ROM drives are connected to and whether there is room for upgrades (empty slots on motherboard and case).</li>
<li>Make a list of all parts and their models (motherboard, processor, memory&#8230;), that will help during installation and later if you need to solve problems.</li>
<li>Put all the pieces back together, then plug in the keyboard, display and power cords for setup phase.</li>
</ul>
<p>As an example, this is my list of the components:</p>
<ul>
<li>Motherboard: Titanium P51430TX/IIB, Intel + Winbond chipset, 4xPCI, 4xISA, 4xSIMM, 2xDIMM</li>
<li>Processor: Intel Pentium MMX 166 MHz Socket 7</li>
<li>Memory: 4x 16MB (long) SIMM</li>
<li>VGA: ATI Rage II+, chipset 3D Rage II+ DVD</li>
<li>Sound: Creative SB Live, model CT-4750</li>
<li>Hard drive: Seagate Medalist ST32122A, 4092 cyl, 2111 MB, 16 heads, 63 sectors (IDE1 master)</li>
<li>Floppy: 3.5&#8243; Teac FDD, model FD-235HF</li>
<li>CD-drive: Toshiba 24x CD-ROM, model XM-6102B (IDE2 master)</li>
<li>Case: Wings (ATX)</li>
<li>PSU: Seventeam ST-200HRK (ATX)</li>
</ul>
<p><em>Note: In case you want to start the computer remotely e.g. via SMS, you&#8217;ll need a device that can receive SMS messages and turn power on/off in its outputs (where you should connect your computer&#8217;s power cord). In addition, you probably need to modify the computer a little. Some PCs can be made to start automatically when they begin to receive power simply by configuring this behavior in the BIOS. Others need a small hardware modification. Old computers based on AT design have on/off type power switch, which you can simply leave &#8220;on&#8221; &#8211; it&#8217;s as simple as that. However, modern ATX form factor computers use a momentary power switch, which cannot be used like that. This can be solved by connecting two certain wires together in the big cord that comes from the PSU and is connected to the motherboard (google for instructions on which pins to connect). I had to go with the last option. For convenience, I even added a switch into the back of the computer so that I can enable/disable auto start feature with ease.</em></p>
<h3>3. Configuring the BIOS</h3>
<p>It is quite likely that there isn&#8217;t that much to tune in the BIOS. However, it may be a good idea to load &#8220;optimized default&#8221; settings just for sure, especially if you got the computer from someone else. Then check that all settings seems to be ok and the computer is working fine.</p>
<p>One thing to note is that since the computer may not have a keyboard attached to it in the remote location, you should check that it is not required during boot procedure. Typically there is a setting called &#8220;Halt on&#8221;, and a proper setting value might be for example &#8220;All but keyboard&#8221;.</p>
<p>Also, you might want to try to optimize the boot time to be as short as possible by removing some checks from the boot operation sequence. However, in general you should not try to tweak the computer to run as fast as possible e.g. via overclocking the processor or tweaking memory timings. There&#8217;s no use for this kind of tricks in our application, but they can make the computer hardware unreliable, which we definitely want to avoid.</p>
<p>To prepare for the next phase, you should check the BIOS settings for the boot media. Make sure that the computer can be booted from a CD. After installing the operating system, change the boot sequence so that it only starts from hard drive (C-drive). This will take a few seconds off from boot time.</p>
<h3>4. Installing the operating system</h3>
<p>If you don&#8217;t already have Ubuntu 8.04 Server CD, create it now (see instructions from Ubuntu website if you don&#8217;t know how to make it). When you&#8217;re done, put the CD into the server computer&#8217;s CD drive and turn the computer on. After a while, Ubuntu start menu should appear on your display.</p>
<ul>
<li>Select your language (I prefer English although it is not my native language).</li>
<li>If you&#8217;ve just burned the CD, you should test it in order to avoid problems later. Select &#8220;Check CD for defects&#8221;. When you&#8217;re done, reboot from the CD.</li>
<li>If you&#8217;re not sure that the computer hardware is OK, you should at least run the memory test. Select &#8220;Test memory&#8221;. When you&#8217;re done, reboot from CD.</li>
<li>To begin installation, select &#8220;Install Ubuntu Server&#8221;.</li>
<li>Choose your language (e.g. English)</li>
<li>Choose country/territory/area (e.g. Finland)</li>
<li>Choose keyboard layout (e.g. Finland). Wait a moment.</li>
<li>Next the installer will try to detect your network card and configure it. This may either work or fail, but it doesn&#8217;t really matter at this point &#8211; you&#8217;ll probably need to configure it manually later anyway, as the server needs a static IP address and the installer waits for dynamic IP address to be assigned by a DHCP server in your network. In case the network detection fails, you are given a possibility to configure it manually. At this point, I chose not to (&#8220;Do not configure the network at this time).</li>
<li>However, you should still give a hostname (the name of the computer), which is asked next. I wrote &#8220;RadioServer1&#8243;. Wait a moment.</li>
<li>The hard drive needs to be partitioned next. I chose &#8220;Guided &#8211; use entire disk&#8221;. The wizard suggested to divide my 2 GB hard drive to one big 1.9 GB partition with ext3 filesystem, and another small 150 MB swap partition. This is fine, so I accepted it by choosing &#8220;Finish partitioning and write changes to disk&#8221;.</li>
<li>Next, a summary of changes was shown together with a confirmation request. Ok&#8217;ed that.</li>
<li>Wait a while &#8211; this time somewhat longer, up to several hours if your computer is low on memory.</li>
<li>Write user name (full name and account name). Write password (use a good one!).</li>
<li>Choose services to install. From the options presented in the list, you only need OpenSSH server for remote management. If you plan to use a web browser for controlling the server, I recommend not to install the full LAMP setup for this purpose; you can install a much more lightweight solution in a later phase. This is important especially if you are low on resources (old computer).</li>
<li>Wait. When the installation is complete, the computer will eject the Ubuntu CD and ask your permission to reboot. Do it.</li>
</ul>
<h3>5. Booting the first time</h3>
<p>After installing the operating system and booting the computer the first time, you should read the text that is printed to screen. Watch out for errors. For example, my computer printed this line:</p>
<blockquote>
<pre>ACPI: Bios age (1997) fails cutoff (2000), acpi=force is required to enable ACPI</pre>
</blockquote>
<p>It is not critical to have ACPI, and my computer does not support it. I got rid of the note as follows:</p>
<ul>
<li>When boot procedure is finished, login prompt is shown. Log in with your user account name and password that were created during operating system installation.</li>
<li>Type <em>sudo nano /boot/grub/menu.lst</em> to begin editing boot options.</li>
<li>Look for a commented line <em>#defoptions=quiet splash </em>and append to the end of the same line <em>acpi=off apm=on</em>. New kernels that will be installed along with future updates will get these boot options. Note: do not uncomment the line; these are used by debian update-grub script.</li>
<li>Then look for the first line that begins <em>kernel    /boot/vmlinuz &#8230;</em> and append to the end of the same line <em>acpi=off apm=on</em></li>
<li>You might want to consider removing <em>quiet splash</em> options from both places mentioned above. This way you get more information on screen while booting, which is usually a good thing for a server computer.</li>
<li>Save <em>CTRL + O</em> and exit <em>CTRL+X</em>.</li>
<li>Reboot the computer by writing to console <em>sudo reboot</em></li>
</ul>
<p>After successfully logging in, I checked a few basic things:</p>
<ul>
<li>Write <em>dmesg | more</em> to read system messages and look for errors. I did not have anything alerting, just some minor nags.</li>
<li>Write <em>df -h</em> to see how much free space is left on the hard drive after installing Ubuntu Linux. In my computer it took about 400 MB and thus left me with 1.4 GB of free space. That is more than enough for software required for an audio link setup.</li>
</ul>
<h3>6. Setting up networking</h3>
<p>One of the first things after Ubuntu installation is setting up networking. I assume you have some kind of router box that has a DHCP service for providing automatic IP address and configuration for clients. I performed the following steps:</p>
<ul>
<li>Write <em>lspci</em> to console in order to list all found PCI devices. I could see that my network card, which is equipped with Realtek RTL-8139 chipset, was included in the list, so the computer found it. I also remember that when I printed system messages with <em>dmesg | more</em> in previous step I could see that network card driver was successfully loaded.</li>
<li>Write <em>sudo nano /etc/network/interfaces </em>to edit network devices. Probably only the loopback devices is listed, so you should add eth0 first as follows:</li>
</ul>
<blockquote>
<pre>auto eth0
iface eth0 inet dhcp</pre>
</blockquote>
<ul>
<li>Write it out <em>CTRL+O</em> and exit <em>CTRL+X</em>.</li>
<li>Connect network cable, if not already connected.</li>
<li>Write <em>sudo ifup eth0</em>. You should see that system is starting networking with eth0 interface and trying get IP address, gateway and DNS server addresses from DHCP.</li>
<li>You can check out the success. Write <em>ifconfig</em> to see details about network interfaces. You should see <em>eth0</em> with proper IP address and some RX and TX packets already sent/received. Next, write <em>cat /etc/resolv.conf</em>, you should see a printout of (likely two) domain name server IPs. Finally, write <em>route</em> to see that default gateway has been setup properly.</li>
<li>You should test the network connection. For example, write <em>ping www.google.com</em> to see that a) your computer can resolve domain name www.google.com to an IP address, and b) your computer has access to Internet and it can send and receive data. If you have troubles, try writing <em>sudo ifdown eth0</em> and then <em>sudo ifup eth0</em> or reboot the computer. If this does not help, google for help on setting up network in Ubuntu Linux.</li>
<li>At this point I got a minor problem. The computer updated its clock from the Internet time servers, and whenever I tried to use <em>sudo</em> for managing the computer, it replied <em>sudo: timestamp too far in the future: [...time...]</em>. I got rid of this problem simply by writing <em>sudo -K</em></li>
<li>When you get the network working, remember that it needs to be configured for server use. Write again <em>sudo nano /etc/network/interfaces</em>. Comment the line <em>iface eth0 inet dhcp</em> by adding # character, i.e. the line becomes <em>#iface eth0 inet dhcp</em> and then add manual IP configuration with following new lines:</li>
</ul>
<blockquote>
<pre>iface eth0 inet static
address 192.168.1.11
netmask 255.255.255.0
gateway 192.168.1.1</pre>
</blockquote>
<ul>
<li> Of course, the addresses need to be adapted according to your own network.</li>
<li>Write out <em>CTRL+O</em> and exit <em>CTRL+X</em>.</li>
<li>To really apply the new settings, write <em>sudo ifdown eth0</em>, then <em>sudo ifup eth0</em>, and check that IP address has changed with <em>ifconfig</em>.</li>
<li> You can use another computer in the same network to check that your server can be accessed. Use for example <em>ping 192.168.1.11</em> (or whatever is your server&#8217;s IP address that you just set) to see that it replies to requests properly.</li>
<li><strong>When you move the computer to the actual remote location, you need to setup networking again!</strong> Change it back to DHCP first to get DNS server IPs and to check that networking in general in that location is ok. Then switch back to the manual configuration, and setup a proper IP address and gateway.</li>
<li>You probably also need to edit your network router box&#8217;s settings, for example open the necessary ports and route request from the Internet to the server computer&#8217;s IP address.</li>
<li>Note: another alternative to manual configuration is to continue using automatic configuration, and apply the permanent IP address by editing the router&#8217;s settings (IP &#8211; MAC address binding in the DHCP table). Depending on the network setup in the remote usage location, it might be even possible to configure the router box in advance and then simply move both the server and the router box to the remote location, without any on-site configuration.</li>
</ul>
<h3>7. Updating your Ubuntu Linux installation</h3>
<p>Now that you have a working network connection, it&#8217;s time to update the operating system. Don&#8217;t leave this to a later phase, do it now!</p>
<ul>
<li> Write <em>sudo apt-get update</em> to update package source list first.</li>
<li> Write <em>sudo apt-get upgrade</em> to upgrade your installation to newest available software packages (this can take a while and even require a reboot).</li>
</ul>
<p>By the way, the reason for selecting Ubuntu 8.04 Server for this project is that it was a) latest release when writing this guide, b) popular Linux distribution, c) already familiar to me, and d) provides updates for 5 YEARS, starting from April 2008 &#8211; which is nice for a remote server computer that you do not wish to install again soon.</p>
<h3>8. Setting up remote management</h3>
<p>Since you now have a server computer in your network, set up with SSH server software, it is possible to now continue either locally (as done so far) or remotely. At least<br />
you should try that the remote management works. Check it like this:</p>
<ul>
<li>Write <em>ps aux | grep ssh</em> to see list of processes with <em>ssh</em> in the name. You should see a line that says something like <em>/usr/sbin/sshd</em> on the right. It means that SSH server (daemon) is started.</li>
<li>Go to another computer in the same network and write <em>ssh [your server's IP address] -l [your user account name]</em>, e.g. <em>ssh 192.168.1.11 -l trk</em>. After accepting RSA key you should be logged in to the server. If you open the SSH port and forward the request properly in your network router, your server computer can be now safely and securely managed by you from wherever you can connect to the Internet!</li>
<li>Note: if you only have Windows boxes, you can&#8217;t just type <em>ssh &#8230;</em> to the DOS box. Instead, you need an application for SSH. I recommend the free Putty.</li>
</ul>
<h3>9. Adding user accounts</h3>
<p>You might wish to create more user accounts to the server, for example for remote management by multiple persons. This is easy in Ubuntu Linux:</p>
<ul>
<li>Write <em>sudo useradd -d /home/newuser -m newuser</em>, but replace <em>newuser</em> with proper user account name you wish to create.</li>
<li> Write <em>sudo passwd newuser</em> (again, replace <em>newuser</em>) to set a password.</li>
<li> If you trust admin (sudo) rights to the new user, write <em>sudo adduser newuser admin</em> (once again, replace <em>newuser</em>).</li>
<li>You probably want that the shell works similar to the root account (bash). Write <em>sudo nano /etc/passwd</em>, then look for the name of the account you created (probably in the end of the file), and change the end of that line from <em>/bin/sh</em> to <em>/bin/bash</em> and then log in again with that account.</li>
</ul>
<h3>10. Setting up Icecast 2 server software</h3>
<p>Installing Icecast is simple: write <em>sudo apt-get install icecast2</em></p>
<p>After installation is finished, it needs to be configured. Write <em>cat /etc/default/icecast2</em>. This will print the defaults for Icecast, including path to server configuration file, and user id and group that are used for running the Icecast server. By default Icecast is disabled. Before enabling it, we must configure it correctly.</p>
<p>Write <em>sudo nano /etc/icecast2/icecast.xml</em> to begin editing configuration file. Then edit the settings as follows (only changes to be made are listed, section is named in parentheses to help locating the correct setting from the file):</p>
<blockquote><p>(limits)</p>
<pre>clients = 20</pre>
</blockquote>
<blockquote><p>(authentication)</p>
<pre>source-password = [your chosen password]</pre>
<pre>relay-password = [your chosen password]</pre>
<pre>admin-user = [your chosen admin username]</pre>
<pre>admin-password = [your chosen password]</pre>
</blockquote>
<blockquote>
<pre>hostname = RadioServer</pre>
</blockquote>
<blockquote>
<pre>&lt;!-- My radio channel configuration --&gt;
&lt;mount&gt;
&lt;mount-name&gt;/radioprogram.ogg&lt;/mount-name&gt;
&lt;public&gt;0&lt;/public&gt;
&lt;on-connect&gt;/home/radio/radioprogram-start.sh&lt;/on-connect&gt;
&lt;on-disconnect&gt;/home/radio/radioprogram-end.sh&lt;/on-disconnect&gt;
&lt;/mount&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;fileserver&gt;0&lt;/fileserver&gt;</pre>
</blockquote>
<blockquote><p>(logging)</p>
<pre>&lt;loglevel&gt;2&lt;/loglevel&gt; &lt;!-- 4 Debug, 3 Info, 2 Warn, 1 Error --&gt;</pre>
</blockquote>
<blockquote><p>(security)</p>
<pre>&lt;changeowner&gt;</pre>
<pre>&lt;user&gt;icecast2&gt;/user&gt;</pre>
<pre>&lt;group&gt;icecast&lt;/group&gt;</pre>
<pre>&lt;/changeowner&gt;</pre>
</blockquote>
<p>Write out <em>CTRL+O</em>, and exit <em>CTRL+X</em>.</p>
<p>Now that we have configured Icecast, we can enable it. Write <em>sudo nano /etc/default/icecast2</em>. Change the line <em>ENABLE=false</em> to <em>ENABLE=true</em>. Write out <em>CTRL+O</em>, and exit <em>CTRL+X</em>.</p>
<p>Now you can try to start Icecast server. Command <em>/etc/init.d/icecast2</em> will print usage guide. Now go ahead and start it as follows: <em>sudo /etc/init.d/icecast2 start</em>. Note that you can also start it manually and specify the configuration file as follows: <em>sudo icecast2 -c /etc/icecast2/icecast.xml</em>. Warning: for simplicity, these commands use <em>sudo</em> in this testing phase. However, in the long term you should not use <em>sudo</em> to run the server, but a separate user and group with properly set access rights.</p>
<p>If you don&#8217;t use <em>sudo</em> here you might get an error message saying <em>I/O warning : failed to load external entity</em> <em>/etc/icecast2/icecast.xml</em>, which means that your user account does not have rights to access the configuration file. Simply write <em>sudo adduser newuser icecast</em> (replace <em>newuser</em> with your username), log out, log in, and try again.</p>
<p>In a similar manner, if you get an error message nagging about log files (<em>Permission denied</em>), write <em>sudo chmod 775 /var/log/icecast2/</em> to give your user account right to write to the log file directory. You may need to delete existing log files, if there is any! Then try again.</p>
<p>An error message saying <em>Unable to set gid to [number] (Operation not permitted)</em> means that in <em>/etc/default/icecast2 </em>file, user id and group id are set and we need admin rights to enable the group id for the process to be started, thus <em>sudo</em> needs to be used to make this effective.</p>
<p>If nothing seems to happen after writing the start command, then the server started. Press CTRL+C to get back to the prompt, and write <em>sudo /etc/init.d/icecast2 stop</em> to stop the server.</p>
<p>Write <em>icecast2 -b -c /etc/icecast2/icecast.xml</em> to make the Icecast server running in the background. This can be checked by writing <em>ps aux | grep icecast2</em>, then you should see two lines, the first one for the actual icecast2 process and the second one for the <em>grep</em> command you just wrote.</p>
<p>Now you can also try to reboot the computer, to check that Icecast2 server will start automatically. Write <em>sudo reboot now</em>, and observe the screen when the computer boots. You should see a few lines related to Icecast2, e.g. <em>Starting icecast2 &#8230;</em> When the computer has started, log in and check again with <em>ps aux | grep icecast2</em> that the process is in fact running.</p>
<p>You can also check that there are no errors in the error log. Write <em>cat /var/log/icecast2/error.log</em> and check it out.</p>
<p>Make sure that admin interface works. Open a web browser from another computer in the same network, and type <em>http://192.168.1.11:8000/</em> (change the IP address and port number to the ones that match your server setup). You should see a basic Icecast2 web interface in your browser. Now click the link <em>Administration</em>, and write the admin user name and password that you specified earlier into the Icecast2 configuration file. The admin web interface should load.</p>
<h3>11. Setting up sound support and a player for incoming audio data</h3>
<p>Ubuntu server installation does not include support for sound in vanilla installation. This is can be well understood, as many server setups simply don&#8217;t need any sound capabilities. However, in the audio link application the server must have sound, since we want that the server computer plays back the audio stream that it receives from the Internet via Icecast.</p>
<p>Begin by writing <em>lspci</em> to check that your sound card is recognized in Ubuntu Linux. For example, in my computer this created a list of devices and one of the printed lines tells that sound card is recognized: <em>00:0c.0 Multimedia audio controller: Ensoniq 5880 AudioPCI (rev o2)</em>.</p>
<p>Next, check that the drivers are loaded by writing <em>lsmod | grep snd</em>. In my computer, various modules were listed (11 lines, in fact).</p>
<p>Write <em>sudo apt-get install alsa-utils</em>. This will install sound support and some utilities, including volume control.</p>
<p>Write <em>alsamixer</em> to start newly installed volume control application. All volume levels are probably turned down and muted, so in order to hear anything, you need to crank up the volumes (use arrow keys) and unmute them (press &#8216;m&#8217;). Turn up at least Master and PCM lines, and check that they are not muted. Exit by pressing the <em>ESC</em> key. Then write <em>sudo alsactl store</em> to save the settings.</p>
<p>Next we will install a sound player application. It must be able to co-operate with Icecast2 software. You can find a list of media players that support Icecast2 streams from <a title="Icecast support in 3rd party applications" href="http://www.icecast.org/3rdparty.php">http://www.icecast.org/3rdparty.php</a>. Since we are using an old computer without graphical X environment, command line based applications like ogg123 and mpg321 are natural choices. Install ogg123 and related packages by writing <em>sudo apt-get install vorbis-tools</em>. You can test ogg123 for example as follows: <em>ogg123 http://www.vorbis.com/music/Epoq-Lepidoptera.ogg</em>. You should see that ogg123 begins to stream a file from the Internet and hear it being played back. If you can&#8217;t hear anything but otherwise it seems to work, then go back to <em>alsamixer</em> and check that the correct channels are turned up and not muted. Then try again.</p>
<p>Install mpg321 and related packages by writing <em>sudo apt-get install mpg321</em>. You can test mpg321 for example as follows: <em>mpg321 http://wahiduddin.net/troubleshooting/testing.mp3</em>. You should see that mpg321 begins to stream a file from the Internet and hear it being played back. If you can&#8217;t hear anything but otherwise it seems to<br />
work, then go back to alsamixer and check that you have correct channels turned up and unmuted. Then try again.</p>
<p>Now you should have sound working, and players that can stream ogg and mp3 files from the Internet &#8211; or, from your locally installed icecast software, as we plan to do.</p>
<h3>12. Testing audio streaming with another computer as a source client</h3>
<p>In this section we will finally create a working audio link. First we need to install a source client software to another computer in the same network. A list of compatible source clients can be found from <a title="Icecast compatible 3rd party software" href="http://www.icecast.org/3rdparty.php">http://www.icecast.org/3rdparty.php</a>. For example, if you use Windows computer, install e.g. Edcast. If you use Linux computer, then install e.g. Ices. Here we use console-based Ices with Ubuntu 8.04 Desktop Linux computer as a client.</p>
<p>Go to the other computer in the same network, open console and write <em>sudo apt-get install ices2</em>. This will install a source client that is compatible with Icecast2 server and can stream audio with Ogg Vorbis lossy packing algorithm. Continue working with the client computer as follows.</p>
<p>Go to your home directory by writing <em>cd ~</em>. Then create a test directory <em>mkdir icetest</em>, and go there <em>cd icetest</em>. Copy example ices2 source configuration files from ices2 documentation folder to your test dir: <em>cp /usr/share/doc/ices2/examples/ices-alsa.xml .</em> (live capture) and <em>cp /usr/share/doc/ices2/examples/ices-playlist.xml .</em> (playlist).</p>
<p>You probably want to try playlist first, as it is a bit easier to get working. Edit the configuration as follows by writing <em>nano ices-playlist.xml</em>, i.e. change the following fields (use your own server&#8217;s IP address, port and password).</p>
<blockquote>
<pre>&lt;param name="file"&gt;/home/[YOUR USER ID]/icetest/playlist.txt&lt;/param&gt;
&lt;hostname&gt;192.168.1.11&lt;/hostaname&gt;
&lt;port&gt;8000&lt;/port&gt;
&lt;password&gt;password&lt;/password&gt;
&lt;mount&gt;/test.ogg&lt;/mount&gt;
&lt;yp&gt;0&lt;/yp&gt;</pre>
</blockquote>
<p>Write out <em>CTRL+O</em>, and exit <em>CTRL+X</em>.</p>
<p>Open a web browser, go to <a title="Music at Vorbis.com" href="http://www.vorbis.com/music/">http://www.vorbis.com/music/</a> and download some .ogg sample files. Save them to <em>~/icetest</em> directory.</p>
<p>Create playlist from sample files: <em>find ~/icetest -iname &#8220;*.ogg&#8221; &gt; playlist.txt</em>. Start source by writing <em>ices2 ~/icetest/ices-playlist.xml</em>. Open web browser and go to <em>http://192.168.1.11:8000</em> and check <em>Server status</em> page, where you should be able to see that the server computer now receives data from the source computer &#8211; i.e. you should see that a new mount point has been created, called <em>/test.ogg</em>. In addition, if you go to the <em>Administration</em> page, you should see that there is now one source client and detailed information about the mount point.</p>
<p>Go to your server computer, open console, and use <em>ogg123</em> (that you set up in the previous step) to begin listening the audio stream: <em>ogg123 http://localhost:8000/test.ogg</em>. You should quickly begin to hear the sound being played back. It comes from the other computer &#8211; you have now created a working audio link!</p>
<p>However, you probably do not plan to stick to playlists only &#8211; thus, we need to setup live capturing as well. Stop both audio player (<em>ogg123</em>) and source client (<em>ices</em>) by giving them <em>CTRL+C</em>. Then, edit the configuration file again as follows by writing <em>nano ices-alsa.xml</em> on the source client computer, i.e. change the following fields:</p>
<blockquote>
<pre>&lt;hostname&gt;192.168.1.11&lt;/hostaname&gt;
&lt;port&gt;8000&lt;/port&gt;
&lt;password&gt;password&lt;/password&gt;
&lt;mount&gt;/test.ogg&lt;/mount&gt;
&lt;yp&gt;0&lt;/yp&gt;</pre>
</blockquote>
<p>Start source by writing <em>ices2 ~/icetest/ices-alsa.xml</em>. You can then test the source via web browser and <em>ogg123</em> just like you did with playlist source. However, it is somewhat likely that in the web browser everything seems to be fine at first glance, but you still don&#8217;t hear anything. In the web browser, when you click the link <em>Admin home</em> and observe the <em>/test.ogg</em> mount point&#8217;s details, you might notice that <em>total_bytes_read</em> field grows rather slowly, especially when compared to previous test with playlist stream (refresh the page a few times to see it change). If you experience something like this, then open your sound mixer in the source client computer, and try to turn volumes and switches on until you find the right configuration. This is easier to do e.g. using Audacity application, by turning input monitoring on and observing when the volume bars begin to move. Then exit audacity to release sound capturing channel, and start ices again. Streaming from live source should now work!</p>
<h3>13. Tuning the bandwith</h3>
<p>The sound quality at default settings is rather poor (downsampled to single 22 kHz channel). You probably wan&#8217;t to adjust the setting for a) higher sound quality, and b) more reliable stream (ie. no drop-outs). Case a) is handled mainly in the source client&#8217;s settings, and case b) in the player&#8217;s settings.</p>
<p>Go to source client computer and edit ices settings: <em>nano ices-alsa.xml</em>, then change the settings as follows:</p>
<blockquote>
<pre>&lt;encode&gt;
&lt;quality&gt;1&lt;/quality&lt;
&lt;samplerate&gt;44100&lt;/samplerate&gt;
&lt;channels&gt;2&lt;/channels&gt;
&lt;/encode&gt;
&lt;downmix&gt;0&lt;/downmix&gt;
&lt;resample&gt;
&lt;in-rate&gt;44100&lt;/in-rate&gt;
&lt;out-rate&gt;44100&lt;/out-rate&gt;
&lt;/resample&gt;</pre>
</blockquote>
<p>Write out <em>CTRL+O</em>, and exit <em>CTRL+X</em>. The stream contains now much higher quality sound, when you restart it: <em>ices2 ~/icetest/ices-alsa.xml.</em></p>
<p>Go to server computer and start sound playback with longer buffering: <em>ogg123 -b 256 -p 50 http://localhost:8000/test.ogg</em>. You should now hear good quality, reliable sound playback. However, note that there is more than 20 second delay between the original sound and the playback. This is mainly due to long buffers. In my test, when I set -b and -p to 0 i.e. input buffer is set to minimum size (only 8 kb), there is still 9 second startup delay (and I get occasional drop-outs). If I re-configure ices-alsa.xml and upgrade quality from 1 to 8, then the delay is less than 3 seconds. This happens because higher quality means more bits per second and thus fixed size buffers will get flushed more quickly. However, drop-outs occur more easily.</p>
<p>Now you might wonder how fast Internet connection is needed in practise. The server needs to be able to <em>download</em> in average at least the amount of data that the encoded stream requires, whereas the client needs to be able to <em>upload</em> that fast. Usually download speed is faster than the upload speed, which you must take into account: in general, the client needs a faster Internet connection than the server.</p>
<p>Therefore, what is expected from the broadband Internet connection depends on a) parameters used for the encoder (sound quality), and b) the direction of the data flow. If the connection has problems in keeping the speed of the data stream constant then faster nominal connection is necessary, so we can add c) the quality of the connection.</p>
<p>As a result, if you use e.g. 64 kbit/s stream in the encoder, then 64 kbit/s theoretical upload speed will <em>not</em> be fast enough! TCP/IP stack adds many additional bits to the stream, which also need to be transferred.  Moreover, there will always be some hiccups in the transfer (i.e. for a short moment no data is transferred at all). In order to tolerate these, additional bandwidth is required so that buffering can handle the hiccups without any audible trace. To be on the safe side, <strong>double the speed of the encoder</strong>: 64 kbit/s encoder stream should work fine on 128 kbit/s upload link.</p>
<p>I have successfully sent data (client side) using a mobile phone in EDGE (EGPRS) network, but plain GRPS is not fast enough. EDGE should be about 4 times faster than GPRS and reach above 200 kbit/s in practise. This goes well with the theory above, EDGE should be fast enough but GPRS not.</p>
<p>It is also possible to chain multiple radio networks in serial. In one test, I used a laptop as a program source. It was connected to my N95 mobile phone via Bluetooth, which connected to the Internet via EDGE. The server computer was connected to the Internet via 450 MHz wireless broadband, and played back the audio signal. Then an FM radio transmitter was used to send the audio signal as FM radio program, which was finally received and played back by an FM radio receiver. All the equipment was located in the same room, but the signal travelled through 4 different radio networks and hundreds of kilometers! The sound quality was still very good.</p>
<p>Note that this kind of setup allows great flexibility: both the program source and the transmission tower can be wirelessly connected to the Internet and thus easily moved from one location to another. The program source can also be battery powered (at least for a while), e.g. a laptop and a mobile phone. With a suitable Icecast compatible client software, the program source could be in fact be no more than a mobile phone &#8211; one could play sound files from the phone&#8217;s memory, or use the built-in microphone or e.g. a Bluetooth microphone for live programs! Although that would be very cool, I&#8217;m not aware of any such client software for mobile phones &#8211; yet.  That would be an interesting hobby project to make one.</p>
<h3>14. Auto-starting playback upon source client connection</h3>
<p>Although the audio link is already working, there is still some tricks to be done. For example, to make the server better automated and more convenient to use, we can auto-start playback when a source client connects to it with a simple script. This way we can control the playback from the client, i.e. from only one point in the chain. Here an example of such a script is presented.</p>
<p>First we will add <em>icecast2</em> user to <em>audio</em> group, so that the player can be started with a script run by <em>icecast2</em> user: <em>sudo usermod -a -G audio icecast2.</em></p>
<p>Next, create a directory for automation scripts: <em>sudo mkdir /home/radio</em> and go to that directory: <em>cd /home/radio</em>. Then create a new script for auto-starting playback: <em>sudo nano radioprogram-start.sh</em> and write the following content:</p>
<blockquote>
<pre>#!/bin/bash
# Script to be run when radio program begins</pre>
</blockquote>
<blockquote>
<pre># Notify all users of beginning radio transmission.
wall &lt; /home/radio/radioprogram-start_message.txt</pre>
</blockquote>
<blockquote>
<pre># Remove potential program end flag, if any.
FLAGFILE=/tmp/program_end.flag
if [ -e $FLAGFILE ]
then
  rm -f $FLAGFILE
fi</pre>
</blockquote>
<blockquote>
<pre># Start playing radio program.
/usr/bin/ogg123 -b 512 -p 100 http://127.0.0.1:8000/radioprogram.ogg &amp;</pre>
</blockquote>
<blockquote>
<pre># End of File</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X</em>.</p>
<p>Change permissions so that the script can be run by you and all users in the icecast group: <em>sudo chown icecast2:icecast radioprogram-start.sh</em> and <em>sudo chmod 754 radioprogram-start.sh</em>.</p>
<p>The script will print a short message to all users that have currently logged in, to notify of beginning of a radio transmission. Write a text file, which contains a message to be sent: <em>sudo nano radioprogram-start_message.txt</em> and type e.g. the following content:</p>
<blockquote>
<pre>RADIO TRANSMISSION BEGINS!!!</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X</em>.</p>
<p>Change permissions so that the message can be read by you and all users in the icecast group: <em>sudo chown icecast2:icecast radioprogram-start_message.sh</em> and <em>sudo chmod 754 radioprogram-start_message.sh</em>.</p>
<p>The script will also delete a flag file, if found from <em>/tmp</em> directory. This will be explained in the following chapter.</p>
<p>Playback will be initiated in the background, with 512 kb buffer size and 100% pre-buffering, using Icecast2 mount point named <em>radioprogram.ogg</em>.</p>
<p>In order to make Icecast2 server run the script when client opens a connection to the server (i.e. begins radio transmission), begin editing the Icecast2 server&#8217;s settings as follows: <em>sudo nano /etc/icecast2/icecast.xml</em>, then create/add the following section. Pay attention to <em>&lt;on-connect&gt;</em> line!</p>
<blockquote>
<pre>&lt;!-- Radio program configuration --&gt;
&lt;mount&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;mount-name&gt;/radioprogram.ogg&lt;/mount-name&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;public&gt;0&lt;/public&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;on-connect&gt;/home/radio/radioprogram-start.sh&lt;/on-connect&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;on-disconnect&gt;/home/radio/radioprogram-end.sh&lt;/on-disconnect&gt;

&lt;/mount&gt;</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X.</em></p>
<p>In order to test this, you need to go to the client computer and check that the mount point matches <em>/radioprogram.ogg</em> in your <em>ices</em> configuration file. Then you need to restart Icecast2 server software on the server computer so that the changed configuration file will be read: <em>/etc/init.d/icecast2 stop </em>and <em>sudo icecast2 -b -c /etc/icecast2/icecast.xml</em><em>. </em>Finally, from the client computer, start sending content to the server: <em>ices2 ~/icetest/ices-alsa.xml.</em> The player should automatically start (in the background), and a notification be printed on the screen.</p>
<p>In case of troubles, write <em>cat /var/log/icecast2/error.log</em> and check it out. Also note that it is possible that the player was in fact started OK, but there is only a problem in writing the notification text on the screen and due to long buffering delay, you don&#8217;t here anything (yet). You can test that by writing <em>ps aux</em> and observing if a process with name <em>/usr/bin/ogg123</em> is running (meaning that the script worked), or just wait a while until player&#8217;s buffer is filled and audio playback begins. For further testing, you can kill the player with <em>sudo kill [PID]</em>, where [PID] is the ID of the player process (you can see that from <em>ps aux</em> output).</p>
<p>You have now probably figured out one problem in the script: it will try to create a new player instance <em>every time</em> the client makes a connection. That&#8217;s not good in case the connection breaks and you need to reconnect. We will handle this with another script and a flag file, see next chapter.</p>
<h3>15. Shutting down server after source client disconnection</h3>
<p>When it is time to end the radio transmission, we will likely want to shutdown the server computer in the radio transmission site. If you have set up a power on/off system with e.g. SMS from a mobile phone, this can be easily performed. However, one shouldn&#8217;t just cut the power off from any computer, these devices need to be <em>prepared</em> for shutdown. For more convenient use, this can be configured to happen automatically after the source client disconnects from the server (i.e. ends sending radio program content).</p>
<p>It is possible that the connection breaks by accident for a short moment, and in this case the server should <em>not</em> automatically shut itself down. We can solve this dilemma with a time delay: after the connection gets broken, a timer will be started. When the timer triggers, we will check if the connection has been opened again, or not. Then we can decide whether to go for shutdown, or to continue radio transmission. In practise, a flag file can be created for marking a potential shutdown, to be deleted when a connection returns. If the connection doesn&#8217;t return in time, the flag file will still be there when the shutdown timer triggers, and we know that we can proceed to shutdown. Necessary code for deleting an existing flag file was already written to on-connection script in the previous chapter, now will do the rest with the on-disconnection script.</p>
<p>Shutting down the server computer requires admin rights. Since Icecast2 server software will initiate the shutdown procedure, it needs to have the right to do that. Here we allow it to run (only) the shutdown script as follows: <em>sudo visudo -f /etc/sudoers</em>, then add <em>icecast2 ALL=NOPASSWD: /sbin/shutdown</em>, save and exit.</p>
<p>Now we can create a script that will be run when the client disconnects: <em>cd /home/radio, </em>then <em>sudo nano radioprogram-end.sh</em> and write the following content:</p>
<blockquote>
<pre>#!/bin/bash
# Script to be run when radio program ends.</pre>
</blockquote>
<blockquote>
<pre># Write potential program end flag.
FLAGFILE=/tmp/program_end.flag
touch $FLAGFILE</pre>
</blockquote>
<blockquote>
<pre># Wait a while (3 minutes) to see if the program begins again.
sleep 180</pre>
</blockquote>
<blockquote>
<pre># Check if program has started again.
if [ -e $FLAGFILE ]
then
  # Notify all users of ending radio transmission.
  wall &lt; /home/radio/radioprogram-end_message.txt</pre>
</blockquote>
<blockquote>
<pre>  # Shutdown computer.
  sudo shutdown -hP now &gt; /var/log/icecast2/shutdown.log 2&gt;&amp;1
fi</pre>
</blockquote>
<blockquote>
<pre># End of File</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X</em>.</p>
<p>Change permissions so that the script can be run by you and all users in the icecast group: <em>sudo chown icecast2:icecast radioprogram-end.sh</em> and <em>sudo chmod 754 </em><em>radioprogram-end.sh.</em></p>
<p>The script will print a short message to all users that have currently logged in, to notify of ending of a radio transmission. Write a text file, which contains a message to be sent: <em>sudo nano radioprogram-end_message.txt</em> and type e.g. the following content:</p>
<blockquote>
<pre>RADIO TRANSMISSION ENDS!!!</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X</em>.</p>
<p>Change permissions so that the message can be read by you and all users in the icecast group: <em>sudo chown icecast2:icecast radioprogram-start_end.sh</em> and <em>sudo chmod 754 radioprogram-end_message.sh</em>.</p>
<p>In order to make Icecast2 server run the script when client closes a connection to the server (i.e. ends radio transmission), edit the Icecast2 server&#8217;s settings as follows: <em>sudo nano /etc/icecast2/icecast.xml</em>, then create/add the following section. Pay attention to <em>&lt;on-disconnect&gt;</em> line!</p>
<blockquote>
<pre>&lt;!-- Radio program configuration --&gt;
&lt;mount&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;mount-name&gt;/radioprogram.ogg&lt;/mount-name&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;public&gt;0&lt;/public&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;on-connect&gt;/home/radio/radioprogram-start.sh&lt;/on-connect&gt;</pre>
</blockquote>
<blockquote>
<pre>&lt;on-disconnect&gt;/home/radio/radioprogram-end.sh&lt;/on-disconnect&gt;

&lt;/mount&gt;</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X.</em></p>
<p>In order to test this, you need to go to the client computer and check that the mount point matches <em>/radioprogram.ogg</em> in your <em>ices</em> configuration file. Then you need to restart Icecast2 server software on the server computer so that the changed configuration file will be read: <em>/etc/init.d/icecast2 stop </em>and <em>sudo icecast2 -b -c /etc/icecast2/icecast.xml</em><em>. </em>Finally, from the client computer, start sending content to the server: <em>ices2 ~/icetest/ices-alsa.xml.</em> The player should automatically start (in the background), and a notification be printed on the screen. Then you can give <em>CTRL-C</em> to it, and the player on the server computer should stop as well. After the time delay, the computer should shutdown, unless you start sending content again. During the time delay, you should see the flag file already in place in <em>/tmp</em> folder and the sleep process running with <em>ps aux </em>command.</p>
<p>In case of troubles, write <em>cat /var/log/icecast2/error.log</em> and check it out. It is possible that the player stops after its internal buffer becomes empty, and the computer will shut itself down after the time delay. For easier testing, you don&#8217;t want the computer to shutdown all the time, so comment out that line from the script and re-enable it when you&#8217;re done.</p>
<h3>16. Firewall</h3>
<p>Since the server computer needs to be reachable from the Internet, some openness is required. However, you should deny all traffic exept what is absolutely necessary. This is achieved with a firewall, which can be either a separate hardware device, built-in to a network router, or implemented with software in the server computer itself. Here an example configuration is presented for using the sofware firewall included in the Ubuntu Linux distribution.</p>
<p>The firewall software is called <em>iptables</em>. It can be configured very precisely, but is known to be somewhat complex to set up. You can check current firewall rules by writing <em>sudo iptables -L</em>. By default, it should allow all traffic. Next we will configure it for audio link use by adding a few new rules. Note that the order of the following commands is very important.</p>
<ul>
<li>Allow loopback device: <em>sudo iptables -I INPUT 1 -i lo -j ACCEPT</em></li>
<li>Allow established sessions: <em>sudo iptables -A INPUT -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT</em></li>
<li>Allow incoming traffic to SSH port for remote administration: <em>sudo iptables -A INPUT -p tcp &#8211;dport ssh -j ACCEPT</em></li>
<li>Allow <em>icecast</em> sources to send radio program, and web administration: <em>sudo iptables -A INPUT -p tcp &#8211;dport 8000 -j ACCEPT</em></li>
<li>Block all other incoming traffic: <em>sudo iptables -A INPUT -i eth0 -j DROP</em></li>
</ul>
<p>Check the rules by writing <em>sudo iptables -L</em>, you should see these rules printed out:</p>
<blockquote>
<pre>Chain INPUT (policy ACCEPT)</pre>
</blockquote>
<blockquote>
<pre>target     prot opt source               destination</pre>
<pre>ACCEPT     all  --  anywhere             anywhere</pre>
<pre>ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED</pre>
<pre>ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh</pre>
<pre>ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:8000</pre>
<pre>DROP       all  --  anywhere             anywhere</pre>
<pre>Chain FORWARD (policy ACCEPT)
target     prot opt source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT)</pre>
<pre>target     prot opt source               destination</pre>
</blockquote>
<p>Save configuration now: <em>sudo iptables-save</em>, then save the firewall rules into a file: <em>sudo sh -c &#8220;iptables-save &gt; /etc/iptables.rules&#8221;<br />
</em></p>
<p>Finally we will enable the firewall rules by automatically loading them from the saved file when the network is brought up. Begin editing network configuration: <em>sudo nano /etc/network/interfaces</em>, then make the following adjustments:</p>
<blockquote>
<pre>auto eth0</pre>
<pre>iface eth0 inet static
address 192.168.1.11
netmask 255.255.255.0
gateway 192.168.1.1</pre>
<pre>pre-up iptables-restore &lt; /etc/iptables.rules</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X. </em></p>
<p>Now the server computer should only allow access to SSH server and Icecast server, blocking all other connection attemps outside.</p>
<h3><em>1</em>7. Dynamic DNS</h3>
<p>In case the broadband operator uses dynamic IP address, it can be difficult to know from which IP address the server can be accessed as it can change often. This problem can be solved by upgrading to static IP address (usually expensive), or by using a free Internet service called dynamic DNS. The service allows reserving a subdomain (xxxx.something.com) and updating your current IP address to the service, so that the traffic to your reserved subdomain can be forwarded to your current IP address. Thus you should be able to always access the server via the subdomain.</p>
<p>There are multiple providers of dynamis DNS service. Here we use DynDns.com, which is probably the most famous of them. Go to <a title="DynDns website" href="http://www.dyndns.com">www.dyndns.com</a> with a web browser, create an account and store the information you get:</p>
<ul>
<li>username: XXXX</li>
<li>password: XXXX</li>
<li>domain: XXXX</li>
</ul>
<p>The server computer needs a few adjustments to publish its IP address that it gets from broadband operator&#8217;s DHCP server to DynDns servers.</p>
<p>First install <em>ipcheck </em>tool: <em>sudo apt-get install ipcheck</em>.</p>
<p>Then continue as follows to create a place for IP publishing script: <em>sudo su</em>, <em>cd /root</em>, <em>mkdir ipcheck</em>, <em>cd ipcheck. </em>Then store the account information into a file: <em>nano dyndns_account,</em> write only one line: [dyndns username] [dyndns password] [dyndns subdomain], save <em>CTRL+O </em>and exit <em>CTRL+X.</em> Change file permissions: <em>chmod o-r dyndns_account</em>.</p>
<p>Create the IP publisher script by writing <em>nano dyndns_update.sh</em> and add the following content:</p>
<blockquote>
<pre>#!/bin/sh
cd /root/ipcheck/
if [ -f ipcheck.dat ]; then
   /usr/sbin/ipcheck -l -r checkip.dyndns.org:8245 --acctfile dyndns_account
else
   /usr/sbin/ipcheck --makedat -l -r checkip.dyndns.org:8245 --acctfile dyndns_account
fi</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X. </em>Change permissions: <em>chmod +x dyndns_update.sh</em>.</p>
<p>Type <em>exit </em>to exit from superuser login.</p>
<p>Finally we need to edit one of the system startup scripts to run our new IP publishing script: sudo nano /etc/rc.local. Add/change the file to look like this:</p>
<blockquote>
<pre>#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.</pre>
</blockquote>
<blockquote>
<pre>test -x /root/ipcheck/dyndns_update.sh &amp;&amp; /root/ipcheck/dyndns_update.sh</pre>
</blockquote>
<blockquote>
<pre>exit 0</pre>
</blockquote>
<p>Save <em>CTRL+O</em> and exit <em>CTRL+X</em>.</p>
<p>After rebooting the server, you should be able to use http://[YOURSUBDOMAIN].dyndns.org:8000/ to access the server &#8211; provided that it is running, connected to Internet and properly routed/firewall to be accessible from the Internet.</p>
<h3>18. Automatic disk scans on boot</h3>
<p>As the server may need to be rebooted during live radio programme if something goes terribly wrong, it would be VERY annoying if this happened to be the 30th time the computer is booted and a long lasting disk scan would start. Or, if the computer is used after long period of time, it would also trigger the scanning. As we actually can live without this feature, we&#8217;ll just turn it off as follows: begin editing file system configuration table <em>sudo nano /etc/fstab</em>, then change the last column from 1 to 0 for main partition, save with <em>CTRL+O</em> and exit <em>CTRL+X.</em></p>
<h3>19. Cleaning up</h3>
<p>Some reminders for things to be done before taking the server to production use:</p>
<p><strong>Check:</strong></p>
<ul>
<li>Icecast log level &#8211; what do you actually need to get logged. Also check that processes aren&#8217;t filling the hard disk with continuously growing log files (logs should be configured rorating).</li>
<li>Activate shutdown feature again in the shutdown script, in case you commented it out for testing</li>
<li>Check all passwords; they should not use any default values or otherwise bad passwords!</li>
<li>Make sure you have documented the basics of the server setup, and stored passwords to a safe place. If everything goes fine, the computer will be almost forgotten and soon nobody remembers anything about its setup &#8211; so do document!</li>
</ul>
<p><strong>Test:</strong></p>
<ul>
<li>Server start time (how many seconds after turning the power on you can start sending audio signal to the server)</li>
<li>Playback start time (how many seconds after audio signal has started to arrive will the player begin to play it back)</li>
<li>Playback stop time (how many seconds after audio signal has stopped to arrive will the player stop to play it back)</li>
<li>Server stop time (how many seconds after the audio signal has stopped to arrive the server has shut itself down)</li>
<li>That no hiccups occur with configured encoder settings</li>
<li>That the speed of the broadband connection is fast enough for used encoder settings</li>
<li>That network configuration is adjusted to the actual production network, and it works</li>
<li>That remote administration can be performed via web interface and SSH</li>
</ul>
<h3>20. Enjoy</h3>
<p>Take the server to production use and enjoy free audio link over the Internet!</p>
<p>Here is a photograph of the place where my setup is being used: Olostunturi in Muonio, Finland. The equipment is located in the cabin, and the antenna is attached to the mast on the left. On the right, you can see part of a wind mill&#8217;s tower.</p>
<div id="attachment_169" class="wp-caption alignleft" style="width: 310px"><img class="size-medium wp-image-169" title="130620093211" src="http://www.rantakokko.net/tapani/blog/wp-content/uploads/2009/06/130620093211-300x225.jpg" alt="Radio setup at Olostunturi, Muonio Finland" width="300" height="225" /><p class="wp-caption-text">Radio setup at Olostunturi, Muonio Finland</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/06/08/how-to-create-a-free-audio-link-over-the-internet-using-an-old-pc-ubuntu-linux-and-icecast-streaming-software/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://wahiduddin.net/troubleshooting/testing.mp3" length="53081" type="audio/mpeg" />
		</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>My first mini laptop, Asus EeePC 1000HE</title>
		<link>http://www.rantakokko.net/tapani/blog/2009/05/23/my-first-mini-laptop-asus-eeepc-1000he/</link>
		<comments>http://www.rantakokko.net/tapani/blog/2009/05/23/my-first-mini-laptop-asus-eeepc-1000he/#comments</comments>
		<pubDate>Fri, 22 May 2009 21:01:50 +0000</pubDate>
		<dc:creator>trk</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Ubuntu/Linux]]></category>
		<category><![CDATA[commuting]]></category>
		<category><![CDATA[EeePC]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[PC]]></category>

		<guid isPermaLink="false">http://www.rantakokko.net/tapani/blog/?p=63</guid>
		<description><![CDATA[I commute on a daily basis by bus. The travelling time is roughly 45 minutes in the morning and 50 minutes in the evening. I don&#8217;t need to change bus, its a direct route from my home door to the office door (lucky me!). So there&#8217;s long enough sitting in one spot to actually do [...]]]></description>
			<content:encoded><![CDATA[<p>I commute on a daily basis by bus. The travelling time is roughly 45 minutes in the morning and 50 minutes in the evening. I don&#8217;t need to change bus, its a direct route from my home door to the office door (lucky me!). So there&#8217;s long enough sitting in one spot to actually do something useful.</p>
<p>So far, I have been reading books or playing with my Nokia N95 &#8211; ie. listening music, reading daily news, playing games etc. However, after 2 years all this feels quite passive &#8211; instead of reading/listening/playing/otherwise consuming some form of entertainment made by others, I would like to be able to create something myself and really make use of that time. A family man never has that much time for himself, so every bit counts.</p>
<p>I&#8217;ve been carrying my bulky work laptop occasionally with me, but I don&#8217;t really want to use that for my personal stuff. Besides, that old windows installation boots in 5+ minutes&#8230; so I bought my first mini laptop. The idea is that I can easily slip it inside my backbag, boot fast, and then do much more than I can with a mobile phone.</p>
<p>I ended up to choose Asus Eee PC 1000HE (black). It&#8217;s a typical mini laptop with Intel Atom processor, 1 GB of memory and 160 GB hard drive. However, this one&#8217;s got a battery with some extra juice: advertisments claim 9.5 hour usage time! In practise it is likely closer to 7 or 8 hours, but hey -  that triples the usage time I get with my HP workhorse.</p>
<p>I have just finished installing some basic stuff and configured Windows XP to my taste (well, up to the limit where you can tailor any Microsoft product). Of course, I will install Ubuntu on this machine and use primarily that. However, I made an exception and decided to let Windows stay for now too, as occasionally one cannot avoid using it (for example, to update new firmware to my Nokia phone).</p>
<p>So far my experience of this little machine have been very nice. It turned out to be a bit heavier than I thought, but that doesn&#8217;t really matter in the bus. Keyboard is nice (to write with), and although I was a bit skeptical about the display size, 10&#8243; and 1024&#215;600 resolution seems to be good enough for basic computing things &#8211; like writing this blog.</p>
<p>So perhaps there will be more updates to the blog in the future&#8230; I&#8217;ve already got a lot of material from my hacking projects that I&#8217;m planning to put here, it just needs to be edited and published. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rantakokko.net/tapani/blog/2009/05/23/my-first-mini-laptop-asus-eeepc-1000he/feed/</wfw:commentRss>
		<slash:comments>5</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>
