2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "accelerometersensorimpl.h"
21
char const * const AccelerometerSensorImpl::id("aal.accelerometer");
23
AccelerometerSensorImpl::AccelerometerSensorImpl(QSensor *sensor)
24
: QSensorBackend(sensor)
26
m_accelCommon = new AccelerometerCommon(this);
28
// Register the reading instance with the parent
29
setReading<QAccelerometerReading>(&m_reading);
31
const qreal minDelay = m_accelCommon->getMinDelay();
34
// Min and max sensor sampling frequencies, in Hz
35
addDataRate(minDelay, minDelay * 10);
37
addOutputRange(m_accelCommon->getMinValue(),
38
m_accelCommon->getMaxValue(),
39
m_accelCommon->getResolution());
41
// Connect to the accelerometer's readingChanged signal
42
connect(m_accelCommon, SIGNAL(accelerometerReadingChanged()), this, SLOT(onAccelerometerReadingChanged()));
44
setDescription(QLatin1String("Accelerometer Sensor"));
47
AccelerometerSensorImpl::~AccelerometerSensorImpl()
49
if (m_accelCommon != NULL) {
54
void AccelerometerSensorImpl::start()
56
Q_ASSERT(m_accelCommon != NULL);
57
m_accelCommon->start();
60
void AccelerometerSensorImpl::stop()
62
Q_ASSERT(m_accelCommon != NULL);
63
m_accelCommon->stop();
66
void AccelerometerSensorImpl::onAccelerometerReadingChanged()
68
Q_ASSERT(m_accelCommon != NULL);
70
const QAccelerometerReading *reading = m_accelCommon->reading();
71
Q_ASSERT(reading != NULL);
73
// Capture the coordinates from the accelerometer device
74
m_reading.setX(reading->x());
75
m_reading.setY(reading->y());
76
m_reading.setZ(reading->z());
78
newReadingAvailable();