Kstars

deviceorientation.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5#include "deviceorientation.h"
6
7#if defined(Q_OS_ANDROID)
8#include <QAndroidJniObject>
9#include <QtAndroidExtras>
10#include <QtAndroid>
11#define ALPHA_LOW_PASS 0.1
12#endif
13
14DeviceOrientation::DeviceOrientation(QObject *parent) : QObject(parent)
15{
16}
17
18void DeviceOrientation::stopSensors()
19{
20#if defined(Q_OS_ANDROID)
21 QAndroidJniObject activity = QtAndroid::androidActivity();
22 activity.callMethod<void>("stopSensors");
23#endif
24}
25
26void DeviceOrientation::startSensors()
27{
28#if defined(Q_OS_ANDROID)
29 QAndroidJniObject activity = QtAndroid::androidActivity();
30 activity.callMethod<void>("startSensors");
31#endif
32}
33
34void DeviceOrientation::getOrientation()
35{
36#if defined(Q_OS_ANDROID)
37 QAndroidJniObject activity = QtAndroid::androidActivity();
38 m_Azimuth = m_Azimuth + ALPHA_LOW_PASS * (activity.callMethod<float>("getAzimuth") - m_Azimuth);
39 m_Altitude = m_Altitude + ALPHA_LOW_PASS * (activity.callMethod<float>("getPitch") - m_Altitude);
40
41 float newRoll = activity.callMethod<float>("getRoll");
42 m_Roll = abs(newRoll - m_Roll) > 10 ? newRoll : m_Roll + ALPHA_LOW_PASS * (newRoll - m_Roll);
43#endif
44}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.