summaryrefslogtreecommitdiffstats
path: root/README.md
blob: ed5d4278adc2e2dd5a1a909be493d1505707b7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Raspberry Pi Sense HAT support module for Qt 5
==============================================

Tested on Raspbian Jessie 2015/09/24 and Qt 5.6 as described on https://wiki.qt.io/RaspberryPi2EGLFS

Sensor support is based on RTIMULib as shipped in Raspbian and https://github.com/RPi-Distro/python-sense-hat.

This a true Qt module. To build, do qmake -r && make && make install. To use, add QT += sensehat.

LED example:

    int main(int argc, char **argv)
    {
        QCoreApplication app(argc, argv);
        QSenseHatFb fb;
        fb.setLowLight(true);
        QPainter p(fb.paintDevice());
        p.fillRect(QRect(QPoint(), fb.size()), Qt::black);
        for (int i = Qt::white; i < Qt::darkYellow; ++i) {
            p.setPen(Qt::GlobalColor(i));
            p.drawEllipse(QPoint(4, 4), 3, 3);
            p.drawLine(QPoint(4, 4), QPoint(7, 7));
            sleep(1);
        }
        p.fillRect(QRect(QPoint(), fb.size()), Qt::black);
        return 0;
    }

An alternative is to run with the linuxfb platform plugin and use QRasterWindow. However,
QSenseHatFb is handy because it automatically finds the right device, supports device
specifics (low-light mode), functions (to some extent) without initializing QtGui, and
allows using any platform plugin and simultaneous HDMI output.

Sensors example:

    int main(int argc, char **argv)
    {
        QCoreApplication app(argc, argv);
        QSenseHatSensors sensors;
        sensors.setAutoPoll(true);
        QObject::connect(&sensors, &QSenseHatSensors::humidityChanged, [](qreal h) {
            qDebug() << "Humidity:" << h;
        });
        QObject::connect(&sensors, &QSenseHatSensors::pressureChanged, [](qreal p) {
            qDebug() << "Pressure:" << p;
        });
        QObject::connect(&sensors, &QSenseHatSensors::temperatureChanged, [](qreal c) {
            qDebug() << "Temperature:" << c;
        });
        QObject::connect(&sensors, &QSenseHatSensors::gyroChanged, [](const QVector3D &v) {
            qDebug() << "Gyro:" << v;
        });
        QObject::connect(&sensors, &QSenseHatSensors::accelerationChanged, [](const QVector3D &v) {
            qDebug() << "Acceleration:" << v;
        });
        QObject::connect(&sensors, &QSenseHatSensors::compassChanged, [](const QVector3D &v) {
            qDebug() << "Compass:" << v;
        });
        QObject::connect(&sensors, &QSenseHatSensors::orientationChanged, [](const QVector3D &v) {
            qDebug() << "Orientation:" << v;
        });
        QTimer::singleShot(10000, &app, &QCoreApplication::quit);
        return app.exec();
    }

Raspbian's default calibration from /etc is picked up automatically, similarly to the Python
lib. Orientation is converted to degrees in range 0..360. Other values are reported as-is.