3

I can't make sensors works on my Asus Transformer T100.

Magnetometer and Compass don't start, and I have fake value from the accelerometer (always x=0, y=9.8, z=0).

I always get the same result, even with my laptop :

first textEdit:

Initialisation...
QAccelerometer is connected to backend...
QAccelerometer isActive...
Attente des données capteur...

Second textEdit:

ven. juin 6 14:56:41 2014
Acceleration:  x = 0
y = 9.8
z = 0

Compass: UNAVAILABLE
QMagnetometer: UNAVAILABLE

And this code :

QList<QByteArray> sensorList = QSensor::sensorTypes();
ui->init->append("Sensor list length: " + QString::number(sensorList.size()).toUtf8());
foreach( QByteArray sensorName, sensorList ) {
    ui->init->append("Sensor: " + sensorName);
}

Give me :

Sensor: QAmbientLightSensor
Sensor: QAccelerometer
Sensor: QTiltSensor
Sensor: QOrientationSensor
Sensor: QRotationSensor

Where is QCompass ? QMagnetometer ? Why QAccelerometer is faked ? :'(

Here is my simplified test-code, only with QCompass :

header:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QCompass>
#include <QCompassReading>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void update();
    void error(int);

private:
    Ui::MainWindow *ui;

    QCompass *compass;
    QCompassReading *compass_reading;
};

#endif // MAINWINDOW_H

code :

#include <QDateTime>
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->init->setText("Initialisation...");

    compass = new QCompass(this);
    connect(compass, SIGNAL(readingChanged()), this, SLOT(update()));
    connect(compass, SIGNAL(sensorError(int)), this, SLOT(error(int)));
    compass->setDataRate(1);
    compass->start();
    if (compass->isBusy()) {
        ui->init->append("QCompass is busy...");
    }
    if(compass->isConnectedToBackend()) {
        ui->init->append("QCompass is connected to backend...");
    }
    if(compass->isActive()) {
        ui->init->append("QCompass isActive...");
    }

    ui->init->append("Waiting for sensors...");
}

MainWindow::~MainWindow()
{
    delete compass;
    delete ui;
}

void MainWindow::update()
{
    QString text_compass;

    ui->textEdit->clear();

    accel_reading = accel->reading();

    compass_reading = compass->reading();
    if(compass_reading != 0) {
        text_compass = QDateTime::currentDateTime().toString() +
                + "\nCompass:  azimuth = " + QString::number(compass_reading->azimuth());
                + "\ncalibration level = " + QString::number(compass_reading->calibrationLevel());

        ui->textEdit->append(text_compass);
    }
    else {
        text_compass = "\nCompass: UNAVAILABLE";
        ui->textEdit->append(text_compass);
    }
}


void MainWindow::error(int erreur) {
    QMessageBox::critical(this, "Erreur", "Erreur num : " + QString::number(erreur).toUtf8());
}
svalsesia
  • 303
  • 2
  • 13
  • Nobody try to use the sensors on a Windows tablet ? Do I have to download the source of Qt and debug to see why I don't see the QCompass sensor ?? – svalsesia Jun 11 '14 at 08:00

1 Answers1

2

The solution for now is to hack the winrt sensors plugin and rebuild it. (the sensors backend for winrt works for windows 7/8 desktop application).

First git clone the plugin, or get Qt's source code.

then open src/plugins/sensors/sensors.pro and add these lines :

win32-msvc2012|win32-msvc2013 {
    isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic dummy
}

winrt|win32-msvc2012|win32-msvc2013 {
    isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt
} 

REMOVE this line :

isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt 

Then open src/plugins/sensors/winrt/winrt.pro and add this lines :

win32-msvc2012|win32-msvc2013: LIBS += -lruntimeobject

And finally run qmake, make/nmake, make/nmake install (Ask google for more informations about how to build)

IMPORTANT : the run process should start from the directory where the qtsensors.pro file is (e. g. C:\Qt\5.4\Src\qtsensors).

To get more informations, and follow :

Jean-Philippe Jodoin
  • 4,536
  • 1
  • 25
  • 28
svalsesia
  • 303
  • 2
  • 13
  • Wow, thanks! Your solution worked for me and I am now able to access the QSensors from my Surface Pro 3 (Concrete these ones: `"QAccelerometer", "QOrientationSensor", "QTiltSensor", "QCompass", "QAmbientLightSensor", "QGyroscope", "QRotationSensor"`). I really wonder why this fix hasn't come into a stable qt release yet. And just a small hint on your solution (this may be obvious to some ;-): the run process should start from the directory where the `qtsensors.pro` file is (e. g. `C:\Qt\5.4\Src\qtsensors`). – Milania Jan 19 '15 at 19:58
  • I don't know, maybe nobody use sensors in win7/8 desktop applications :( Thanks for the hint, I edited my answer :) – svalsesia Feb 04 '15 at 15:13
  • I added comments (Qt bug/patch) and try to get more informations why this patch isn't integrate... – svalsesia Feb 04 '15 at 15:27
  • It works. Quick precision, you must make sure the qtsensors_winrt.dll or qtsensorsd_winrtd.dll are loaded instead of the qtsensors_dummy.dll or else you will still have the same problem. – Jean-Philippe Jodoin Feb 11 '15 at 17:44