summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors/android/androidtemperature.cpp
blob: f4c6cbe2a58ae5ea1a391ebdd7e571f7bb9fc676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Copyright (C) 2019 BogDan Vatra <bogdan@kde.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "androidtemperature.h"

AndroidTemperature::AndroidTemperature(int type, QSensor *sensor, QObject *parent)
    : SensorEventQueue<QAmbientTemperatureReading>(type, sensor, parent)
{}

void AndroidTemperature::dataReceived(const ASensorEvent &event)
{
    if (sensor()->skipDuplicates() && qFuzzyCompare(m_reader.temperature(), qreal(event.temperature)))
        return;
    m_reader.setTimestamp(uint64_t(event.timestamp / 1000));
    // https://developer.android.com/reference/android/hardware/SensorEvent.html#sensor.type_ambient_temperature:
    m_reader.setTemperature(qreal(event.temperature)); // in  degree Celsius
    newReadingAvailable();
}