[Interest] Implementing custom orientation sensor using QtSensors
Lincoln Ramsay
a1291762 at gmail.com
Thu Jan 10 03:08:57 CET 2013
On 10/01/13 07:23, Jim Hodapp wrote:
> I'm attempting to create my own orientation sensor that sits on top of a
> particular accelerometer implementation. I'd like to use my orientation
> sensor from a QML application. Given what I just stated, I'm looking for
> the recommended approach to implementing my own orientation sensor and
> using it in QML. Let me explain further with the following questions:
>
> 1. Do I want to create a new class, call it MyOrientationSensor, that
> inherits from QOrientationSensor and a paired class for the reading,
> call it MyOrientationReading? Or do I want to implement it like the
> GrueSensor example and inherit from QSensor?
Neither.
You should create a class that provides accelerometer values to
QAccelerometer (a sub-class of QSensorBackend).
Or, if there's some reason why the generic "accelerometer to
orientation" implementation does not suit your purposes, create a class
that provides orientation values to QOrientationSensor.
> 2. If taking the GrueSensor approach from #1, how do I avoid
> reimplementing the interface and implementation of the
> QOrientationSensor again?
You can't avoid this if you're going to copy the interface. So don't do
that.
> 3. Next, using my sensor within QML, if taking the GrueSensor approach,
> I know I'd then import my own QML package and instantiate my sensor by
> its unique name. But if the approach is the use the same name as the
> default orientation sensor type, i.e. "OrientationSensor", how do I make
> sure that it selects my orientation sensor as the one to use and not one
> of the sensors from dummy sensors, generic sensors, etc? Do I need to
> register another type with QML, or does it automatically get registered
> using this approach?
The grue sensor example is a "complete" example, creating both a "front
end" and a "back end". In your case, you're just creating a "back end",
which includes the plugin that registers your backend with the Qt
Sensors API.
http://llornkcor.com/qt/doc/qtsensors/creating-a-sensor-plugin.html
Your backend will always override the generic one due to some logic in
the loader. Otherwise, the default is "up to the platform" and can be
influenced in a number of ways.
http://llornkcor.com/qt/doc/qtsensors/determining-the-default-sensor-for-a-type.html
From QML, I think you can do:
OrientationSensor {
sensorid: "my.sensor"
}
Though this ties your QML to your plugin. If you want to do any kind of
detection, you need to create the object dynamically.
--
Link
More information about the Interest
mailing list