2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <qmcompass.h>
25 Compass::Compass(QObject *parent) :
27 m_compass(new MeeGo::QmCompass(this)),
31 m_compass->setUseDeclination(true);
33 QObject::connect(m_compass, SIGNAL(dataAvailable(const MeeGo::QmCompassReading&)),
34 this, SLOT(dataAvailable(const MeeGo::QmCompassReading&)));
36 if (m_compass->requestSession(MeeGo::QmSensor::SessionTypeListen)
37 == MeeGo::QmSensor::SessionTypeNone) {
38 qDebug() << "Failed to get listen session:" << m_compass->lastError();
46 bool Compass::isActive() const {
47 return m_compass->isRunning();
50 void Compass::setActive(bool active) {
51 if (active == isActive()) {
62 emit directionValidChanged();
68 int Compass::direction() const {
72 bool Compass::isDirectionValid() const {
76 void Compass::dataAvailable(const MeeGo::QmCompassReading& value) {
77 bool degreeChanged = (m_degree != value.degrees);
78 bool validityChanged = m_valid != (value.level >= 2);
80 m_degree = value.degrees;
81 m_valid = (value.level >= 2);
83 if (validityChanged) {
84 emit directionValidChanged();
88 emit directionChanged();