We have moved to a new Sailfish OS Forum. Please start new discussions there.

Revision history [back]

click to hide/show revision 1
initial version

posted 2015-03-12 14:59:05 +0200

Accelerometer ignore accelerometerMode

Greetings, everyone!

I've tried to play with accelerometer in qml and ran into a problem: in the following code "accelerometerMode:" seems to be ingored. With different mode accelerometer return the same data. As i understand, the only way to solve this is simply to subtract gravity from data. Correct?

import QtQuick 2.0
import Sailfish.Silica 1.0
import QtSensors 5.2
            Label {
                id: lx
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Label {
                id: ly
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Label {
                id: lz
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Accelerometer {
                id: accel
                active: true
                accelerationMode: Accelerometer.User
                onReadingChanged: {
                    lx.text = reading.x;
                    ly.text = reading.y;
                    lz.text = reading.z;
                }
            }

Accelerometer ignore accelerometerMode

Greetings, everyone!

I've tried to play with accelerometer in qml and ran into a problem: in the following code "accelerometerMode:" seems to be ingored. With different mode accelerometer return the same data. As i understand, the only way to solve this is simply to subtract gravity from data. Correct?

import QtQuick 2.0
import Sailfish.Silica 1.0
import QtSensors 5.2
            Label {
                id: lx
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Label {
                id: ly
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Label {
                id: lz
                x: Theme.paddingLarge
                color: Theme.secondaryHighlightColor
                font.pixelSize: Theme.fontSizeExtraLarge
            }
            Accelerometer {
                id: accel
                active: true
                accelerationMode: Accelerometer.User
                onReadingChanged: {
                    lx.text = reading.x;
                    ly.text = reading.y;
                    lz.text = reading.z;
                }
            }