-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTorchBearerWorker.hpp
More file actions
93 lines (68 loc) · 2.16 KB
/
Copy pathTorchBearerWorker.hpp
File metadata and controls
93 lines (68 loc) · 2.16 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-FileCopyrightText: 2026 Błażej Szczygieł <mumei6102@gmail.com>
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include "SpectrometerWorker.hpp"
class TorchBearerWorker : public SpectrometerWorker
{
Q_OBJECT
enum class MessageType : uint8_t
{
STOP = 0x04,
SET_DEVICE_ID = 0x07, // Don't use, it'll change the device ID permanently!
GET_DEVICE_ID = 0x08,
SET_EXPOSURE_MODE = 0x0A,
GET_EXPOSURE_MODE = 0x0B,
SET_EXPOSURE = 0x0C,
GET_EXPOSURE = 0x0D,
GET_RANGE = 0x0F,
GET_DATA = 0x33,
};
Q_ENUM(MessageType)
enum class ExposureMode : uint8_t
{
MANUAL = 0x00,
AUTOMATIC = 0x01,
};
Q_ENUM(ExposureMode)
enum class ExposureStatus : uint8_t
{
NORMAL = 0x00,
OVER = 0x01,
UNDER = 0x02,
};
Q_ENUM(ExposureStatus)
using Commands = QList<pair<MessageType, QByteArray>>;
struct Message;
public:
static QStringList scanDevices();
public:
TorchBearerWorker(QObject *parent = nullptr);
~TorchBearerWorker();
bool setParam(const QString &key, const QVariant &value) override;
QString staticDataName() const override;
private:
void run() override;
void xferMessage(QIODevice &device, MessageType messageType, const QByteArrayView data = QByteArrayView());
void processCommandsFinished();
private:
static uint8_t calculateChecksum(const QByteArrayView message);
static QByteArray buildMessage(MessageType messageType, const QByteArrayView data);
static QByteArray intToBa(auto val);
private:
optional<Message> parseMessage(MessageType message_type, const QByteArrayView data) const;
private:
void readData(QIODevice &device);
private:
bool m_br = false;
const double m_minAllowedAutoExposure = 1.0;
const double m_maxAllowedAutoExposure = 2000.0;
QString m_dev;
bool m_openError = true;
optional<ExposureMode> m_exposureMode;
mutex m_mutex;
condition_variable m_cv;
Commands m_commands;
bool m_ignoreDataForSingleMeasurement = false;
bool m_singleMeasurement = false;
bool m_mustEmitCommandsFinished = false;
};