123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- #ifndef QSENSOR_H
- #define QSENSOR_H
- #include <QtSensors/qsensorsglobal.h>
- #include <QtCore/QObject>
- #include <QtCore/QByteArray>
- #include <QtCore/QMetaType>
- #include <QtCore/QVariant>
- #include <QtCore/QPair>
- QT_BEGIN_NAMESPACE
- class QSensorPrivate;
- class QSensorBackend;
- class QSensorReading;
- class QSensorReadingPrivate;
- class QSensorFilter;
- typedef quint64 qtimestamp;
- typedef QPair<int,int> qrange;
- typedef QList<qrange> qrangelist;
- struct qoutputrange
- {
- qreal minimum;
- qreal maximum;
- qreal accuracy;
- };
- typedef QList<qoutputrange> qoutputrangelist;
- class Q_SENSORS_EXPORT QSensor : public QObject
- {
- friend class QSensorBackend;
- Q_OBJECT
- Q_ENUMS(Feature)
- Q_ENUMS(AxesOrientationMode)
- Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier)
- Q_PROPERTY(QByteArray type READ type)
- Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend)
- Q_PROPERTY(qrangelist availableDataRates READ availableDataRates)
- Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate NOTIFY dataRateChanged)
- Q_PROPERTY(QSensorReading* reading READ reading NOTIFY readingChanged)
- Q_PROPERTY(bool busy READ isBusy)
- Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
- Q_PROPERTY(qoutputrangelist outputRanges READ outputRanges)
- Q_PROPERTY(int outputRange READ outputRange WRITE setOutputRange)
- Q_PROPERTY(QString description READ description)
- Q_PROPERTY(int error READ error NOTIFY sensorError)
- Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged)
- Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged)
- Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged)
- Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged)
- Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged)
- Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged)
- Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged)
- Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged)
- public:
- enum Feature {
- Buffering,
- AlwaysOn,
- GeoValues,
- FieldOfView,
- AccelerationMode,
- SkipDuplicates,
- AxesOrientation,
- PressureSensorTemperature,
- Reserved = 257
- };
-
- enum AxesOrientationMode {
- FixedOrientation,
- AutomaticOrientation,
- UserOrientation
- };
- explicit QSensor(const QByteArray &type, QObject *parent = Q_NULLPTR);
- virtual ~QSensor();
- QByteArray identifier() const;
- void setIdentifier(const QByteArray &identifier);
- QByteArray type() const;
- Q_INVOKABLE bool connectToBackend();
- bool isConnectedToBackend() const;
- bool isBusy() const;
- void setActive(bool active);
- bool isActive() const;
- bool isAlwaysOn() const;
- void setAlwaysOn(bool alwaysOn);
- bool skipDuplicates() const;
- void setSkipDuplicates(bool skipDuplicates);
- qrangelist availableDataRates() const;
- int dataRate() const;
- void setDataRate(int rate);
- qoutputrangelist outputRanges() const;
- int outputRange() const;
- void setOutputRange(int index);
- QString description() const;
- int error() const;
-
- void addFilter(QSensorFilter *filter);
- void removeFilter(QSensorFilter *filter);
- QList<QSensorFilter*> filters() const;
-
- QSensorReading *reading() const;
-
-
- static QList<QByteArray> sensorTypes();
- static QList<QByteArray> sensorsForType(const QByteArray &type);
- static QByteArray defaultSensorForType(const QByteArray &type);
- Q_INVOKABLE bool isFeatureSupported(Feature feature) const;
- AxesOrientationMode axesOrientationMode() const;
- void setAxesOrientationMode(AxesOrientationMode axesOrientationMode);
- int currentOrientation() const;
- void setCurrentOrientation(int currentOrientation);
- int userOrientation() const;
- void setUserOrientation(int userOrientation);
- int maxBufferSize() const;
- void setMaxBufferSize(int maxBufferSize);
- int efficientBufferSize() const;
- void setEfficientBufferSize(int efficientBufferSize);
- int bufferSize() const;
- void setBufferSize(int bufferSize);
- public Q_SLOTS:
-
- bool start();
-
- void stop();
- Q_SIGNALS:
- void busyChanged();
- void activeChanged();
- void readingChanged();
- void sensorError(int error);
- void availableSensorsChanged();
- void alwaysOnChanged();
- void dataRateChanged();
- void skipDuplicatesChanged(bool skipDuplicates);
- void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode);
- void currentOrientationChanged(int currentOrientation);
- void userOrientationChanged(int userOrientation);
- void maxBufferSizeChanged(int maxBufferSize);
- void efficientBufferSizeChanged(int efficientBufferSize);
- void bufferSizeChanged(int bufferSize);
- protected:
- explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = Q_NULLPTR);
- QSensorBackend *backend() const;
- private:
- void registerInstance();
- Q_DISABLE_COPY(QSensor)
- Q_DECLARE_PRIVATE(QSensor)
- };
- class Q_SENSORS_EXPORT QSensorFilter
- {
- friend class QSensor;
- public:
- virtual bool filter(QSensorReading *reading) = 0;
- protected:
- QSensorFilter();
- virtual ~QSensorFilter();
- virtual void setSensor(QSensor *sensor);
- QSensor *m_sensor;
- };
- class Q_SENSORS_EXPORT QSensorReading : public QObject
- {
- friend class QSensorBackend;
- Q_OBJECT
- Q_PROPERTY(quint64 timestamp READ timestamp)
- public:
- virtual ~QSensorReading();
- quint64 timestamp() const;
- void setTimestamp(quint64 timestamp);
-
-
- int valueCount() const;
- QVariant value(int index) const;
- protected:
- explicit QSensorReading(QObject *parent, QSensorReadingPrivate *d);
- QScopedPointer<QSensorReadingPrivate> *d_ptr() { return &d; }
- virtual void copyValuesFrom(QSensorReading *other);
- private:
- QScopedPointer<QSensorReadingPrivate> d;
- Q_DISABLE_COPY(QSensorReading)
- };
- #define DECLARE_READING(classname)\
- DECLARE_READING_D(classname, classname ## Private)
- #define DECLARE_READING_D(classname, pclassname)\
- public:\
- classname(QObject *parent = Q_NULLPTR);\
- virtual ~classname();\
- void copyValuesFrom(QSensorReading *other);\
- private:\
- QScopedPointer<pclassname> d;
- #define IMPLEMENT_READING(classname)\
- IMPLEMENT_READING_D(classname, classname ## Private)
- #define IMPLEMENT_READING_D(classname, pclassname)\
- classname::classname(QObject *parent)\
- : QSensorReading(parent, Q_NULLPTR)\
- , d(new pclassname)\
- {}\
- classname::~classname() {}\
- void classname::copyValuesFrom(QSensorReading *_other)\
- {\
- \
- classname *other = static_cast<classname *>(_other);\
- pclassname *my_ptr = d.data();\
- pclassname *other_ptr = other->d.data();\
- \
- *(my_ptr) = *(other_ptr);\
- \
- QSensorReading::copyValuesFrom(_other);\
- }
- QT_END_NAMESPACE
- Q_DECLARE_METATYPE(qrange)
- Q_DECLARE_METATYPE(qrangelist)
- Q_DECLARE_METATYPE(qoutputrangelist)
- #endif
|