src/SpacenavReceiver.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Mar 2019 18:33:22 +0100
branchv_0
changeset 9 d3716f03efcd
parent 6 49560660d230
child 11 aaa89fe98b63
permissions -rw-r--r--
display status – connection type (domain socket or X11)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Spacenav Demo Qt
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <QObject>
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <QThread>
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    23
#include "SpacenavWrapper.h"
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    24
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    25
Q_DECLARE_METATYPE(SpacenavWrapper::Event::MotionEvent)
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    26
Q_DECLARE_METATYPE(SpacenavWrapper::Event::ButtonEvent)
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    27
Q_DECLARE_METATYPE(SpacenavWrapper::ConnectionStatus)
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
class SpacenavReceiver : public QThread {
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    30
	Q_OBJECT
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    31
private:
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    32
	SpacenavWrapper spnav;
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
public:
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	SpacenavReceiver() : QThread() {
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	}
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	void run() {
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    40
		emit spacenavConnectionStatus(spnav.getConnectionStatus());
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    41
		while (true) {
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    42
			SpacenavWrapper::Event e = spnav.waitEvent();
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    43
			if (e.type == SpacenavWrapper::Event::Type::MOTION) emit spacenavMotionEvent(e.motion);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    44
			if (e.type == SpacenavWrapper::Event::Type::BUTTON) emit spacenavButtonEvent(e.button);
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		}
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	}
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
signals:
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    49
	void spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    50
	void spacenavButtonEvent(SpacenavWrapper::Event::ButtonEvent e);
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    51
	void spacenavConnectionStatus(SpacenavWrapper::ConnectionStatus s);
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
};