Dec 7, 2006

GentooLinuxでWiiリモコンを試す その2

前回から大幅に進展。 Control X.Org cursor with Wiimoteで公開されたドライバにより、LinuxなどのX環境でWiiリモコンが使えるようになったらしい。赤外線センサーにも対応した模様。早速試す。 試した環境は前回と同じ。

  • Wiiリモコン(RVL-003)
  • PLANEX BT-01UDE(Bluetooth Ver2.0 USBアダプタ)
  • Gentoo Linux amd64(kernel gentoo-sources-2.6.18-r3)
まず、カーネル再構築。Bluetoothが使えるようにするのと、CONFIG_INPUT_EVDEV, CONFIG_INPUT_UINPUTを有効に。
Networking ---> <*> Bluetooth subsystem support ---> --- Bluetooth subsystem support L2CAP protocol support SCO links support RFCOMM protocol support [*] RFCOMM TTY support BNEP protocol support [*] Multicast filter support [*] Protocol filter support HIDP protocol support Bluetooth device drivers ---> HCI USB driver [*] SCO (voice) support HCI UART driver [*] UART (H4) protocol support [*] BCSP protocol support [*] Transmit CRC with every BCSP packet HCI BCM203x USB driver HCI BPA10x USB driver HCI BlueFRITZ! USB driver HCI VHCI (Virtual HCI device) driver Device Drivers ---> Input device support ---> <*> Event interface [*] Miscellaneous devices ---> User level driver support USB support ---> <*> Support for Host-side USB --- USB Host Controller Drivers EHCI HCD (USB 2.0) support [ ] Full speed ISO transactions (EXPERIMENTAL) [ ] Root Hub Transaction Translators (EXPERIMENTAL) <*> OHCI HCD support <*> UHCI HCD (most Intel and VIA) support < > SL811HS HCD support
必要なソフトウェア(ebuild)は、
  • net-wireless/bluez-libs-3.7
  • net-wireless/bluez-utils-3.7
  • dev-python/pybluez-0.9.1
  • x11-drivers/xf86-input-evdev
  • dev-python/python-xlib
bluez-libs, bluez-utils, pybluezの最新ebuildはまだPortageツリーに入ってない。バージョン番号を変更するだけで動作するので適宜修正、追加。 Bluetoothを動作させる。
$ sudo /etc/init.d/bluetooth start
Wiiリモコンのアドレスを取得。WiiリモコンのSyncボタンを押して以下のコマンドを実行。
$ hcitool scan Scanning ... 00:19:1D:xx:xx:xx Nintendo RVL-CNT-01
上記のようにアドレスが表示されたらBluetoothの通信はできているはず。 続いてドライバを用意。
$ wget http://davr.org/wiimotulator.py.txt -O wiiremote.py $ vi wiiremote.py
55行目のMY_WIIMOTE_ADDRに、Wiiリモコンのアドレスを記入する。 64bit環境の場合は、818行目の"LLHHl"を"LLHHi"に変更する。 X環境を設定。Wiiリモコン用のInputDeviceを追加。ServerLayoutに1行追加。
$ sudo vi /etc/X11/xorg.conf Section "InputDevice" # Identifier "Wiimote" Driver "evdev" Option "Name" "Nintendo Wiimote" EndSection Section "ServerLayout" Identifier "X.org Configured" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" InputDevice "Wiimote" "AlwaysCore" EndSection
で、実行。WiiリモコンのSyncボタンを押して、
$ sudo python wiiremote.py Registered key KEY_KPPLUS for button + with code 4e Registered key KEY_KPMINUS for button - with code 4a Registered key BTN_LEFT for button 1 with code 110 Registered key BTN_RIGHT for button 2 with code 111 Looking for Wiimote services at address 00:19:1D:xx:xx:xx Victory! We have found that Wiimote! We are now connected to Wiimote at address 00:19:1D:xx:xx:xx
と出ればOK。 適当にボタンを押すと画面上にメッセージが出るはず。 デフォルト設定では以下の通り。
  • 上ボタン WiiリモコンのLED1
  • 下ボタン WiiリモコンのLED2
  • 右ボタン WiiリモコンのLED3
  • 左ボタン WiiリモコンのLED4
  • Aボタン バイブレーションON
  • Bボタン バイブレーションOFF
  • -ボタン キーボードの-キー
  • +ボタン キーボードの+キー
  • 1ボタン マウスの左クリック
  • 2ボタン マウスの右クリック(私の環境では中クリックになってしまった)
  • HOMEボタン 終了
他、加速度センサーも検知。ボタン設定は118行目から130行目のcommandMapで変更可能。 赤外線センサーも動作するはずなのだが、私の環境(ロウソク2本)では動かなかった。赤外線センサーが正常に動いた方、連絡ください。 12/9追記・修正 最新版に更新したところ、赤外線センサーが動作するようになりました。 Wiiを持ってない方はロウソク2本用意しましょう。私はロウソク2本で動作確認しました。

No comments: