OrientationSensor.cpp Example File
orientation/src/OrientationSensor.cpp
#include <QDebug>
#include "OrientationSensor.hpp"
OrientationSensor::OrientationSensor(QObject *parent)
: QObject(parent)
, m_orientation(Undefined)
{
if (!m_sensor.connectToBackend()) {
qWarning() << "Cannot connect to orientation sensor backend!";
}
m_sensor.addFilter(this);
m_sensor.start();
}
OrientationSensor::Orientation OrientationSensor::orientation() const
{
return m_orientation;
}
bool OrientationSensor::filter(QOrientationReading *reading)
{
const Orientation oldOrientation = m_orientation;
switch (reading->orientation()) {
case QOrientationReading::Undefined:
m_orientation = Undefined;
break;
case QOrientationReading::TopUp:
m_orientation = TopUp;
break;
case QOrientationReading::TopDown:
m_orientation = TopDown;
break;
case QOrientationReading::LeftUp:
m_orientation = LeftUp;
break;
case QOrientationReading::RightUp:
m_orientation = RightUp;
break;
case QOrientationReading::FaceUp:
m_orientation = FaceUp;
break;
case QOrientationReading::FaceDown:
m_orientation = FaceDown;
break;
}
if (m_orientation != oldOrientation)
emit orientationChanged();
return false;
}