Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2023 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 1782 : Q_OBJECT 25 : 26 : public: 27 : static const QBluetoothUuid serviceUuid; 28 : 29 : struct QTPOKIT_EXPORT CharacteristicUuids { 30 : static const QBluetoothUuid settings; 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 : Capacitance = 9, ///< Measure capacitance. 45 : ExternalTemperature = 10, ///< Measure temperature via an external temperature probe. 46 : }; 47 : static QString toString(const Mode &mode); 48 : 49 : static QString toString(const PokitProduct product, const quint8 range, const Mode mode); 50 : QString toString(const quint8 range, const Mode mode) const; 51 : static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode); 52 : QVariant maxValue(const quint8 range, const Mode mode) const; 53 : 54 : struct Settings { 55 : Mode mode; ///< Desired operation mode. 56 : quint8 range; ///< Desired range. 57 : quint32 updateInterval; ///< Desired update interval in milliseconds. 58 : }; 59 : 60 : enum class MeterStatus : quint8 { 61 : AutoRangeOff = 0, ///< Auto-range is disabled (voltage, current and resistance modes only). 62 : AutoRangeOn = 1, ///< Auto-range is enabled (voltage, current and resistance modes only). 63 : NoContinuity = 0, ///< No continuity (continuity mode only). 64 : Continuity = 1, ///< Continuity (continuity mode only). 65 : Ok = 0, ///< Ok (temperature and diode modes only). 66 : Error = 255 ///< Error (all modes). 67 : }; 68 : 69 : struct Reading { 70 : MeterStatus status; ///< Current multimeter status. 71 : float value; ///< Last acquired value. 72 : Mode mode; ///< Current operation mode. 73 : quint8 range; ///< Current range. 74 : }; 75 : 76 : MultimeterService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr); 77 : ~MultimeterService() override; 78 : 79 : bool readCharacteristics() override; 80 : bool readReadingCharacteristic(); 81 : 82 : // Settings characteristic (BLE write only). 83 : bool setSettings(const Settings &settings); 84 : 85 : // Reading characteristic (BLE read/notify). 86 : Reading reading() const; 87 : bool enableReadingNotifications(); 88 : bool disableReadingNotifications(); 89 : 90 : signals: 91 : void settingsWritten(); 92 : void readingRead(const MultimeterService::Reading &reading); 93 : 94 : protected: 95 : /// \cond internal 96 : MultimeterService(MultimeterServicePrivate * const d, QObject * const parent); 97 : /// \endcond 98 : 99 : private: 100 162 : Q_DECLARE_PRIVATE(MultimeterService) 101 : Q_DISABLE_COPY(MultimeterService) 102 : friend class TestMultimeterService; 103 : }; 104 : 105 : QTPOKIT_END_NAMESPACE 106 : 107 : #endif // QTPOKIT_MULTIMETERSERVICE_H