glennji.com

Because breaking things is much more fun

ubuntu

Jan 18

Alphacool LCD support in serdisplib, lcd4linux - the hard way

The Alphacool LCD is nice: 320x200 pixels, graphical, brushed aluminium with a blue back-light. I've got one in my main PC, and it's been sitting there - inactive - since I upgraded from Ubuntu Feisty. Yesterday I (finally) got it going again, with only a little mucking about.

The display is now officially in serdisplib, provided you've got libusb (and specify it in the configure), and there is a serdisplib-based driver in lcd4linux ... although it's not compiled in the standard lcd4linux package that comes with Ubuntu Intrepid.

So, first thing was to download serdisplib and compile it. To do this in a slightly-more sensible way I use checkinstall to create a .deb package. It's a good idea, because it means the software is controlled by the packaging system (and can therefore be removed or reinstalled as necessary). Install checkinstall if you don't have it

sudo apt-get install checkinstall

So, I gunzipped the serdisplib package then opened a terminal and navigated to the appropriate directory:

cd ~/serdisplib-1.97.8

This is the source-code of serdisplib, so I need to configure and make it to compile it for my system. Make sure you scroll back up and check the output of the configure, because the first time I tried it didn't compile libusb because I didn't have the libusb-dev package. This was resolved by installing it in the usual way:

sudo apt-get install libusb libusb-dev

So then, configure and make:

./configure --enable-libusb
make

Alright, at this point I had compiled the binaries, but they're still sitting in this directory (rather than the /usr/bin and other system directories). It's a good time to test out the display:

testserdisp -n alphacool -p 'USB:060C/04EB'

It's a bit weird, but the display shows up as an "EEH Datalink GmbH". Try:

lsusb

... and you can see an entry like

Bus 004 Device 002: ID 060c:04eb EEH Datalink GmbH

Anyway, my test worked - the LCD was activated and displayed a test pattern. You can run a few tests with this one, but I was just happy to see it running again. Time to install serdisplib to the system!

Normally, this is done by running something like "sudo make install", which copies the compiled files and libraries to the appropriate locations, but as I said earlier this would mean serdisplib was entirely outside the packaging system. Instead, run:

checkinstall

This will ask a couple of questions (a description) and then create a .deb package which can be installed (and removed) like any other package. Find the .deb in the same directory and either double-click it in the file manager or install it from the terminal with

sudo dpkg -i serdisplib_1.97.8-1_i386.deb

What I didn't realise, but probably should have, is that this installs to /usr/local (e.g. /usr/local/bin, /usr/local/lib) rather than /usr. This isn't really a problem, but lcd4linux had trouble a little further on finding the libraries in /usr/local/lib rather than /usr/lib. At the time, I just copied the serdisplib stuff from /usr/local/lib to /usr/lib, but it would probably be better to either configure serdisplib to use /usr, or configure lcd4linux to look in /usr/local/lib. Oh well.

So, onto lcd4linux. I already had lcd4linux installed from the Ubuntu repositories, but it didn't include the serdisplib driver. You can check what drivers are included with

lcd4linux -l

So it was time to download the source code for lcd4linux too. Gunzip this in the same way as serdisplib. After attempting to compile this a couple of times I found I needed to patch the source code. Download the patch to your home directory and apply it

cd ~
patch -p0 < lcd4linux-0.10.1_rc2-nordtsc.patch

then we can compile and install it

cd lcd4linux-0.10.1-RC2
./configure
make
checkinstall
sudo dpkg -i lcd4linux-0.10.1_RC2-1_i386.deb

Cool! So now I had the new lcd4linux AND it had serdisplib support. Because I had the Ubuntu repository one too, I could test the two:

/usr/sbin/lcd4linux -l

That's the Ubuntu repo one

/usr/local/bin/lcd4linux -l

and that's the new one. Importantly, this has the line

serdisplib          : any

showing that it has the serdisplib support compiled in.

Because I had installed the repo one first, I already had an init.d script for starting lcd4linux at boot time. However, you want to edit /etc/init.d/lcd4linux and specify the absolute path to the new lcd4linux executable. i.e. change the DAEMON line to:

DAEMON=/usr/local/bin/lcd4linux

Also, you need an lcd4linux config file in /etc/lcd4linux.conf. The easiest way to get this is copy the sample one

sudo cp /usr/share/doc/lcd4linux/lcd4linux.conf.sample.gz /etc/
cd /etc
sudo gunzip lcd4linux.conf.sample.gz
sudo mv lcd4linux.conf.sample lcd4linux.conf

Now edit /etc/lcd4linux.conf with your favourite text editor. Find the SerDispLib display section and replace it with this:

Display SerDispLib {
   Driver 'serdisplib'
   Port 'USB:060C/04EB'
   Model 'ALPHACOOL'
}

Then go to the end of the file and comment/uncomment the appropriate line to specify the SerDispLib display

Display 'SerDispLib'
#Display 'LCD-Linux'
#Display 'LCD2041'
#Display 'LK202'
#Display 'LK204'
#Display 'MI240'
#Display 'CW12232'
#Display 'HD44780-generic'
#Display 'HD44780-WinAmp'

... and a layout

Layout 'Default'
#Layout 'TestLayer'
#Layout 'TestImage'
#Layout 'L8x2'

All being well, you should be able to start up lcd4linux and have the display activate with

sudo /etc/init.d/lcd4linux start

Cool!

There's a lot of tweaking and playing that you can do with lcd4linux layouts, so go nuts.

Jul 11

Gaming for self-improvement

Some people are naturally strategic thinkers. We all subconsciously process a multitude of data-points -- other peoples' emotional states, for example; the tiny signals that say "danger!"; even driving a vehicle. But some people take that processing to a higher abstraction and think in terms of situations, outcomes, agents -- even if they don't realise that's how they think.

Someone who is good at chess is obviously a strategic thinker. But so is the social or corporate climber, or the rally-organiser, or the RTS-gamer. Hell, business-people and entrepreneurs are strategic thinkers of a high-order. This might be obvious to a lot of people, but I've realised that I don't think this way. Strategy lets me down. I play instant-action games (FPS) and live for the moment, with only a cursory nod towards the future ... since the future I plan for may not eventuate!

So I decided that I should take steps to improve my strategic thinking abilities, and after talking to a friend I decided upon a computer game called "Dawn Of War". Set in the distant-future Warhammer 40,000 universe, you control squads of the post-human "Space Marines" and battle various alien and other-dimensional beings. What I like about Dawn Of War is the rich mythology and storyline -- I read some Warhammer 40,000 books growing up, and have seen the table-top game in stores (although not tried it). So it fulfils my basic need for imagination-fuel better than the old favourites Starcraft, Total Annihilation or Command & Conquer.

Better, the game was £10 from Amazon, and ran first-time in Wine on Ubuntu Linux.

Like I say, I'm not naturally a strategic-thinker, but I have noticed a certain change in my abilities as I play through the levels (sometimes multiple times, to try out different tactics). I was also thinking this morning about the general rules for RTS games I've determined so far, and how they might apply to things in Real Life® (RL):-

Nail the build-order
Or: Determine the optimal process
In-game, this means figuring out what the best order of build commands should be: do I need a main base, then a plasma generator, then a barracks, another generator then a squad? There is definitely an optimal process to building up big in as short a time as possible, and games like Dawn Of War capitalise on that by introducing new units, vehicles and structures with each tutorial mission.

In-RL, process optimisation is the best way to either lighten your workload (if applied to a 9-to-5 job) or get more done (if applied to your own entrepreneurial endeavours). To optimise a process you have to both observe the process and consider it -- that is, apply conscious analysis and effort to an accurate mental model of the process, rather than just following a process because it is familiar or for its own sake. Most humans will just follow the process without deep-thinking it -- why else do we exchange most of our time for money? Even if we are the boss?

Keep your troops close
Or: proximity begets communication/cooperation
In-game: any army can be defeated if spread too thin, and having more than a few clusters of troops means you cannot effectively monitor them -- a war on too many fronts is a losing proposition. (This has been used by military leaders historically, and is the reason we use the singular phrase "The Front" or "The Front Line" rather than something like "The Fronts".) So cluster together, build a secondary base near the front if possible and replenish your troops from there.

RL: Apart from the obvious military tactics, it makes sense to keep your resources close-at-hand. For personnel, co-locating business (sales, marketing) and technology (operations, manufacturing) means real communications and faster reactivity to the changing market (the "front" for commercial enterprise). For personal, having a "dashboard view" (e.g. of finances) allows for situational analysis and problem avoidance that is both fast and intelligent. Continuing the finance example, it makes sense to have a portfolio (hell, a spreadsheet will do) of all investments, assets, savings, debts, debtors and budgeted projected requirements in one place.

Automatic-fire gun turrets are your friend
Or: automate everything -- including notification
In-game example: For the last mission I played, I had multiple attack points -- enemy troops (those damn Eldar) would hit me from a number of sides, and it was all I could do to move my retalitory troops from one side of the base to the other. Not good. So I built up the necessary capabilities and started placing automatic-fire gun turrets at the usual incursion locations.

Suddenly my troops weren't even needed -- a couple of turrets could take out all but the most concerted attack, and my builder (technician, drone) was nearby to repair or replace the turrets as needed. I could build up my army and begin my own strikes, expanding the "safe" territory ... and then building more automatic-fire turrets, expanding, rinse and repeat ad infinitum (or at least until the end of the mission).

In RL as in the game, automation is a necessary tactic for getting beyond the level of survival (putting out fires, keeping the show on the road, keeping our heads above water -- we have so many colloquialisms for this because it's deep in our psyche) towards actually doing something useful. Utilising humans as brainless robots is stupid; doing it to ourselves is even more ridiculous.

When I refer to automation in RL, I mean getting a more efficient system to do repetitive tasks for us, leaving us to do the things we are good at. It includes the field of "intelligence augmentation" (using systems to provide us with appropriate information in a ready-format which augments our decision-making) and even, say, World Wide Web search engines. If I pay my bills by direct-debit or standing order, it's automated. If my PC backs up my personal files for me, it's automated. If my Oyster travel card adds £20 every time the balance gets too low ... you guessed it.

In Timothy Ferris' Four Hour Work Week, automation is the key to a low-maintenance "muse" business -- every possible part of the order-fulfillment backend is integrated, so an order on the web is sent directly to the factory, which sends the completed goods to a drop-shipper (who was also automatically advised of the delivery destination). This leaves Tim to either deal with customer queries, or go swimming in Greece. Whichever he prefers.

But of course you have to trust your automated systems, and the only way to do that is to be notified of exceptional situations. Automation's noisy twin is thus notification -- you want to know if you're double-charged, or your manufacturing chain breaks down, or your solar collector array is on fire. Unless it's AI, an automated system will eventually be out-of-date and out-of-sync with it's environment i.e. the model upon which the system was based no longer matches reality. So timely, appropriate notification of exceptional "edge-conditions" can allow you to tweak the automated system back in-line.

Anyway, that's all I've got so far. I'm sure there's much more that can be learned from strategy games.

May 12

Installing MediaTomb UPnP Media Server

Mediatomb is an free open source UPnP server for Linux and Mac OS X. It allows you to stream media (videos and music) to networked devices for playback, and has an (admittedly grim) web-based GUI.

Installing in Ubuntu or Debian is easy (for other distros please check the website). First, add the gpg key so the package can be verified:

   wget http://apt.mediatomb.cc/key.asc -O- -q | sudo apt-key add -

Add the following line to /etc/apt/sources.list:

   deb http://apt.mediatomb.cc/ feisty main 

(Note that although the package specifies "feisty" it will work in the new "gutsy" i.e. Ubuntu 7.10.)

Now install like normal:

   sudo aptitude install mediatomb

Unfortunately the version here doesn't seem to support MySQL as a backend.

Of course, you will want to add your music too. If my music collection is at /opt/share/Music:

   sudo mediatomb --add /opt/share/Music

Now you can tune in with a music player such as Rhythmbox or iTunes

May 12

Password-less logins with PAM

Sometimes you want certain to be able to log in to certain user accounts without a password -- for a guest account, for example. It's not terribly secure, sure, but sometimes you don't need that security. Read on for how to do this on any GNU/Linux OS that uses PAM and GDM.

To enable password-less logins for any operating system that uses PAM and GDM, edit /etc/pam.d/gdm to add the following line:

   auth    sufficient      pam_listfile.so sense=allow file=/etc/passwordless item=user
   
   @include common-auth
   ... 

Then create the /etc/passwordless file (readable only by root). List each user you want to login without a password, one per line.

If you are using the GDM autologin feature, add the line "@include common-pamkeyring" to /etc/pam.d/gdm-autologin. I haven't tried it, but this is reported to allow the no-password user wireless access without entering the keyring password.

If not, you need a script like the following to your session startup:

   #!/bin/sh
   exec echo -n "MyKeyringPassword" | /usr/lib/libpam-keyring/pam-keyring-tool -u -s

However, pam-keyring-tool is not included in Ubuntu 7.10, so you need to compile it.