Creating a remote Scroll Wheel for your Linux Machine using Android, Bluetooth and uinput

Scrolling long documents can be tiring for your index finger on a mouse wheel or on a touch pad. What if you could use your phones touch screen to scroll a document on your computer? While maybe not the most ergonomically solution it may well be a good example of how to work with bluetooth, uinput and Android.

Setup
Android Phone ( >= 2.1)
Ubuntu Laptop with Bluetooth
Two great Tutorials:
Bluez: http://people.csail.mit.edu/albert/bluez-intro/x604.html
uinput: http://thiemonge.org/getting-started-with-uinput

Concept
The application consists of two parts:

  • A client side on the phone that serves as touch pad to scroll.
  • A server part on the computer that receives commands from the phone and emulates scroll movement for uinput.

The Client is a simple Android Activity spawning a Bluetooth Thread. Touch events then result in a Bluetooth packet that tell the server if the user moved up or down. The source code is very straight forward; only Thread synchronization is a bit tricky as well as the way how the application is stopped (locks etc.).

The Server application connects the world of Bluetooth (RFCOMM/SDP) with the uinput event input system. Basically the server registers an SDP entry and then listens on an RFCOMM channel for incoming connections. As soon as a connection is established a new input device is created and scroll events are sent. Note that you probably need to be root (or use sudo) on the Linux machine to feed uinput new events.

Instructions

  • Pair your Android phone with the Linux device
  • Start the server on your Linux device: $ sudo ./btserver (make sure BT is turned on, else there could be a segfault -> working on that)
  • Install and start the app on the phone. In the menus select your Linux device.

Building Dependencies
To build the dev-libbluetooth package was necessary on our Ubuntu machine.

The code is available under GPL. Have fun playing around with it :)
Note: It’s very straight forward to create a remote control for your Linux machine with the sources. Key presses can be emulated very easily with uinput.

Source Code
Android Sources
Android APK
Server code for Linux
Our App on the Android Market

Leave a comment if you like what we did or have some improvements :)

8 thoughts on “Creating a remote Scroll Wheel for your Linux Machine using Android, Bluetooth and uinput

  1. Pingback: Scrollpad - Android Apps - Best Android Apps, News and Reviews | Android-Apps.com

  2. rer

    libbluetooth-dev installed
    $ ./btserver
    ./btserver: error while loading shared libraries: libbluetooth.so.3: cannot open shared object file: No such file or directory
    $ gcc btserver.c simplescrolling.c -o btserver
    /tmp/ccKgFmW4.o: In function `sdp_set_service_classes’:
    btserver.c:(.text+0×21): undefined reference to `sdp_set_uuidseq_attr’
    /tmp/ccKgFmW4.o: In function `sdp_set_browse_groups’:
    btserver.c:(.text+0×48): undefined reference to `sdp_set_uuidseq_attr’
    /tmp/ccKgFmW4.o: In function `main’:
    btserver.c:(.text+0x16c): undefined reference to `ba2str’
    /tmp/ccKgFmW4.o: In function `register_service’:
    btserver.c:(.text+0x29d): undefined reference to `sdp_record_alloc’
    btserver.c:(.text+0x2b7): undefined reference to `sdp_uuid128_create’
    btserver.c:(.text+0x2e4): undefined reference to `sdp_set_service_id’
    btserver.c:(.text+0x2f8): undefined reference to `sdp_uuid16_create’
    btserver.c:(.text+0x30c): undefined reference to `sdp_list_append’
    btserver.c:(.text+0×337): undefined reference to `sdp_uuid16_create’
    btserver.c:(.text+0x34b): undefined reference to `sdp_list_append’
    btserver.c:(.text+0×360): undefined reference to `sdp_list_append’
    btserver.c:(.text+0×378): undefined reference to `sdp_uuid16_create’
    btserver.c:(.text+0x38c): undefined reference to `sdp_data_alloc’
    btserver.c:(.text+0x3a4): undefined reference to `sdp_list_append’
    btserver.c:(.text+0x3bb): undefined reference to `sdp_list_append’
    btserver.c:(.text+0x3ce): undefined reference to `sdp_list_append’
    btserver.c:(.text+0x3df): undefined reference to `sdp_list_append’
    btserver.c:(.text+0x3f6): undefined reference to `sdp_set_access_protos’
    btserver.c:(.text+0x40a): undefined reference to `sdp_list_append’
    btserver.c:(.text+0x43c): undefined reference to `sdp_set_info_attr’
    btserver.c:(.text+0×493): undefined reference to `sdp_connect’
    btserver.c:(.text+0x4af): undefined reference to `sdp_record_register’
    btserver.c:(.text+0x4ce): undefined reference to `sdp_data_free’
    btserver.c:(.text+0x4df): undefined reference to `sdp_list_free’
    btserver.c:(.text+0x4f0): undefined reference to `sdp_list_free’
    btserver.c:(.text+0×501): undefined reference to `sdp_list_free’
    btserver.c:(.text+0×512): undefined reference to `sdp_list_free’
    collect2: ld returned 1 exit status

    Reply
  3. pato

    to rer: you need to link with -lbluetooth
    (add -lbluetooth to your compling line)

    To all: this is nice. I wish it did far more, like other java-based out of there. Having a remote mouse is such a useful thing for presentations.

    Reply
    1. Sam

      I got it working, just had to compile it with the right dependies etc. I did have another problem.
      read(client, buf, sizeof(buf)) always returned with -1. But when I changed the buffersize to more than 1, the problem was resolved.

      I’m now going to build a remote for my xbmc setup. See how it’ll go.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>