Sunday, June 27, 2010

Using vibration API in Maemo

Recently I was creating some simple application that give notification when some new information is available in one site that I visit often.

This application play sound and vibrate when new information is available. In this blog I will share code required to enable vibration support in Maemo application and I am using Qt framework to implement my application.

In Maemo, Vibration API is based on DBUS call, with proper DBUS call you can enable disable vibration and apply certain vibration pattern.

To be able to use DBUS api, Qt required to enable DBUS support, which can be done by putting this line "Qt += dbus" in to .pro file.

Now we can use DBUS API to enable and apply vibration. API are from following headers.

#include <QtDBus>

#ifdef Q_WS_MAEMO_5
#include <mce mode-names.h>
#include <mce dbus-names.h>
#endif

by sending MCE_ENABLE_VIBRATOR dbus call, we tell OS to enable vibration support.

void Sample::enableVibration()
{
    #ifdef Q_WS_MAEMO_5
    mDbusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
                                     MCE_REQUEST_IF, QDBusConnection::systemBus(),
                                     this);

    mDbusInterface->call(MCE_ENABLE_VIBRATOR);

    #endif
}

Now that, vibration is enabled, we can apply certain vibration pattern. For my application is am enabling "PatternIncomingCall", After this call vibration will be on until we deactivate applied vibration patter.

void Sample::vibrate(int aTimeout)
{
    #ifdef Q_WS_MAEMO_5

    mDbusInterface->call(MCE_ACTIVATE_VIBRATOR_PATTERN, "PatternIncomingCall");
    QTimer::singleShot(aTimeout,this,SLOT(stopVibration()));
    #endif
}

And finally "MCE_DEACTIVATE_VIBRATOR_PATTERN" dbus call will deactivate vibration patter.

void Sample::stopVibration()
{
    #ifdef Q_WS_MAEMO_5
    mDbusInterface->call(MCE_DEACTIVATE_VIBRATOR_PATTERN, "PatternIncomingCall");
    #endif
} 

So this was all that required to enable vibration support for Maemo application.

Saturday, June 5, 2010

Snake game for Maemo

Past few weeks I was working on Snake game implementation for maemo. I tried to implement classic snake game in Qt as learning exercise. To make game more interesting, game is using Accelerometer to direct snake and there is also support for keyboard to direct snake.

Source code is already in gitorous. and installation file is also uploaded on maemo extra-testing repository. To install game on n900 enable either extra-devel or extra-testing and then from terminal type apt-get install snake.

Here are fews snaps from game for overview.