Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2025 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 :
12 : #include "abstractpokitservice.h"
13 :
14 : #include <QBluetoothAddress>
15 : #include <QBluetoothUuid>
16 : #include <QVersionNumber>
17 :
18 : QTPOKIT_BEGIN_NAMESPACE
19 :
20 : class MultimeterServicePrivate;
21 :
22 : class QTPOKIT_EXPORT MultimeterService : public AbstractPokitService
23 : {
24 6435 : Q_OBJECT
25 0 :
26 0 : public:
27 0 : /// UUID of the `Multimeter` service.
28 0 : static inline const QBluetoothUuid serviceUuid { QStringLiteral("e7481d2f-5781-442e-bb9a-fd4e3441dadc") };
29 0 :
30 0 : /// Characteristics available via the `Multimeter` service.
31 0 : struct QTPOKIT_EXPORT CharacteristicUuids {
32 0 : /// UUID of the `Multimeter` service's `Settings` characteristic.
33 0 : static inline const QBluetoothUuid settings { QStringLiteral("53dc9a7a-bc19-4280-b76b-002d0e23b078") };
34 0 :
35 0 : /// UUID of the `Multimeter` service's `Reading` characteristic.
36 0 : static inline const QBluetoothUuid reading { QStringLiteral("047d3559-8bee-423a-b229-4417fa603b90") };
37 0 : };
38 0 :
39 0 : /// Values supported by the `Mode` attribute of the `Settings` and `Reading` characteristics.
40 0 : enum class Mode : quint8 {
41 0 : Idle = 0, ///< Make device idle.
42 0 : DcVoltage = 1, ///< Measure DC voltage.
43 0 : AcVoltage = 2, ///< Measure AC voltage.
44 0 : DcCurrent = 3, ///< Measure DC current.
45 0 : AcCurrent = 4, ///< Measure AC current.
46 0 : Resistance = 5, ///< Measure resistance.
47 0 : Diode = 6, ///< Measure diode.
48 0 : Continuity = 7, ///< Measure continuity.
49 0 : Temperature = 8, ///< Measure temperature.
50 0 : Capacitance = 9, ///< Measure capacitance.
51 0 : ExternalTemperature = 10, ///< Measure temperature via an external temperature probe.
52 0 : };
53 0 : static QString toString(const Mode &mode);
54 0 :
55 0 : static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
56 0 : QString toString(const quint8 range, const Mode mode) const;
57 0 : static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
58 0 : quint32 maxValue(const quint8 range, const Mode mode) const;
59 0 :
60 0 : /// Attributes included in the `Settings` characteristic.
61 0 : struct Settings {
62 0 : Mode mode; ///< Desired operation mode.
63 0 : quint8 range; ///< Desired range.
64 0 : quint32 updateInterval; ///< Desired update interval in milliseconds.
65 0 : };
66 0 :
67 0 : /// Values supported by the `Status` attribute of the `Settings` characteristic.
68 0 : enum class MeterStatus : quint8 {
69 0 : AutoRangeOff = 0, ///< Auto-range is disabled (voltage, current and resistance modes only).
70 0 : AutoRangeOn = 1, ///< Auto-range is enabled (voltage, current and resistance modes only).
71 0 : NoContinuity = 0, ///< No continuity (continuity mode only).
72 0 : Continuity = 1, ///< Continuity (continuity mode only).
73 0 : Ok = 0, ///< Ok (temperature and diode modes only).
74 0 : Error = 255 ///< Error (all modes).
75 0 : };
76 0 :
77 0 : /// Attributes included in the `Reading` characteristic.
78 0 : struct Reading {
79 0 : MeterStatus status; ///< Current multimeter status.
80 0 : float value; ///< Last acquired value.
81 0 : Mode mode; ///< Current operation mode.
82 0 : quint8 range; ///< Current range.
83 0 : };
84 0 :
85 0 : MultimeterService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
86 3390 : ~MultimeterService() = default;
87 :
88 : bool readCharacteristics() override;
89 : bool readReadingCharacteristic();
90 :
91 : // Settings characteristic (BLE write only).
92 : bool setSettings(const Settings &settings);
93 :
94 : // Reading characteristic (BLE read/notify).
95 : Reading reading() const;
96 : bool enableReadingNotifications();
97 : bool disableReadingNotifications();
98 :
99 : Q_SIGNALS:
100 : void settingsWritten();
101 : void readingRead(const MultimeterService::Reading &reading);
102 :
103 : protected:
104 : /// \cond internal
105 : MultimeterService(MultimeterServicePrivate * const d, QObject * const parent);
106 : /// \endcond
107 :
108 : private:
109 585 : Q_DECLARE_PRIVATE(MultimeterService)
110 : Q_DISABLE_COPY(MultimeterService)
111 : QTPOKIT_BEFRIEND_TEST(MultimeterService)
112 : };
113 :
114 : QTPOKIT_END_NAMESPACE
115 :
116 : #endif // QTPOKIT_MULTIMETERSERVICE_H
|