diff options
-rw-r--r-- | plugins/sensors/blackberry/bbsensorbackend.cpp | 67 | ||||
-rw-r--r-- | plugins/sensors/blackberry/bbsensorbackend.h | 2 | ||||
-rw-r--r-- | src/sensors/qsensor.cpp | 59 | ||||
-rw-r--r-- | src/sensors/qsensor.h | 20 | ||||
-rw-r--r-- | src/sensors/qsensor_p.h | 8 |
5 files changed, 122 insertions, 34 deletions
diff --git a/plugins/sensors/blackberry/bbsensorbackend.cpp b/plugins/sensors/blackberry/bbsensorbackend.cpp index 4bace8a808..ce63a8b115 100644 --- a/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -82,18 +82,19 @@ static void remapMatrix(const float inputMatrix[3*3], BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType, QSensor *sensor) : QSensorBackend(sensor), m_deviceFile(devicePath), m_sensorType(sensorType), m_guiHelper(0), - m_started(false) + m_started(false), m_applyingBufferSize(false) { m_mappingMatrix[0] = m_mappingMatrix[3] = 1; m_mappingMatrix[1] = m_mappingMatrix[2] = 0; connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty())); + connect(sensor, SIGNAL(bufferSizeChanged(int)), this, SLOT(applyBuffering())); QOrientableSensorBase * const base = dynamic_cast<QOrientableSensorBase*>(sensor); if (base) connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation())); // Set some sensible default values - sensor->setProperty("efficientBufferSize", defaultBufferSize); - sensor->setProperty("maxBufferSize", defaultBufferSize); + sensor->setEfficientBufferSize(defaultBufferSize); + sensor->setMaxBufferSize(defaultBufferSize); } BbGuiHelper *BbSensorBackendBase::guiHelper() const @@ -281,24 +282,7 @@ void BbSensorBackendBase::start() return; } - // Activate event queuing if needed - bool ok = false; - const int requestedBufferSize = sensor()->property("bufferSize").toInt(&ok); - if (ok && requestedBufferSize > 1) { - sensor_devctl_queue_u queueControl; - queueControl.tx.enable = 1; - const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL); - if (result != EOK) { - perror(QString::fromLatin1("Enabling sensor queuing for %1 failed") - .arg(m_deviceFile.fileName()).toLocal8Bit()); - } - - const int actualBufferSize = queueControl.rx.size; - sensor()->setProperty("bufferSize", actualBufferSize); - sensor()->setProperty("efficientBufferSize", actualBufferSize); - sensor()->setProperty("maxBufferSize", actualBufferSize); - } - + applyBuffering(); applyAlwaysOnProperty(); } @@ -346,6 +330,47 @@ void BbSensorBackendBase::applyAlwaysOnProperty() updatePauseState(); } +void BbSensorBackendBase::applyBuffering() +{ + if (!m_deviceFile.isOpen() || !m_started || m_applyingBufferSize) + return; + + // Flag to prevent recursion. We call setBufferSize() below, and because of the changed signal, + // we might end up in this slot again. + // The call to setBufferSize() is needed since the requested buffer size is most likely different + // from the actual buffer size that will be used. + m_applyingBufferSize = true; + + const bool enableBuffering = sensor()->bufferSize() > 1; + sensor_devctl_queue_u queueControl; + queueControl.tx.enable = enableBuffering ? 1 : 0; + const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL); + if (result != EOK) { + perror(QString::fromLatin1("Enabling sensor queuing for %1 failed") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + } else { + if (enableBuffering) { + int actualBufferSize = queueControl.rx.size; + + // Some firmware versions don't report the buffer size correctly. Simply pretend the + // buffer size is the same as the requested buffer size, as setting the buffer size to + // 1 here would seem as if buffering were disabled. + if (actualBufferSize == 1) + actualBufferSize = sensor()->bufferSize(); + + sensor()->setBufferSize(actualBufferSize); + sensor()->setEfficientBufferSize(actualBufferSize); + sensor()->setMaxBufferSize(actualBufferSize); + } else { + sensor()->setBufferSize(1); + sensor()->setEfficientBufferSize(defaultBufferSize); + sensor()->setMaxBufferSize(defaultBufferSize); + } + } + + m_applyingBufferSize = false; +} + bool BbSensorBackendBase::setPaused(bool paused) { if (!m_deviceFile.isOpen()) diff --git a/plugins/sensors/blackberry/bbsensorbackend.h b/plugins/sensors/blackberry/bbsensorbackend.h index abc50f76ae..884e39d12a 100644 --- a/plugins/sensors/blackberry/bbsensorbackend.h +++ b/plugins/sensors/blackberry/bbsensorbackend.h @@ -108,6 +108,7 @@ protected: private slots: void dataAvailable(); void applyAlwaysOnProperty(); + void applyBuffering(); bool setPaused(bool paused); void updatePauseState(); void updateOrientation(); @@ -119,6 +120,7 @@ private: BbGuiHelper *m_guiHelper; float m_mappingMatrix[4]; bool m_started; + bool m_applyingBufferSize; }; template<class SensorReading> diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 4ae9bb7ec1..fdbe9d4f61 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -796,11 +796,28 @@ int QSensor::error() const The property holds the maximum buffer size. - Note that this may be undefined, in which case the sensor does not support any form of buffering. + Note that this may be 1, in which case the sensor does not support any form of buffering. \sa QSensor::bufferSize, QSensor::efficientBufferSize */ +int QSensor::maxBufferSize() const +{ + return d->maxBufferSize; +} + +/*! + Sets the maximum buffer size to \a maxBufferSize. This is to be called from the + backend. +*/ +void QSensor::setMaxBufferSize(int maxBufferSize) +{ + if (d->maxBufferSize != maxBufferSize) { + d->maxBufferSize = maxBufferSize; + emit maxBufferSizeChanged(maxBufferSize); + } +} + /*! \property QSensor::efficientBufferSize @@ -808,17 +825,32 @@ int QSensor::error() const no particular size is most efficient). Some sensor drivers have a FIFO buffer which makes it more efficient to deliver the FIFO's size worth of readings at one time. - Note that this may be undefined, in which case the sensor does not support any form of buffering. - \sa QSensor::bufferSize, QSensor::maxBufferSize */ +int QSensor::efficientBufferSize() const +{ + return d->efficientBufferSize; +} + +/*! + Sets the efficient buffer size to \a efficientBufferSize. This is to be called from the + backend. +*/ +void QSensor::setEfficientBufferSize(int efficientBufferSize) +{ + if (d->efficientBufferSize != efficientBufferSize) { + d->efficientBufferSize = efficientBufferSize; + emit efficientBufferSizeChanged(efficientBufferSize); + } +} + /*! \property QSensor::bufferSize - This property holds the size of the buffer. By default (and if the property - is left undefined), the buffer size is 1, which means no buffering. - If the maximum buffer size is 1 (or undefined), then buffering is not supported + This property holds the size of the buffer. By default, the buffer size is 1, + which means no buffering. + If the maximum buffer size is 1, then buffering is not supported by the sensor. Setting bufferSize greater than maxBufferSize will cause maxBufferSize to be used. @@ -845,11 +877,22 @@ int QSensor::error() const in time, for example when the event loop is blocked for too long. Without a buffer, these readings would simply be dropped. - The buffer size can only be changed while the sensor is not active. - \sa QSensor::maxBufferSize, QSensor::efficientBufferSize */ +int QSensor::bufferSize() const +{ + return d->bufferSize; +} + +void QSensor::setBufferSize(int bufferSize) +{ + if (d->bufferSize != bufferSize) { + d->bufferSize = bufferSize; + emit bufferSizeChanged(bufferSize); + } +} + // ===================================================================== /*! diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 1a221c55d9..8b4fe0b413 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -100,11 +100,9 @@ class Q_SENSORS_EXPORT QSensor : public QObject 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) -#ifdef Q_QDOC - Q_PROPERTY(int maxBufferSize) - Q_PROPERTY(int efficientBufferSize) - Q_PROPERTY(int bufferSize) -#endif + 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: explicit QSensor(const QByteArray &type, QObject *parent = 0); virtual ~QSensor(); @@ -153,6 +151,15 @@ public: static QList<QByteArray> sensorsForType(const QByteArray &type); static QByteArray defaultSensorForType(const QByteArray &type); + int maxBufferSize() const; + void setMaxBufferSize(int maxBufferSize); + + int efficientBufferSize() const; + void setEfficientBufferSize(int efficientBufferSize); + + int bufferSize() const; + void setBufferSize(int bufferSize); + public Q_SLOTS: // Start receiving values from the sensor bool start(); @@ -169,6 +176,9 @@ Q_SIGNALS: void alwaysOnChanged(); void skipDuplicatesChanged(bool skipDuplicates); void dataRateChanged(); + void maxBufferSizeChanged(int maxBufferSize); + void efficientBufferSizeChanged(int efficientBufferSize); + void bufferSizeChanged(int bufferSize); protected: QSensor(const QByteArray &type, QSensorPrivate *dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 650612c15d..ca8dc0a4a8 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -76,6 +76,9 @@ public: , error(0) , alwaysOn(false) , skipDuplicates(false) + , bufferSize(1) + , maxBufferSize(1) + , efficientBufferSize(1) , q(sensor) { } @@ -107,6 +110,11 @@ public: bool alwaysOn; bool skipDuplicates; + + int bufferSize; + int maxBufferSize; + int efficientBufferSize; + QSensor *q; }; |