LCOV - code coverage report
Current view: top level - src/lib - pokitmeter.cpp (source / functions) Coverage Total Hit
Project: Dokit Lines: 84.1 % 88 74
Version: Functions: 92.3 % 13 12

            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 PokitMeter namespace.
       7              :  */
       8              : 
       9              : #include <qtpokit/pokitmeter.h>
      10              : 
      11              : #include <QCoreApplication>
      12              : #include <QLoggingCategory>
      13              : 
      14              : namespace PokitMeter {
      15              : 
      16            0 : static Q_LOGGING_CATEGORY(lc, "dokit.pokit.products.meter", QtInfoMsg); ///< Logging category for this file.
      17              : 
      18              : namespace {
      19              :     class Private
      20              :     {
      21            0 :         Q_DECLARE_TR_FUNCTIONS(PokitMeter)
      22              :     };
      23              : }
      24              : 
      25              : /// Returns \a range as a user-friendly string.
      26         4840 : QString toString(const CurrentRange &range)
      27         3167 : {
      28         8007 :     switch (range) {
      29          435 :     case CurrentRange::_10mA:     return Private::tr("Up to 10mA");
      30          435 :     case CurrentRange::_30mA:     return Private::tr("Up to 30mA");
      31         3438 :     case CurrentRange::_150mA:    return Private::tr("Up to 150mA");
      32          435 :     case CurrentRange::_300mA:    return Private::tr("Up to 300mA");
      33         2829 :     case CurrentRange::_2A:       return Private::tr("Up to 2A");
      34          435 :     case CurrentRange::AutoRange: return Private::tr("Auto-range");
      35            0 :     default:                      return QString();
      36         3167 :     }
      37         3167 : }
      38              : 
      39              : /*!
      40              :  * Returns the maximum value for \a range in microamps, or 0 if \a range is not a known value for Pokit Meter devices.
      41              :  */
      42         2040 : quint32 maxValue(const CurrentRange &range)
      43         2397 : {
      44         4437 :     switch (range) {
      45          611 :     case CurrentRange::_10mA:     return    10'000;
      46          957 :     case CurrentRange::_30mA:     return    30'000;
      47         1392 :     case CurrentRange::_150mA:    return   150'000;
      48          522 :     case CurrentRange::_300mA:    return   300'000;
      49          188 :     case CurrentRange::_2A:       return 2'000'000;
      50           47 :     case CurrentRange::AutoRange: return 2'000'000;
      51            0 :     default:
      52            0 :         qCWarning(lc).noquote() << Private::tr("Unknown CurrentRange value: %1").arg((int)range);
      53            0 :         return 0;
      54         2397 :     }
      55         2397 : }
      56              : 
      57              : /// Returns \a range as a user-friendly string.
      58         2160 : QString toString(const ResistanceRange &range)
      59         2358 : {
      60         4518 :     switch (range) {
      61          435 :     case ResistanceRange::_160:      return Private::tr("Up to 160Ω");
      62          435 :     case ResistanceRange::_330:      return Private::tr("Up to 330Ω");
      63          435 :     case ResistanceRange::_890:      return Private::tr("Up to 890Ω");
      64          435 :     case ResistanceRange::_1K5:      return Private::tr("Up to 1.5KΩ");
      65          777 :     case ResistanceRange::_10K:      return Private::tr("Up to 10KΩ");
      66          435 :     case ResistanceRange::_100K:     return Private::tr("Up to 100KΩ");
      67          696 :     case ResistanceRange::_470K:     return Private::tr("Up to 470KΩ");
      68          435 :     case ResistanceRange::_1M:       return Private::tr("Up to 1MΩ");
      69          435 :     case ResistanceRange::AutoRange: return Private::tr("Auto-range");
      70            0 :     default:                         return QString();
      71         2358 :     }
      72         2358 : }
      73              : 
      74              : /*!
      75              :  * Returns the maximum value for \a range in ohms, or 0 if \a range is not a known value for Pokit Meter devices.
      76              :  */
      77         3960 : quint32 maxValue(const ResistanceRange &range)
      78         4653 : {
      79         8613 :     switch (range) {
      80          893 :     case ResistanceRange::_160:      return       160;
      81         1479 :     case ResistanceRange::_330:      return       330;
      82         1305 :     case ResistanceRange::_890:      return       890;
      83         1131 :     case ResistanceRange::_1K5:      return     1'500;
      84          957 :     case ResistanceRange::_10K:      return    10'000;
      85          783 :     case ResistanceRange::_100K:     return   100'000;
      86          870 :     case ResistanceRange::_470K:     return   470'000;
      87          188 :     case ResistanceRange::_1M:       return 1'000'000;
      88           47 :     case ResistanceRange::AutoRange: return 1'000'000;
      89            0 :     default:
      90            0 :         qCWarning(lc).noquote() << Private::tr("Unknown ResistanceRange value: %1").arg((int)range);
      91            0 :         return 0;
      92         4653 :     }
      93         4653 : }
      94              : 
      95              : /// Returns \a range as a user-friendly string.
      96         5040 : QString toString(const VoltageRange &range)
      97         3402 : {
      98         8442 :     switch (range) {
      99         1044 :     case VoltageRange::_300mV:    return Private::tr("Up to 300mV");
     100         5223 :     case VoltageRange::_2V:       return Private::tr("Up to 2V");
     101          435 :     case VoltageRange::_6V:       return Private::tr("Up to 6V");
     102          435 :     case VoltageRange::_12V:      return Private::tr("Up to 12V");
     103          435 :     case VoltageRange::_30V:      return Private::tr("Up to 30V");
     104          435 :     case VoltageRange::_60V:      return Private::tr("Up to 60V");
     105          435 :     case VoltageRange::AutoRange: return Private::tr("Auto-range");
     106            0 :     default:                      return QString();
     107         3402 :     }
     108         3402 : }
     109              : 
     110              : /*!
     111              :  * Returns the maximum value for \a range in millivolts, or 0 if \a range is not a known value for Pokit Meter devices.
     112              :  */
     113         2680 : quint32 maxValue(const VoltageRange &range)
     114         3149 : {
     115         5829 :     switch (range) {
     116         1034 :     case VoltageRange::_300mV:    return    300;
     117         1131 :     case VoltageRange::_2V:       return  2'000;
     118          957 :     case VoltageRange::_6V:       return  6'000;
     119          783 :     case VoltageRange::_12V:      return 12'000;
     120          609 :     case VoltageRange::_30V:      return 30'000;
     121          188 :     case VoltageRange::_60V:      return 60'000;
     122           47 :     case VoltageRange::AutoRange: return 60'000;
     123            0 :     default:
     124            0 :         qCWarning(lc).noquote() << Private::tr("Unknown VoltageRange value: %1").arg((int)range);
     125            0 :         return 0;
     126         3149 :     }
     127         3149 : }
     128              : 
     129              : }
        

Generated by: LCOV version 2.2-1