LCOV - code coverage report
Current view: top level - src/lib - pokitmeter.cpp (source / functions) Hit Total Coverage
Project: Dokit Lines: 56 56 100.0 %
Version: Functions: 6 6 100.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 PokitMeter namespace.
       7             :  */
       8             : 
       9             : #include "qtpokit/pokitmeter.h"
      10             : 
      11             : #include <QCoreApplication>
      12             : 
      13             : namespace PokitMeter {
      14             : 
      15             : /// \enum CurrentRange
      16             : /// \brief Values supported by the Pokit Meter's `Range` attributes in `*Current` modes.
      17             : 
      18             : /// Returns \a range as a user-friendly string.
      19        1746 : QString toString(const CurrentRange &range)
      20             : {
      21        1746 :     switch (range) {
      22          18 :     case CurrentRange::_10mA:     return QCoreApplication::translate("PokitMeter", "Up to 10mA",  "CurrentRange");
      23          18 :     case CurrentRange::_30mA:     return QCoreApplication::translate("PokitMeter", "Up to 30mA",  "CurrentRange");
      24         900 :     case CurrentRange::_150mA:    return QCoreApplication::translate("PokitMeter", "Up to 150mA", "CurrentRange");
      25          18 :     case CurrentRange::_300mA:    return QCoreApplication::translate("PokitMeter", "Up to 300mA", "CurrentRange");
      26         774 :     case CurrentRange::_2A:       return QCoreApplication::translate("PokitMeter", "Up to 2A",    "CurrentRange");
      27          18 :     case CurrentRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto-range",  "CurrentRange");
      28             :     default:                      return QString();
      29             :     }
      30             : }
      31             : 
      32             : /*!
      33             :  *  Returns the maximum value for \a range in (integer) microamps, or the string "Auto".
      34             :  *  If \a range is not a known valid value, then an null QVariant is returned.
      35             :  */
      36         234 : QVariant maxValue(const CurrentRange &range)
      37             : {
      38         234 :     switch (range) {
      39          18 :     case CurrentRange::_10mA:     return   10000;
      40          18 :     case CurrentRange::_30mA:     return   30000;
      41         144 :     case CurrentRange::_150mA:    return  150000;
      42          18 :     case CurrentRange::_300mA:    return  300000;
      43          18 :     case CurrentRange::_2A:       return 2000000;
      44          22 :     case CurrentRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto", "CurrentRange");
      45             :     default:                      return QVariant();
      46             :     }
      47             : }
      48             : 
      49             : /// \enum ResistanceRange
      50             : /// \brief Values supported by the Pokit Meter's `Range` attributes in `Resistance` mode.
      51             : 
      52             : /// Returns \a range as a user-friendly string.
      53         324 : QString toString(const ResistanceRange &range)
      54             : {
      55         324 :     switch (range) {
      56          18 :     case ResistanceRange::_160:      return QCoreApplication::translate("PokitMeter", "Up to 160Ω",  "ResistanceRange");
      57          18 :     case ResistanceRange::_330:      return QCoreApplication::translate("PokitMeter", "Up to 330Ω",  "ResistanceRange");
      58          18 :     case ResistanceRange::_890:      return QCoreApplication::translate("PokitMeter", "Up to 890Ω",  "ResistanceRange");
      59          18 :     case ResistanceRange::_1K5:      return QCoreApplication::translate("PokitMeter", "Up to 1.5KΩ", "ResistanceRange");
      60         126 :     case ResistanceRange::_10K:      return QCoreApplication::translate("PokitMeter", "Up to 10KΩ",  "ResistanceRange");
      61          18 :     case ResistanceRange::_100K:     return QCoreApplication::translate("PokitMeter", "Up to 100KΩ", "ResistanceRange");
      62          72 :     case ResistanceRange::_470K:     return QCoreApplication::translate("PokitMeter", "Up to 470KΩ", "ResistanceRange");
      63          18 :     case ResistanceRange::_1M:       return QCoreApplication::translate("PokitMeter", "Up to 1MΩ",   "ResistanceRange");
      64          18 :     case ResistanceRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto-range",  "ResistanceRange");
      65             :     default:                         return QString();
      66             :     }
      67             : }
      68             : 
      69             : /*!
      70             :  *  Returns the maximum value for \a range in (integer) ohms, or the string "Auto".
      71             :  *  If \a range is not a known valid value, then an null QVariant is returned.
      72             :  */
      73         216 : QVariant maxValue(const ResistanceRange &range)
      74             : {
      75         216 :     switch (range) {
      76          18 :     case ResistanceRange::_160:      return     160;
      77          18 :     case ResistanceRange::_330:      return     330;
      78          18 :     case ResistanceRange::_890:      return     890;
      79          18 :     case ResistanceRange::_1K5:      return    1500;
      80          18 :     case ResistanceRange::_10K:      return   10000;
      81          18 :     case ResistanceRange::_100K:     return  100000;
      82          72 :     case ResistanceRange::_470K:     return  470000;
      83          18 :     case ResistanceRange::_1M:       return 1000000;
      84          22 :     case ResistanceRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto", "ResistanceRange");
      85             :     default:                         return QVariant();
      86             :     }
      87             : }
      88             : 
      89             : /// \enum VoltageRange
      90             : /// \brief Values supported by the Pokit Meter's `Range` attributes in `*Voltage` modes.
      91             : 
      92             : /// Returns \a range as a user-friendly string.
      93        1764 : QString toString(const VoltageRange &range)
      94             : {
      95        1764 :     switch (range) {
      96         144 :     case VoltageRange::_300mV:    return QCoreApplication::translate("PokitMeter", "Up to 300mV", "VoltageRange");
      97        1530 :     case VoltageRange::_2V:       return QCoreApplication::translate("PokitMeter", "Up to 2V",    "VoltageRange");
      98          18 :     case VoltageRange::_6V:       return QCoreApplication::translate("PokitMeter", "Up to 6V",    "VoltageRange");
      99          18 :     case VoltageRange::_12V:      return QCoreApplication::translate("PokitMeter", "Up to 12V",   "VoltageRange");
     100          18 :     case VoltageRange::_30V:      return QCoreApplication::translate("PokitMeter", "Up to 30V",   "VoltageRange");
     101          18 :     case VoltageRange::_60V:      return QCoreApplication::translate("PokitMeter", "Up to 60V",   "VoltageRange");
     102          18 :     case VoltageRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto-range",  "VoltageRange");
     103             :     default:                      return QString();
     104             :     }
     105             : }
     106             : 
     107             : /*!
     108             :  *  Returns the maximum value for \a range in (integer) millivolts, or the string "Auto".
     109             :  *  If \a range is not a known valid value, then an null QVariant is returned.
     110             :  */
     111         252 : QVariant maxValue(const VoltageRange &range)
     112             : {
     113         252 :     switch (range) {
     114         144 :     case VoltageRange::_300mV:    return   300;
     115          18 :     case VoltageRange::_2V:       return  2000;
     116          18 :     case VoltageRange::_6V:       return  6000;
     117          18 :     case VoltageRange::_12V:      return 12000;
     118          18 :     case VoltageRange::_30V:      return 30000;
     119          18 :     case VoltageRange::_60V:      return 60000;
     120          22 :     case VoltageRange::AutoRange: return QCoreApplication::translate("PokitMeter", "Auto", "VoltageRange");
     121             :     default:                      return QVariant();
     122             :     }
     123             : }
     124             : 
     125             : }

Generated by: LCOV version 1.14