CWiid for Android

Name:
CWiid for Android
Tags:
android, cwiid, wiimote
Description:
Program to allow Wiimotes to connect to an Android device.
Last Update:
2010-03-11

I always thought it would be cool to have a wiimote connected to my phone, specifically for use with emulators, so I'm going to try to compile CWiid for android!

My tutorials explain EXACTLY the sequence of steps I used to create the release, so that in the event I loose my release tarballs I can recreate them. If you are not planning on re-creating the releases from scratch, you can safely skip to the section labelled “Releases” for information on how to download/install a given release.

Step 0: Prerequisites

In order to compile the CWiid code for android, you're obviously going to need a native compiler for android. Thus, you will need to complete the native tutorial prior to embarking on this exciting adventure. For the entirety of this howto, I will assume that the location of your android sdk directory from that tutorial be in ${ANDROIDSDK} and that your copy of the agcc script be located at ${AGCC}.

I am doing all of my compiling on an x86_64 gentoo machine. These instructions should work on any standard linux distribution, though.

Also, as per usual, set up a place to compile:

mkdir ${CWIID}
cd ${CWIID}

Step 1: Get CWiid

The first step is obviously to get the CWiid source:

cd ${CWIID}
wget http://abstrakraft.org/cwiid/downloads/cwiid-0.6.00.tgz
tar -zxvf cwiid-0.6.00.tgz
cd cwiid-0.6.00
In the event that abstrakraft's website becomes unavailable in the future, I have saved a copy of this tarball here.

Step 2: Porting CWiid to Android

This step has essentially been the bane of my existance, as there is a LOT of problems with trying to get the code to compile, mostly in the sense that libraries that are required aren't present.

To circumvent this, I have essentially solved the problems and made a beautiful little patch for everyone to download to auto-fix everything. However I will document what I can remember below

Boo ./configure

Every time I see a ./configure script when porting, it makes my blood boil. They are a nuisance to code around as they try to run code for tests, which is difficult when cross-compiling. (I know there is a more adequate way to do this (like actually cross-compiling), but I haven't learned it yet).

So anyway, I ran ./configure as using the host toolchain, and then manually modified the makefiles (yep).

Oh Thank You Mystery Man

I must put in a special thanks to whoever posted the patch that I reference at the bottom of the page. It was a fantastic starting point and helped out with a lot of problems.

hci_remote_name

hci_remote_name was deprecated in bluez, so I simply changed those references to the new hci_read_remote_name

paths paths paths!

There were some ugly path issues that had to be solved as well. I'm going to try to forget about them now >.>

OMG PLUGINS!

Anyone who has spoken to me while working on this knows that bionic + plugins = bad. There were SO many undefined reference errors I don't even know where to begin. So essentially I had to rip all of wminput apart and put it in it's own library, libwminput.so. This required quite a bit of Makefile editing as well as some substantial source code changes, but in the end it was worth it :D

And now THE PATCHES!

So after many hours of toiling, here are the patches:

And now we patch our source, as well as make some last-minute modifications:

cd ${CWIID}/cwiid-0.6.00
lzma -cd ${loc_to_download}/cwiid-android-001.patch.lzma | patch -Np1
lzma -cd ${loc_to_download}/cwiid-android-002.patch.lzma | patch -Np1
lzma -cd ${loc_to_download}/cwiid-android-003.patch.lzma | patch -Np1
SED="s/^COMMON =.*$/COMMON = $(pwd | sed -r 's/\//\\\//g')\/common/"; sed -i -r "$SED" defs.mak
ln -s ${ANDROIDSDK} android-sdk
chmod 755 agcc

Step 3: Compiling

Finally, we can compile our cwiid libraries:

cd ${CWIID}/cwiid-0.6.00
export PATH=$(pwd)/android-sdk/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:${PATH}
make

And if all goes well, things should compile smoothly! :D

Step 4: Pushing to the Device

To make this easier, I am going to first log into the device, and create the necessary directories, as well as mount the system rw.

All of the ADB commands must be run as root. I use AdamZ's ROM so the shell is in root mode by default. Be sure to run su if you need to.
adb shell
 
# mount read/write
$ sysrw
 
# set umask (so that directories are created with proper permissions
$ umask 0022
 
# make the directories
$ busybox mkdir -p /system/etc/cwiid/wminput
$ busybox mkdir -p /system/lib/cwiid/plugins
 
# now exit
$ exit

Next we push the files to the system in the proper places:

cd ${CWIID}/cwiid-0.6.00
 
# push the libraries first
adb push libcwiid/libcwiid.so.1.0 /system/lib/libcwiid.so
adb push libwminput/libwminput.so.1.0 /system/lib/libwminput.so
 
# then the executables
adb push wminput/wminput /system/xbin/
adb push lswm/lswm /system/xbin/
 
# then the plugins
for i in wminput/plugins/*/*.so; do adb push ${i} /system/lib/cwiid/plugins/; done
 
# push default configs
for i in wminput/configs/*; do adb push ${i} /system/etc/cwiid/wminput/; done

And finally, we return to our device to modify permissions and ownership, as well as remount our system ro:

adb shell
 
# permissions!
$ chmod 755 \
/system/xbin/lswm \
/system/xbin/wminput
$ chmod 644 \
/system/lib/libcwiid.so \
/system/lib/libwminput.so \
/system/lib/cwiid/plugins/* \
/system/etc/cwiid/wminput/*
 
# ownership!
$ busybox sh
$ chown 0.0 \
/system/xbin/lswm \
/system/xbin/wminput \
/system/lib/libcwiid.so \
/system/lib/libwminput.so \
/system/lib/cwiid/plugins/* \
/system/etc/cwiid/wminput/* \
/system/lib/cwiid \
/system/lib/cwiid/plugins \
/system/etc/cwiid \
/system/etc/cwiid/wminput
$ exit
 
# and now mount the system read-only
$ sysro
$ sync
 
$ exit

And there you have it! A working copy of CWiid for Android!

Step 5: How does it work?

Well, since I haven't taken the time to write an APP to control it yet, you have to start the input daemon from adb. Essentially these are the steps:

  • Edit a config file and place it on the system. (the default configs are in /system/etc/cwiid/wminput to give you an idea of how this works.
  • Ensure that bluetooth is enabled
  • Log into adb and start the WMINPUT daemon
adb shell
$ wminput -w -c ${CONFIGFILE_NAME}

This will start up the daemon and put it into a perpetual waiting state (-w), for more options check wminput –help

  • Press 1+2 on your wiimote to connect (make sure your Wii isn't on or the Wiimote will connect to that instead)
  • Press and hold power on your wiimote to disconnect

And that's basically all there is to it!

This daemon talks directly to the user input device, so all input you send on the wiimote will be sent to the global device, not the ADB shell. (good things).
A list of valid KEY codes for WMINPUT's configs can be found here

Releases

Below are any releases of this software that I have made.

CWiid-Android v1.0.0 (MAJOR RELEASE!)

Well here it is! The MAJOR RELEASE of CWIID! So far as I can tell ALL functionality currently supported in CWiid 0.6.00 is now supported in CWiid-Android!

Download: [removed]

Install:

  • Push the .rom.tgz file to /sdcard
  • Reboot into recovery mode (SPRecovery)
  • install → install ROM from /sdcard → cwiid-android-1.0.0
  • After it performs a NAndroid backup it will unpack the rom.tgz and give you the option to install or cancel installation, choose install.
  • You're done! Reboot and the files/directories should be on your phone in the proper place :D

Changes from v0.9.1:

  • All plugins are FINALLY working! HUZZAH!
  • New libwminput.so library used to support plugins.

TODO:

  • Still need to fix the problem with re-loading the key mappings without disassociating. (v1.1.0)
  • Develop a root APP to control all of this

CWiid-Android v0.9.1

I have finally gotten a ROM.tgz build of this working for easier installation. It removes any existing CWiid libraries/binaries/default configs/plugins and installs the new ones for this release automagically.

Download: TAKEN DOWN (there was an error in this O.O)

Changes from v0.9.0:

  • Added the nunchuk_stick2btn plugin from CWiid SVN
  • Added the led plugin from CWiid SVN
  • New ROM.tgz installation format

TODO:

  • There are some problems loading the IR, Accelerometer, Nunchuk, and LED plugins. Looking into that.
  • Still need to fix the problem with re-loading the key mappings without disassociating.
  • Develop a root APP to control all of this

CWiid-Android v0.9.0

I have built a release of this just to make it easier on people who don't wish to build the SDK and compile everything from scratch. It basically is just a tarball of all of the files that would be pushed to your system, in the proper directory structure.

Download: [removed]

Features:

  • Ability to connect your Wiimote to your phone! (multiple Wiimotes have not been tested)
  • Support for IR sensor and Accelerometer, as well as Classic Controller and Nunchuck extensions
  • Ability to map any button/joystick from any supported device/extension to any standard keyboard/mouse button.

TODO:

  • Move from .tar.gz format to update.zip format (or possibly rom.tgz format) for easier installation
  • Develop root application to make setup much easier
  • Currently the only way to re-map something is by killing wminput and restarting it with a new config. I hope to recode that.

References

  • CWiid - the CWiid project website
  • Android Patch - found this gem of a patch to get CWiid to compile
  • hci_remote_name ticket - a bug ticket on the CWiid website that explained how to fix the problems with hci_remote_name deprication
 
projects/android/cwiid4android.txt · Last modified: 2014/05/13 12:36 (external edit)
 

Hosted on Microsoft Azure Powered by PHP Driven by DokuWiki RSS Feed

© 2011 Austen Dicken | cvpcs.org