v2.0.0
Loading...
Searching...
No Matches
polhemus_connection.h
Go to the documentation of this file.
1//=============================================================================================================
29
30#ifndef UTILS_POLHEMUS_CONNECTION_H
31#define UTILS_POLHEMUS_CONNECTION_H
32
33//=============================================================================================================
34// INCLUDES
35//=============================================================================================================
36
37#include "../utils_global.h"
38#include "fastrak_parser.h"
39
40//=============================================================================================================
41// QT INCLUDES
42//=============================================================================================================
43
44#include <QObject>
45#include <QQuaternion>
46#include <QSerialPort>
47#include <QSerialPortInfo>
48#include <QString>
49#include <QStringList>
50#include <QTimer>
51#include <QVector3D>
52
53//=============================================================================================================
54// DEFINE NAMESPACE UTILSLIB
55//=============================================================================================================
56
57namespace UTILSLIB
58{
59
60//=============================================================================================================
65{
66 int baudRate = 115200;
73 QVector3D hemisphere = QVector3D(0, 0, 0);
77 QByteArray streamCommand = QByteArrayLiteral("C\r");
78};
79
80//=============================================================================================================
85{
86 Q_OBJECT
87
88public:
89 explicit PolhemusConnection(QObject* parent = nullptr);
90 ~PolhemusConnection() override;
91
99 bool open(const QString& portName,
101
103 void close();
104
105 bool isConnected() const;
106 QString backendName() const;
107
108 //=========================================================================================================
117 static QStringList availablePorts();
118
119 //=========================================================================================================
129 static QString autoDetectPortName();
130
131signals:
137 void pointReceived(int station, const QVector3D& position, const QQuaternion& orientation);
138
141
143 void errorOccurred(const QString& message);
144
153 void penButtonPressed(int station, const QVector3D& position, const QQuaternion& orientation);
154
155private slots:
156 void onMockTick();
157 void onSerialReadyRead();
158 void onSerialError(QSerialPort::SerialPortError err);
159 void onStreamPauseTimeout();
160
161private:
162 bool openMock();
163 void closeMock();
164
165 bool openSerial(const QString& portName, const PolhemusSerialConfig& cfg);
166 void closeSerial();
167 void drainParser();
168
169 bool m_isConnected = false;
170 QString m_backendName;
171
172 // Mock backend ------------------------------------------------------------
173 QTimer m_mockTimer;
174 int m_mockSampleIdx = 0;
175
176 // Serial backend ----------------------------------------------------------
177 QSerialPort* m_pSerial = nullptr;
178 FastrakParser m_parser;
179
180 // Pen-button detection (stream-pause timeout) -----------------------------
181 QTimer m_streamPauseTimer;
182 struct StationSample { QVector3D position; QQuaternion orientation; };
183 QMap<int, StationSample> m_lastSamples;
184};
185
186} // namespace UTILSLIB
187
188#endif // UTILS_POLHEMUS_CONNECTION_H
Public umbrella header for UTILSLIB exposing the UTILSSHARED_EXPORT macro and build-info accessors.
#define UTILSSHARED_EXPORT
Polhemus Fastrak / FastSCAN ASCII record parser.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Streaming parser for Fastrak / FastSCAN ASCII records.
@ Inches
Fastrak factory default.
Settings used to open a real Polhemus serial connection.
void connectedChanged(bool isConnected)
void penButtonPressed(int station, const QVector3D &position, const QQuaternion &orientation)
void pointReceived(int station, const QVector3D &position, const QQuaternion &orientation)
PolhemusConnection(QObject *parent=nullptr)
void errorOccurred(const QString &message)
bool open(const QString &portName, const PolhemusSerialConfig &cfg=PolhemusSerialConfig{})
static QString autoDetectPortName()
Best-effort auto-detection of an attached Fastrak/FastSCAN.
static QStringList availablePorts()
Enumerate every serial port currently visible to the OS.