#ifndef ROTATION_H
#define ROTATION_H

#include <QRotationFilter>
#include <QDebug>
#include <QVariant>

QTM_USE_NAMESPACE

class Signaler : public QObject
{
    Q_OBJECT
public:
    void emitSignal(qreal x, qreal y, qreal z)
    {
        emit rotationChanged(x, y, z);
    }

signals:
    void rotationChanged(QVariant x, QVariant y, QVariant z);
};


class RotationFilter : public QRotationFilter
{
protected:
    Signaler m_Signaler;

    qreal x,y,z;

public:
    RotationFilter() : x(0), y(0), z(0) {}

    bool filter(QRotationReading *reading)
    {
        // Reduce the noise in sensor readings
        x += (reading->x() - x) * 0.05;
        y += (reading->y() - y) * 0.05;
        z += (reading->z() - z) * 0.05;

        m_Signaler.emitSignal(x, y, z);
        return false; // don't store the reading in the sensor
    }

    Signaler* getSignaler() { return &m_Signaler; }
};

#endif // ROTATION_H
