Tuesday 5 June 2007

Wiimote under FreeBSD using bsdmoted

I have recently acquired a Wii and the Wiimote is an interesting creation indeed. Some attempts to reverse engineer it has been made and I found that FreeBSD has a driver. Sadly though, it lacks good documentation so I thought that I would walk through what I made in order to make it work.

First of all, we need to enable Bluetooth device support by loading the ng_ubt Bluetooth module into the kernel.

If you want it to load upon boot add the following line to /etc/loader.conf

/etc/loader.conf
ng_ubt_load="YES"

And load the module immediately in order to detect any Bluetooth devices. Afterwards check dmesg in order to check if any device was detected. In my case I had to remove the BT USB stick and then insert it again for it to work properly. Somehow it seems that the O/S won't detect it properly if ng_ubg wasn't loaded when the device was first detected.

# kldload ng_ubt

Then we need to make config for the Bluetooth daemon, the default conf will do just fine.

# cp /usr/share/examples/netgraph/bluetooth/rc.bluetooth /etc/rc.bluetooth
# chmod +x /etc/rc.bluetooth
# /etc/rc.bluetooth start ubt0

Now we are on to starting the bthid daemon. First let's use the default conf. If you are unable to start bthid due to some load command (yes, I admit that I have forgot which command it was AND lost the link to the solution). Then you need to upgrade to the latest STABLE RELENG_6, where the problem has been solved.

# cp /usr/src/usr.sbin/bluetooth/bthidd/bthidd.conf.sample /etc/bluetooth/bthidd.conf
# /etc/rc.d/bthid start

Now on to getting your Wiimote's BD_ADDR. You will probably have a bundle of BT devices nearby if you live in an apartment. I detected "Willy's mobile" for example. Press 1 and 2 simultaneously on the Wiimote and it will enter a detectable mode. Then execute a following command and note down all BD_ADDR of the devices that responds.

# hccontrol -n ubt0hci inquiry
[a list of devices]

When you request the name of the device (the Wiimote should still be blinking on happily in 1 + 2 detectable mode) it should respond accordingly. It will of course use another BD_ADDR.

# hccontrol -n ubt0hci remote_name_request 12:34:56:78:9A:BC
BD_ADDR: 12:34:56:78:9A:BC
Name: Nintendo RVL-CNT-01

Now you need to fetch the bsdmoted source. Get the latest version from. http://sourceforge.net/projects/bsdmoted/
Extract it somewhere and cd into the directory. Then clean, compile, install clean.

# make clean
# make
# make install
# make clean

You now need to configure bsdmoted with some info from the Wiimote. Execute the following command to do this.

# bthidcontrol -a 12:34:56:78:9A:BC query >> /usr/local/etc/bsdmoted.conf


Now you only need to start the bsdmoted daemon.

# bsdmoted

The binds are the following:
A is the left mouse button.
B is the right mouse button.
+ and - are used to calibrate the sensitivity .
Use 1 and 2 to switch between IR-mode and tilting mode.

I did not get the IR-mode working, but perhaps you do. Enjoy!

Recommended reading:
The FreeBSD handbook on Bluetooth.

bsdmoted links:
The bsdmoted Sourceforge page.
Chuan-Heng Hsiao's bsdmoted page (videos showing that it actually works).

Going home... well... sort of

Returning to where you grew up brings you a certain feeling. A feeling of things that have been lost forever. You feel old, happy and sad. And for some reason, you want to return home, to where you currently live. Meeting friends and family is nice, but it stirs up a lot of emotions. It's exhausting.

I had the chance to take a lot of photos, wandering around Örebro and Lindesberg. Here are some of them. I will process a few panorama photos that needs to be stitched in the days to come (or tonight if I'll take a cup of tea in order to stay awake).

Let's begin with some flowers.






Then some flowers and bees.



Then some animals.

A "Skäggdopping" or Great crested grebe in English.

I am not sure which bird this was, I guess I should ask my mother to remind me on what was told about it.

A "Gräsand" or a Mallard I believe it's called in English.

In my hometown Lindesberg this relic has been left standing near the railway station. It's a pump for filling up the water tank of steam engines.

It seems that the railway company has taken actions against birds deciding to rest too close to the electric lines.


In Örebro I found this old sign on a door to a house from the early 20th century. Roughly translated into English it reads "Begging and the sale of merchandise within this property is strictly forbidden".

Saturday 2 June 2007

In health... and a panorama

Today I felt better, I managed to get some work done and ship a patch to a customer. I also remembered that cjg and I tried to make a 360 degree panorama photo from the KTH clock tower last summer. Eager to try it myself this time with my rather new camera I set off to the tower. It was closed, so I wandered around campus for roughly 2h and the sun was setting. Finally when I walked through one of the computer halls I found a view. The result can be seen below, it's a rather huge picture so I recommend opening it in a separate window. The only editing done, apart from making it a panorama from several smaller pictures, is removing some flaws made by my camera.

(singe Google don't want to host the whole image, here is a link to the real thing)

What you see is, starting from the lower left corner is the Engelbrekt church, the flag of the KTH student union beneath the flag is the one of KTH;s administrative buildings, the tall distant building is "Nyponet" a 21 story building with student apartments, next with a rather tall chimney is what I believe to be an on-campus heating plant and finally the tower of the KTH library (KTHB).

A tutorial on how to make panorama pictures.