~ubuntu-branches/ubuntu/trusty/qtubuntu-sensors/trusty

« back to all changes in this revision

Viewing changes to plugin/accelerometersensorimpl.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, thomas-voss, Christian Dywan, Ubuntu daily release
  • Date: 2014-01-08 17:17:24 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140108171724-vfvrjf6vwpxx431u
Tags: 0.6+14.04.20140108.2-0ubuntu1
[ thomas-voss ]
* Remove obsolete symbols file. Add a TODO in
  core::SharedAccelerometer for switching to an object-pool for
  allocation of sensor readings. Refactor core-based sensor backend
  implementation. Fix numerous bugs for the orientation and
  acceleration sensor. Make sure that signal-slot connections are
  queued as sensor callbacks can happen on any thread. Add a
  configuration file (place in /etc/xdg/QtProject) to select the
  ubuntu sensors by default.

[ Christian Dywan ]
* Keep vibrator around to prevent it from being recycled too fast.
  (LP: #1241735)

[ Ubuntu daily release ]
* Automatic snapshot from revision 42

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 */
16
 
 
17
 
#include "accelerometersensorimpl.h"
18
 
 
19
 
#include <QDebug>
20
 
 
21
 
char const * const AccelerometerSensorImpl::id("aal.accelerometer");
22
 
 
23
 
AccelerometerSensorImpl::AccelerometerSensorImpl(QSensor *sensor)
24
 
    : QSensorBackend(sensor)
25
 
{
26
 
    m_accelCommon = new AccelerometerCommon(this);
27
 
 
28
 
    // Register the reading instance with the parent
29
 
    setReading<QAccelerometerReading>(&m_reading);
30
 
 
31
 
    const qreal minDelay = m_accelCommon->getMinDelay();
32
 
    if (minDelay > -1)
33
 
    {
34
 
        // Min and max sensor sampling frequencies, in Hz
35
 
        addDataRate(minDelay, minDelay * 10);
36
 
    }
37
 
    addOutputRange(m_accelCommon->getMinValue(),
38
 
                   m_accelCommon->getMaxValue(),
39
 
                   m_accelCommon->getResolution());
40
 
 
41
 
    // Connect to the accelerometer's readingChanged signal
42
 
    connect(m_accelCommon, SIGNAL(accelerometerReadingChanged()), this, SLOT(onAccelerometerReadingChanged()));
43
 
 
44
 
    setDescription(QLatin1String("Accelerometer Sensor"));
45
 
}
46
 
 
47
 
AccelerometerSensorImpl::~AccelerometerSensorImpl()
48
 
{
49
 
    if (m_accelCommon != NULL) {
50
 
        delete m_accelCommon;
51
 
    }
52
 
}
53
 
 
54
 
void AccelerometerSensorImpl::start()
55
 
{
56
 
    Q_ASSERT(m_accelCommon != NULL);
57
 
    m_accelCommon->start();
58
 
}
59
 
 
60
 
void AccelerometerSensorImpl::stop()
61
 
{
62
 
    Q_ASSERT(m_accelCommon != NULL);
63
 
    m_accelCommon->stop();
64
 
}
65
 
 
66
 
void AccelerometerSensorImpl::onAccelerometerReadingChanged()
67
 
{
68
 
    Q_ASSERT(m_accelCommon != NULL);
69
 
 
70
 
    const QAccelerometerReading *reading = m_accelCommon->reading();
71
 
    Q_ASSERT(reading != NULL);
72
 
 
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());
77
 
 
78
 
    newReadingAvailable();
79
 
}