45 #include <qmobilityglobal.h> |
45 #include <qmobilityglobal.h> |
46 #include <QObject> |
46 #include <QObject> |
47 #include <QByteArray> |
47 #include <QByteArray> |
48 #include <QMetaType> |
48 #include <QMetaType> |
49 #include <QVariant> |
49 #include <QVariant> |
|
50 #include <QPair> |
50 |
51 |
51 QTM_BEGIN_NAMESPACE |
52 QTM_BEGIN_NAMESPACE |
52 |
53 |
53 class QSensorPrivate; |
54 class QSensorPrivate; |
54 class QSensorBackend; |
55 class QSensorBackend; |
55 class QSensorReading; |
56 class QSensorReading; |
56 class QSensorReadingPrivate; |
57 class QSensorReadingPrivate; |
57 class QSensorFilter; |
58 class QSensorFilter; |
58 |
59 |
|
60 #ifdef Q_QDOC |
59 typedef quint64 qtimestamp; |
61 typedef quint64 qtimestamp; |
|
62 #else |
|
63 class qtimestamp |
|
64 { |
|
65 public: |
|
66 qtimestamp() : value() {} |
|
67 qtimestamp(quint64 timestamp) : value(timestamp) {} |
|
68 operator quint64() const { return value; } |
|
69 private: |
|
70 quint64 value; |
|
71 }; |
|
72 #endif |
|
73 |
|
74 typedef QPair<int,int> qrange; |
|
75 typedef QList<qrange> qrangelist; |
|
76 struct qoutputrange |
|
77 { |
|
78 qreal minimum; |
|
79 qreal maximum; |
|
80 qreal accuracy; |
|
81 }; |
|
82 typedef QList<qoutputrange> qoutputrangelist; |
60 |
83 |
61 class Q_SENSORS_EXPORT QSensor : public QObject |
84 class Q_SENSORS_EXPORT QSensor : public QObject |
62 { |
85 { |
63 friend class QSensorBackend; |
86 friend class QSensorBackend; |
64 |
87 |
65 Q_OBJECT |
88 Q_OBJECT |
66 Q_ENUMS(UpdatePolicy) |
|
67 Q_FLAGS(UpdatePolicies) |
|
68 Q_PROPERTY(QByteArray sensorid READ identifier WRITE setIdentifier) |
89 Q_PROPERTY(QByteArray sensorid READ identifier WRITE setIdentifier) |
69 Q_PROPERTY(QByteArray type READ type WRITE setType) |
90 Q_PROPERTY(QByteArray type READ type) |
70 Q_PROPERTY(bool connected READ isConnected) |
91 Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend) |
71 Q_PROPERTY(UpdatePolicies supportedUpdatePolicies READ supportedUpdatePolicies) |
92 Q_PROPERTY(QtMobility::qrangelist availableDataRates READ availableDataRates) |
72 Q_PROPERTY(UpdatePolicy updatePolicy READ updatePolicy WRITE setUpdatePolicy) |
93 Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate) |
73 Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval) |
|
74 Q_PROPERTY(QSensorReading* reading READ reading NOTIFY readingChanged) |
94 Q_PROPERTY(QSensorReading* reading READ reading NOTIFY readingChanged) |
75 Q_PROPERTY(bool running READ isActive WRITE setActive) |
95 Q_PROPERTY(bool busy READ isBusy) |
76 public: |
96 Q_PROPERTY(bool active READ isActive) |
77 explicit QSensor(QObject *parent = 0); |
97 Q_PROPERTY(QtMobility::qoutputrangelist outputRanges READ outputRanges) |
|
98 Q_PROPERTY(int outputRange READ outputRange WRITE setOutputRange) |
|
99 Q_PROPERTY(QString description READ description) |
|
100 Q_PROPERTY(int error READ error NOTIFY sensorError) |
|
101 public: |
|
102 explicit QSensor(const QByteArray &type, QObject *parent = 0); |
78 virtual ~QSensor(); |
103 virtual ~QSensor(); |
79 |
104 |
80 QByteArray identifier() const; |
105 QByteArray identifier() const; |
81 void setIdentifier(const QByteArray &identifier); |
106 void setIdentifier(const QByteArray &identifier); |
82 |
107 |
83 QByteArray type() const; |
108 QByteArray type() const; |
84 void setType(const QByteArray &type); |
109 |
85 |
110 Q_INVOKABLE bool connectToBackend(); |
86 Q_INVOKABLE bool connect(); |
111 bool isConnectedToBackend() const; |
87 bool isConnected() const; |
112 |
88 |
113 bool isBusy() const; |
89 bool isActive() const; |
114 bool isActive() const; |
90 void setActive(bool running); |
115 |
91 |
116 qrangelist availableDataRates() const; |
92 bool isSignalEnabled() const; |
117 int dataRate() const; |
93 void setSignalEnabled(bool enabled); |
118 void setDataRate(int rate); |
94 |
119 |
95 enum UpdatePolicy { |
120 qoutputrangelist outputRanges() const; |
96 Undefined = 0x00, // If the sensor has no specific policy |
121 int outputRange() const; |
97 |
122 void setOutputRange(int index); |
98 // Used by irregularly updating sensors |
123 |
99 OnChangeUpdates = 0x01, |
124 QString description() const; |
100 |
125 int error() const; |
101 // Used by continuously updating sensors |
|
102 OccasionalUpdates = 0x02, |
|
103 InfrequentUpdates = 0x04, |
|
104 FrequentUpdates = 0x08, |
|
105 |
|
106 // For more control |
|
107 TimedUpdates = 0x10, // Every x milliseconds (may not be supported by all sensors) |
|
108 PolledUpdates = 0x20 // As often as polled (may not be supported by all sensors) |
|
109 }; |
|
110 Q_DECLARE_FLAGS(UpdatePolicies, UpdatePolicy) |
|
111 |
|
112 // What policies does the sensor support |
|
113 UpdatePolicies supportedUpdatePolicies() const; |
|
114 |
|
115 // Set the desired update policy (default is defined by the sensor) |
|
116 // Use documentation to determine the policies that the sensor |
|
117 // supports. |
|
118 void setUpdatePolicy(UpdatePolicy policy); |
|
119 void setUpdateInterval(int interval); |
|
120 |
|
121 // Retrieve the policy |
|
122 UpdatePolicy updatePolicy() const; |
|
123 int updateInterval() const; |
|
124 |
126 |
125 // Filters modify the reading |
127 // Filters modify the reading |
126 void addFilter(QSensorFilter *filter); |
128 void addFilter(QSensorFilter *filter); |
127 void removeFilter(QSensorFilter *filter); |
129 void removeFilter(QSensorFilter *filter); |
128 |
130 |
129 // Poll for sensor change (only if using PolledUpdates) |
|
130 void poll(); |
|
131 |
|
132 // The readings are exposed via this object |
131 // The readings are exposed via this object |
133 QSensorReading *reading() const; |
132 QSensorReading *reading() const; |
134 |
133 |
135 // Information about available sensors |
134 // Information about available sensors |
|
135 // These functions are implemented in qsensormanager.cpp |
136 static QList<QByteArray> sensorTypes(); |
136 static QList<QByteArray> sensorTypes(); |
137 static QList<QByteArray> sensorsForType(const QByteArray &type); |
137 static QList<QByteArray> sensorsForType(const QByteArray &type); |
138 static QByteArray defaultSensorForType(const QByteArray &type); |
138 static QByteArray defaultSensorForType(const QByteArray &type); |
139 |
139 |
140 public Q_SLOTS: |
140 public Q_SLOTS: |
141 // Start receiving values from the sensor |
141 // Start receiving values from the sensor |
142 void start(); |
142 bool start(); |
143 |
143 |
144 // Stop receiving values from the sensor |
144 // Stop receiving values from the sensor |
145 void stop(); |
145 void stop(); |
146 |
146 |
147 Q_SIGNALS: |
147 Q_SIGNALS: |
|
148 void busyChanged(); |
148 void readingChanged(); |
149 void readingChanged(); |
|
150 void sensorError(int error); |
149 |
151 |
150 protected: |
152 protected: |
151 // called by the back end |
153 // called by the back end |
152 QSensorPrivate *d_func() const { return d.data(); } |
154 QSensorPrivate *d_func() const { return d.data(); } |
153 |
155 |
154 private: |
156 private: |
155 QScopedPointer<QSensorPrivate> d; |
157 QScopedPointer<QSensorPrivate> d; |
156 Q_DISABLE_COPY(QSensor) |
158 Q_DISABLE_COPY(QSensor) |
157 }; |
159 }; |
158 |
|
159 Q_DECLARE_OPERATORS_FOR_FLAGS(QSensor::UpdatePolicies) |
|
160 |
160 |
161 class Q_SENSORS_EXPORT QSensorFilter |
161 class Q_SENSORS_EXPORT QSensorFilter |
162 { |
162 { |
163 friend class QSensor; |
163 friend class QSensor; |
164 public: |
164 public: |