[Interest] Implementing custom orientation sensor using QtSensors

Jim Hodapp james.hodapp at gmail.com
Thu Jan 10 15:09:29 CET 2013


Thanks for your reply Lincoln, see my comments below:

On 01/09/2013 09:08 PM, Lincoln Ramsay wrote:
> 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.

I think what is missing from the QtSensors examples are more QML 
examples that show simple uses of the sensor backends like the Linux 
accelerometer or the dummy sensors. Straight and to-the-point examples 
that clearly show the basics of how the interface is supposed to work.

>
>> 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"
> }

Thanks, as it turns out this wasn't even necessary. Just making sure 
that my backend is registered ensured that my OrientationSensor was the 
one that was used from my QML application.

>
> Though this ties your QML to your plugin. If you want to do any kind of
> detection, you need to create the object dynamically.
>




More information about the Interest mailing list