LCOV - code coverage report
Current view: top level - include/qtpokit - multimeterservice.h (source / functions) Hit Total Coverage
Project: QtPokit Lines: 3 4 75.0 %
Version: Functions: 0 0 -

          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        2652 :     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             :         /// \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           0 :     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          51 :     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             : 
     138             : signals:
     139             :     void settingsWritten();
     140             :     void readingRead(const MultimeterService::Reading &reading);
     141             : 
     142             : protected:
     143             :     /// \cond internal
     144             :     MultimeterService(MultimeterServicePrivate * const d, QObject * const parent);
     145             :     /// \endcond
     146             : 
     147             : private:
     148         153 :     Q_DECLARE_PRIVATE(MultimeterService)
     149             :     Q_DISABLE_COPY(MultimeterService)
     150             :     friend class TestMultimeterService;
     151             : };
     152             : 
     153             : QTPOKIT_EXPORT bool operator==(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     154             : QTPOKIT_EXPORT bool operator!=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     155             : QTPOKIT_EXPORT bool operator< (const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     156             : QTPOKIT_EXPORT bool operator> (const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     157             : QTPOKIT_EXPORT bool operator<=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     158             : QTPOKIT_EXPORT bool operator>=(const MultimeterService::Range &lhs, const MultimeterService::Range &rhs);
     159             : 
     160             : QTPOKIT_END_NAMESPACE
     161             : 
     162             : #endif // QTPOKIT_MULTIMETERSERVICE_H

Generated by: LCOV version 1.14