QtPokit
Native Qt library for Pokit devices
multimeterservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Declares the MultimeterService class.
7 */
8
9#ifndef QTPOKIT_MULTIMETERSERVICE_H
10#define QTPOKIT_MULTIMETERSERVICE_H
11
13
14#include <QBluetoothAddress>
15#include <QBluetoothUuid>
16#include <QVersionNumber>
17
18QTPOKIT_BEGIN_NAMESPACE
19
20class MultimeterServicePrivate;
21
22class QTPOKIT_EXPORT MultimeterService : public AbstractPokitService
23{
24 Q_OBJECT
25
26public:
28
29 struct QTPOKIT_EXPORT CharacteristicUuids {
31 static const QBluetoothUuid reading;
32 };
33
34 enum class Mode : quint8 {
35 Idle = 0, ///< Make device idle.
36 DcVoltage = 1, ///< Measure DC voltage.
37 AcVoltage = 2, ///< Measure AC voltage.
38 DcCurrent = 3, ///< Measure DC current.
39 AcCurrent = 4, ///< Measure AC current.
40 Resistance = 5, ///< Measure resistance.
41 Diode = 6, ///< Measure diode.
42 Continuity = 7, ///< Measure continuity.
43 Temperature = 8, ///< Measure temperature.
44 /// \todo Pokit Pro supports capacitance too.
45 };
46 static QString toString(const Mode &mode);
47
48 enum class VoltageRange : quint8 {
49 _0_to_300mV = 0, ///< 0 to 300mV.
50 _300mV_to_2V = 1, ///< 300mV to 2V.
51 _2V_to_6V = 2, ///< 2V to 6V.
52 _6V_to_12V = 3, ///< 6V to 12V.
53 _12V_to_30V = 4, ///< 12V to 30V.
54 _30V_to_60V = 5, ///< 30V to 60V.
55 /// \todo Pokit Pro supports up to 600V.
56 AutoRange = 255 ///< Auto-range.
57 };
58 static QString toString(const VoltageRange &range);
59 static QVariant minValue(const VoltageRange &range);
60 static QVariant maxValue(const VoltageRange &range);
61
62 enum class CurrentRange : quint8 {
63 _0_to_10mA = 0, ///< 0 to 10mA.
64 _10mA_to_30mA = 1, ///< 10mA to 30mA.
65 _30mA_to_150mA = 2, ///< 30mA to 150mA.
66 _150mA_to_300mA = 3, ///< 150mA to 300mA.
67 _300mA_to_3A = 4, ///< 300mA to 3A.
68 /// \todo Pokit Pro supports up to 10A.
69 AutoRange = 255 ///< Auto-range.
70 };
71 static QString toString(const CurrentRange &range);
72 static QVariant minValue(const CurrentRange &range);
73 static QVariant maxValue(const CurrentRange &range);
74
75 enum class ResistanceRange : quint8 {
76 _0_to_160 = 0, ///< 0 to 160 ohms.
77 _160_to_330 = 1, ///< 160 to 330 ohms.
78 _330_to_890 = 2, ///< 330 to 890 ohms.
79 _890_to_1K5 = 3, ///< 890 to 1.5K ohms.
80 _1K5_to_10K = 4, ///< 1.5K to 10K ohms.
81 _10K_to_100K = 5, ///< 10K to 100K ohms.
82 _100K_to_470K = 6, ///< 100K to 470K ohms.
83 _470K_to_1M = 7, ///< 470K to 1M ohms.
84 /// \todo Pokit Pro supports up to 3M ohms.
85 AutoRange = 255 ///< Auto-range.
86 };
87 static QString toString(const ResistanceRange &range);
88 static QVariant minValue(const ResistanceRange &range);
89 static QVariant maxValue(const ResistanceRange &range);
90
91 union QTPOKIT_EXPORT Range {
92 VoltageRange voltageRange; ///< Range when in AC/DC voltage mode.
93 CurrentRange currentRange; ///< Range when in AC/DC current mode.
94 ResistanceRange resistanceRange; ///< Range when in resistance mode.
95 Range();
96 Range(const VoltageRange range);
97 Range(const CurrentRange range);
98 Range(const ResistanceRange range);
99 };
100 static QString toString(const Range &range, const Mode &mode);
101
102 struct Settings {
103 Mode mode; ///< Desired operation mode.
104 Range range; ///< Desired range.
105 quint32 updateInterval; ///< Desired update interval in milliseconds.
106 };
107
108 enum class MeterStatus : quint8 {
109 AutoRangeOff = 0, ///< Auto-range is disabled (voltage, current and resistance modes only).
110 AutoRangeOn = 1, ///< Auto-range is enabled (voltage, current and resistance modes only).
111 NoContinuity = 0, ///< No continuity (continuity mode only).
112 Continuity = 1, ///< Continuity (continuity mode only).
113 Ok = 0, ///< Ok (temperature and diode modes only).
114 Error = 255 ///< Error (all modes).
115 };
116
117 struct Reading {
118 MeterStatus status; ///< Current multimeter status.
119 float value; ///< Last acquired value.
120 Mode mode; ///< Current operation mode.
121 Range range; ///< Current range.
122 };
123
124 MultimeterService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
125 ~MultimeterService() override;
126
127 bool readCharacteristics() override;
128 bool readReadingCharacteristic();
129
130 // Settings characteristic (BLE write only).
131 bool setSettings(const Settings &settings);
132
133 // Reading characteristic (BLE read/notify).
134 Reading reading() const;
135 bool enableReadingNotifications();
136 bool disableReadingNotifications();
137
138signals:
141
142protected:
143 /// \cond internal
144 MultimeterService(MultimeterServicePrivate * const d, QObject * const parent);
145 /// \endcond
146
147private:
148 Q_DECLARE_PRIVATE(MultimeterService)
149 Q_DISABLE_COPY(MultimeterService)
150 friend class TestMultimeterService;
151};
152
153QTPOKIT_EXPORT bool operator==(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
154QTPOKIT_EXPORT bool operator!=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
155QTPOKIT_EXPORT bool operator< (const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
156QTPOKIT_EXPORT bool operator> (const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
157QTPOKIT_EXPORT bool operator<=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
158QTPOKIT_EXPORT bool operator>=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
159
160QTPOKIT_END_NAMESPACE
161
162#endif // QTPOKIT_MULTIMETERSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition: abstractpokitservice.h:24
virtual bool readCharacteristics()=0
Read all characteristics.
The MultimeterService class accesses the Pokit Status service of Pokit devices.
Definition: multimeterservice.h:23
CurrentRange
Values supported by the Range attribute of the Settings and Reading characteristics,...
Definition: multimeterservice.h:62
MeterStatus
Values supported by the Status attribute of the Settings characteristic.
Definition: multimeterservice.h:108
Mode
Values supported by the Mode attribute of the Settings and Reading characteristics.
Definition: multimeterservice.h:34
static const QBluetoothUuid serviceUuid
UUID of the "Multimeter" service.
Definition: multimeterservice.h:27
ResistanceRange
Values supported by the Range attribute of the Settings and Reading characteristics,...
Definition: multimeterservice.h:75
void readingRead(const MultimeterService::Reading &reading)
This signal is emitted when the Reading characteristic has been read successfully.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
VoltageRange
Values supported by the Range attribute of the Settings and Reading characteristics,...
Definition: multimeterservice.h:48
QTPOKIT_EXPORT bool operator!=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically not-equal to rhs, false otherwise.
Definition: multimeterservice.cpp:289
QTPOKIT_EXPORT bool operator==(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically equal to rhs, false otherwise.
Definition: multimeterservice.cpp:282
QTPOKIT_EXPORT bool operator>=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically greater than or equal to rhs, false otherwise.
Definition: multimeterservice.cpp:317
QTPOKIT_EXPORT bool operator<(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically less than rhs, false otherwise.
Definition: multimeterservice.cpp:296
QTPOKIT_EXPORT bool operator>(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically greater than rhs, false otherwise.
Definition: multimeterservice.cpp:303
QTPOKIT_EXPORT bool operator<=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs)
Returns true if lhs is numerically less than or equal to rhs, false otherwise.
Definition: multimeterservice.cpp:310
Characteristics available via the Multimeter service.
Definition: multimeterservice.h:29
static const QBluetoothUuid reading
UUID of the Multimeter service's Reading characterstic.
Definition: multimeterservice.h:31
static const QBluetoothUuid settings
UUID of the Multimeter service's Settings characterstic.
Definition: multimeterservice.h:30
Attributes included in the Reading characterstic.
Definition: multimeterservice.h:117
MeterStatus status
Current multimeter status.
Definition: multimeterservice.h:118
Range range
Current range.
Definition: multimeterservice.h:121
Mode mode
Current operation mode.
Definition: multimeterservice.h:120
float value
Last acquired value.
Definition: multimeterservice.h:119
Attributes included in the Settings characterstic.
Definition: multimeterservice.h:102
quint32 updateInterval
Desired update interval in milliseconds.
Definition: multimeterservice.h:105
Range range
Desired range.
Definition: multimeterservice.h:104
Mode mode
Desired operation mode.
Definition: multimeterservice.h:103
Values supported by the Range attribute of the Settings characteristic.
Definition: multimeterservice.h:91
ResistanceRange resistanceRange
Range when in resistance mode.
Definition: multimeterservice.h:94
CurrentRange currentRange
Range when in AC/DC current mode.
Definition: multimeterservice.h:93
VoltageRange voltageRange
Range when in AC/DC voltage mode.
Definition: multimeterservice.h:92