There is a bunch of code out there (which can be copied and pasted) to grab the acceleration values from Nokia N900. Here I contribute one more, it’s Qt-based and using the QtDBus module. The values in x, y, z will have the unit of G.
QDBusConnection connection(QDBusConnection::systemBus()); QDBusInterface interface("com.nokia.mce", "/com/nokia/icd", QString(), connection); QDBusPendingReply<qstring> reply; reply = interface.asyncCall("get_device_orientation"); reply.waitForFinished(); x = static_cast<qreal>(reply.argumentAt<3>()) / 1000; y = static_cast</qreal><qreal>(reply.argumentAt<4>()) / 1000; z = static_cast</qreal><qreal>(reply.argumentAt<5>()) / 1000; </qreal></qstring>
As usual, error checking is omitted (left as an exercise for the reader). Like Star Wars, there is also a reason I skip the first 3 QStrings. Debug it yourself to see what you would get. In addition, I found out that at most it would take 25 ms to grab all three values. It means, if you run your application at > 40 fps, then better put this function is a separate thread. Actually, consider that you don’t want QDBusPendingReply::waitForFinished() to block your entire GUI, this is likely a good idea anyway.
For a full-version of an accelerometer tool, check out the X2 repository under the sub-directory sensor/accelview. Note that technically acceleration > 1 G is always possible, I clamp the values in this example to keep the UI simple.