[SailfishDevel] QAccelerometer availability ?

Franck Routier (perso) alci at mecadu.org
Mon Jan 13 08:41:14 UTC 2014


Thanks all for your help.

I ended up with this QML and thought I might share with the list:

- added qt5-qtdeclarative-import-sensors in Requires (.yaml)
- created a component that checks if the device is shaked:

ShakeSensor.qml

import QtQuick 2.0
import QtSensors 5.1

Accelerometer {

    signal shaked
    property real sensitivity: 30
    property real module: 0

    active: true
    dataRate: 20

    onReadingChanged: {
        var rx = reading.x;
        var ry = reading.y;
        var rz = reading.z;
        var cmodule = Math.sqrt(rx * rx + ry * ry + rz * rz);
        var cshake = Math.sqrt(Math.pow(module,2)+Math.pow(cmodule,2));

        if( cshake >= sensitivity ) {
            shaked();
        }

        module = cmodule;
    }
}


This code is strongly indebted to QShake by Sebastiano Galazzo
<sebastiano.galazzo at gmail.com> for the way to find if device was shaked
out of accelerometer readings. Thanks to him.

Check the result in my MkPokerPlanning app ! :-)

Best regards,
Franck

Le 12/01/2014 17:00, Mike Sheldon a écrit :
> On Sun, 2014-01-12 at 16:42 +0100, Franck Routier (perso) wrote:
>> But... I get this:
>>
>> SensorManagerInterface::interface:78 - Requested sensor id '
>> "accelerometersensor" ' interface not granted
>>
>> Any idea where this comes from ?
> 
> The emulator doesn't simulate accelerometer sensors, for this sort of
> thing your only option is to test on device.
> 
> Cheers, 
> Mike.
> 
> _______________________________________________
> SailfishOS.org Devel mailing list
> 



More information about the Devel mailing list