QtMobility compass cannot be used because we need to switch on the declination correction
--- /dev/null
+#include "compass.h"
+#include <qmcompass.h>
+#include <QDebug>
+
+Compass::Compass(QObject *parent) :
+ QObject(parent),
+ m_compass(new MeeGo::QmCompass(this)),
+ m_degree(-1),
+ m_valid(false) {
+
+ m_compass->setUseDeclination(true);
+
+ QObject::connect(m_compass, SIGNAL(dataAvailable(const MeeGo::QmCompassReading&)),
+ this, SLOT(dataAvailable(const MeeGo::QmCompassReading&)));
+
+ if (m_compass->requestSession(MeeGo::QmSensor::SessionTypeListen)
+ == MeeGo::QmSensor::SessionTypeNone) {
+ qDebug() << "Failed to get listen session:" << m_compass->lastError();
+ }
+}
+
+Compass::~Compass() {
+ m_compass->stop();
+}
+
+bool Compass::isActive() const {
+ return m_compass->isRunning();
+}
+
+void Compass::setActive(bool active) {
+ if (active == isActive()) {
+ return;
+ }
+
+ if (active) {
+ m_compass->start();
+ }
+ else {
+ m_compass->stop();
+
+ m_valid = false;
+ emit directionValidChanged();
+ }
+
+ emit activeChanged();
+}
+
+int Compass::direction() const {
+ return m_degree;
+}
+
+bool Compass::isDirectionValid() const {
+ return m_valid;
+}
+
+void Compass::dataAvailable(const MeeGo::QmCompassReading& value) {
+ bool degreeChanged = (m_degree != value.degrees);
+ bool validityChanged = m_valid != (value.level >= 2);
+
+ m_degree = value.degrees;
+ m_valid = (value.level >= 2);
+
+ if (validityChanged) {
+ emit directionValidChanged();
+ }
+
+ if (degreeChanged) {
+ emit directionChanged();
+ }
+}
--- /dev/null
+// -*- c++ -*-
+
+#ifndef COMPASS_H
+#define COMPASS_H
+
+#include <QObject>
+
+namespace MeeGo {
+ class QmCompass;
+ class QmCompassReading;
+};
+
+class Compass : public QObject {
+ Q_OBJECT
+
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+ Q_PROPERTY(int direction READ direction NOTIFY directionChanged);
+ Q_PROPERTY(bool directionValid READ isDirectionValid NOTIFY directionValidChanged);
+
+public:
+ Compass(QObject *parent = 0);
+ ~Compass();
+
+ bool isActive() const;
+ void setActive(bool active);
+
+ int direction() const;
+ bool isDirectionValid() const;
+
+signals:
+ void activeChanged();
+ void directionChanged();
+ void directionValidChanged();
+
+private slots:
+ void dataAvailable(const MeeGo::QmCompassReading& value);
+
+private:
+ MeeGo::QmCompass *m_compass;
+ int m_degree;
+ bool m_valid;
+};
+
+#endif /* COMPASS_H */
#include "displaystate.h"
#include "fsmonitor.h"
#include "cameraresources.h"
+#include "compass.h"
+#include "orientation.h"
Q_DECL_EXPORT int main(int argc, char *argv[]) {
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
qmlRegisterType<DisplayState>("CameraPlus", 1, 0, "DisplayState");
qmlRegisterType<FSMonitor>("CameraPlus", 1, 0, "FSMonitor");
qmlRegisterType<CameraResources>("CameraPlus", 1, 0, "CameraResources");
+ qmlRegisterType<Compass>("CameraPlus", 1, 0, "Compass");
+ qmlRegisterType<Orientation>("CameraPlus", 1, 0, "Orientation");
QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
view.setSource(sourceUrl);
--- /dev/null
+#include "orientation.h"
+#include <qmorientation.h>
+#include <QDebug>
+
+Orientation::Orientation(QObject *parent) :
+ QObject(parent),
+ m_orientation(new MeeGo::QmOrientation(this)),
+ m_direction(Unknown) {
+
+ QObject::connect(m_orientation, SIGNAL(orientationChanged(const MeeGo::QmOrientationReading&)),
+ this, SLOT(orientationChanged(const MeeGo::QmOrientationReading&)));
+
+ if (m_orientation->requestSession(MeeGo::QmSensor::SessionTypeListen)
+ == MeeGo::QmSensor::SessionTypeNone) {
+ qDebug() << "Failed to get listen session:" << m_orientation->lastError();
+ }
+}
+
+Orientation::~Orientation() {
+ m_orientation->stop();
+}
+
+bool Orientation::isActive() const {
+ return m_orientation->isRunning();
+}
+
+void Orientation::setActive(bool active) {
+ if (active == isActive()) {
+ return;
+ }
+
+ if (active) {
+ m_orientation->start();
+ orientationChanged(m_orientation->orientation());
+ }
+ else {
+ m_orientation->stop();
+ m_direction = Unknown;
+
+ emit orientationChanged();
+ }
+
+ emit activeChanged();
+}
+
+Orientation::OrientationDirection Orientation::orientation() const {
+ return m_direction;
+}
+
+void Orientation::orientationChanged(const MeeGo::QmOrientationReading& value) {
+ OrientationDirection direction = Unknown;
+
+ switch (value.value) {
+ case MeeGo::QmOrientation::BottomUp:
+ direction = InvertedLandscape;
+ break;
+
+ case MeeGo::QmOrientation::BottomDown:
+ direction = Landscape;
+ break;
+
+ case MeeGo::QmOrientation::LeftUp:
+ direction = Portrait;
+ break;
+
+ case MeeGo::QmOrientation::RightUp:
+ direction = InvertedPortrait;
+ break;
+
+ default:
+ direction = Unknown;
+ break;
+ }
+
+ if (direction != m_direction) {
+ m_direction = direction;
+ emit orientationChanged();
+ }
+}
--- /dev/null
+// -*- c++ -*-
+
+#ifndef ORIENTATION_H
+#define ORIENTATION_H
+
+#include <QObject>
+
+namespace MeeGo {
+ class QmOrientation;
+ class QmOrientationReading;
+};
+
+class Orientation : public QObject {
+ Q_OBJECT
+
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+ Q_PROPERTY(OrientationDirection orientation READ orientation NOTIFY orientationChanged);
+
+ Q_ENUMS(OrientationDirection);
+
+public:
+ Orientation(QObject *parent = 0);
+ ~Orientation();
+
+ // Make sure they are synced with metadata.
+ typedef enum {
+ Unknown = -1,
+ Landscape = 0,
+ Portrait = 1,
+ InvertedLandscape = 2,
+ InvertedPortrait = 3
+ } OrientationDirection;
+
+ bool isActive() const;
+ void setActive(bool active);
+
+ OrientationDirection orientation() const;
+
+signals:
+ void activeChanged();
+ void orientationChanged();
+
+private slots:
+ void orientationChanged(const MeeGo::QmOrientationReading& value);
+
+private:
+ MeeGo::QmOrientation *m_orientation;
+ OrientationDirection m_direction;
+};
+
+#endif /* ORIENTATION_H */
LIBS += -L../imports/ -limports -L../lib/ -lqtcamera
SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
- cameraresources.cpp
+ cameraresources.cpp compass.cpp orientation.cpp
HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
- cameraresources.h
+ cameraresources.h compass.h orientation.h