Dokit 0.5.3-pre
Internal development documentation
Loading...
Searching...
No Matches
pokitproducts.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Defines the #PokitProduct helper functions.
7 */
8
10#include <qtpokit/pokitpro.h>
13
14#include "pokitproducts_p.h"
15
16#include <QCoreApplication>
17#include <QLoggingCategory>
18
19static Q_LOGGING_CATEGORY(lc, "dokit.pokit.products", QtInfoMsg); ///< Logging category for this file.
20
22
23/*!
24 * Returns \c product as user-friendly string.
25 */
27{
28 switch (product) {
29 case PokitProduct::PokitMeter: return QStringLiteral("Pokit Meter");
30 case PokitProduct::PokitPro: return QStringLiteral("Pokit Pro");
31 }
32 qCWarning(lc).noquote() << QCoreApplication::translate("PokitProducts",
33 "Unknown PokitProduct value: %1", "toString").arg((int)product);
34 return QString();
35}
36
37/*!
38 * Returns \c true if \a info describes a Pokit device.
39 *
40 * Currently, this is based on whether or not \a info's service UUIDs includes a known Pokit
41 * Status service, but this test criteria might be swapped for something else sometime.
42 */
44{
45 return isPokitProduct(info.serviceUuids());
46}
47
48/*!
49 * Returns the #PokitProduct corresponding the Bluetotoh device \a info.
50 *
51 * If \a info is not a Pokit device, then result is undefined.
52 *
53 * \see isPokitProduct
54 */
59
60/// \cond internal
61
62/*!
63 * Returns \c true if \a serviceUuids contains a known Pokit Status service UUID.
64 *
65 * Currently, this is the only known way to detect a Pokit device.
66 */
67bool isPokitProduct(const QList<QBluetoothUuid> &serviceUuids)
68{
71}
72
73
74/*!
75 * Returns \c true if \a controller describes a Pokit device.
76 *
77 * Currently, this is based on whether or not \a controller's service UUIDs includes a known Pokit
78 * Status service, but this test criteria might be swapped for something else sometime.
79 *
80 * \see isPokitProduct
81 */
82bool isPokitProduct(const QLowEnergyController &controller)
83{
84 return isPokitProduct(controller.services());
85}
86
87/*!
88 * Returns the #PokitProduct corresponding to the Bluetooth \a serviceUuids.
89 *
90 * Currently, this is based on whether or not \a servceUuids includes a known Pokit
91 * Status service, but this test criteria might be swapped for something else sometime.
92 *
93 * \see isPokitProduct
94 */
96{
99 } else if (serviceUuids.contains(StatusService::ServiceUuids::pokitPro)) {
101 } else {
102 qCWarning(lc).noquote()
103 << QCoreApplication::translate("PokitProducts", "Device is not a Pokit product", "pokitProduct");
104 qCDebug(lc).noquote() << "Service UUIDs:" << serviceUuids;
105 return PokitProduct::PokitMeter; // Need to fallback to something; Pokit Meter is just the lowest product.
106 }
107}
108
109/*!
110 * Returns the #PokitProduct corresponding to the Bluetooth \a controller.
111 *
112 * Currently, this is based on whether or not \a controller's service UUIDs includes a known Pokit
113 * Status service, but this test criteria might be swapped for something else sometime.
114 *
115 * \see isPokitProduct
116 */
118{
119 return pokitProduct(controller.services());
120}
121
123
124/// Encapsulates convenience functions for working with capacitance ranges.
126
127/*!
128 * Returns \a product's capacitance \a range as a human-friendly string.
129 *
130 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
131 *
132 * \see PokitPro::toString(const PokitPro::CapacitanceRange &range)
133 */
134QString toString(const PokitProduct product, const quint8 range)
135{
136 switch (product) {
138 qCWarning(lc).noquote()
139 << QCoreApplication::translate("PokitProducts", "Pokit Meter has no capacitance support", "toString");
140 return QString();
142 return PokitPro::toString(static_cast<PokitPro::CapacitanceRange>(range));
143 }
144 qCWarning(lc).noquote() << QCoreApplication::translate("CapacitanceRange",
145 "Unknown PokitProduct value: %1", "toString").arg((int)product);
146 return QString();
147}
148
149/*!
150 * Returns the maximum value for \a product's \a range in (integer) nanofarads, or the string "Auto".
151 * If \a range is not a known valid value, then an null QVariant is returned.
152 *
153 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
154 *
155 * \see PokitPro::maxValue(const PokitPro::CapacitanceRange &range)
156 */
157QVariant maxValue(const PokitProduct product, const quint8 range)
158{
159 switch (product) {
161 qCWarning(lc).noquote()
162 << QCoreApplication::translate("PokitProducts", "Pokit Meter has no capacitance support", "toString");
163 return QVariant();
165 return PokitPro::maxValue(static_cast<PokitPro::CapacitanceRange>(range));
166 }
167 qCWarning(lc).noquote() << QCoreApplication::translate("CapacitanceRange",
168 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
169 return QVariant();
170}
171
172}
173
174/// Encapsulates convenience functions for working with current ranges.
175namespace CurrentRange {
176
177/*!
178 * Returns \a product's current \a range as a human-friendly string.
179 *
180 * \see PokitMeter::toString(const PokitMeter::CurrentRange &range)
181 * \see PokitPro::toString(const PokitPro::CurrentRange &range)
182 */
183QString toString(const PokitProduct product, const quint8 range)
184{
185 switch (product) {
187 return PokitMeter::toString(static_cast<PokitMeter::CurrentRange>(range));
189 return PokitPro::toString(static_cast<PokitPro::CurrentRange>(range));
190 }
191 qCWarning(lc).noquote() << QCoreApplication::translate("CurrentRange",
192 "Unknown PokitProduct value: %1", "toString").arg((int)product);
193 return QString();
194}
195
196/*!
197 * Returns the maximum value for \a product's \a range in (integer) microamps, or the string "Auto".
198 * If \a range is not a known valid value, then an null QVariant is returned.
199 *
200 * \see PokitMeter::maxValue(const PokitMeter::CurrentRange &range)
201 * \see PokitPro::maxValue(const PokitPro::CurrentRange &range)
202 */
203QVariant maxValue(const PokitProduct product, const quint8 range)
204{
205 switch (product) {
207 return PokitMeter::maxValue(static_cast<PokitMeter::CurrentRange>(range));
209 return PokitPro::maxValue(static_cast<PokitPro::CurrentRange>(range));
210 }
211 qCWarning(lc).noquote() << QCoreApplication::translate("CurrentRange",
212 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
213 return QVariant();
214}
215
216}
217
218/// Encapsulates convenience functions for working with resistance ranges.
220
221/*!
222 * Returns \a product's current \a range as a human-friendly string.
223 *
224 * \see PokitMeter::toString(const PokitMeter::ResistanceRange &range)
225 * \see PokitPro::toString(const PokitPro::ResistanceRange &range)
226 */
227QString toString(const PokitProduct product, const quint8 range)
228{
229 switch (product) {
231 return PokitMeter::toString(static_cast<PokitMeter::ResistanceRange>(range));
233 return PokitPro::toString(static_cast<PokitPro::ResistanceRange>(range));
234 }
235 qCWarning(lc).noquote() << QCoreApplication::translate("ResistanceRange",
236 "Unknown PokitProduct value: %1", "toString").arg((int)product);
237 return QString();
238}
239
240/*!
241 * Returns the maximum value for \a product's \a range in (integer) ohms, or the string "Auto".
242 * If \a range is not a known valid value, then an null QVariant is returned.
243 *
244 * \see PokitMeter::maxValue(const PokitMeter::ResistanceRange &range)
245 * \see PokitPro::maxValue(const PokitPro::ResistanceRange &range)
246 */
247QVariant maxValue(const PokitProduct product, const quint8 range)
248{
249 switch (product) {
251 return PokitMeter::maxValue(static_cast<PokitMeter::ResistanceRange>(range));
253 return PokitPro::maxValue(static_cast<PokitPro::ResistanceRange>(range));
254 }
255 qCWarning(lc).noquote() << QCoreApplication::translate("ResistanceRange",
256 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
257 return QVariant();
258}
259
260}
261
262/// Encapsulates convenience functions for working with voltage ranges.
263namespace VoltageRange {
264
265/*!
266 * Returns \a product's current \a range as a human-friendly string.
267 *
268 * \see PokitMeter::toString(const PokitMeter::VoltageRange &range)
269 * \see PokitPro::toString(const PokitPro::VoltageRange &range)
270 */
271QString toString(const PokitProduct product, const quint8 range)
272{
273 switch (product) {
275 return PokitMeter::toString(static_cast<PokitMeter::VoltageRange>(range));
277 return PokitPro::toString(static_cast<PokitPro::VoltageRange>(range));
278 }
279 qCWarning(lc).noquote() << QCoreApplication::translate("VoltageRange",
280 "Unknown PokitProduct value: %1", "toString").arg((int)product);
281 return QString();
282}
283
284/*!
285 * Returns the maximum value for \a product's \a range in (integer) millivolts, or the string "Auto".
286 * If \a range is not a known valid value, then an null QVariant is returned.
287 *
288 * \see PokitMeter::maxValue(const PokitMeter::VoltageRange &range)
289 * \see PokitPro::maxValue(const PokitPro::VoltageRange &range)
290 */
291QVariant maxValue(const PokitProduct product, const quint8 range)
292{
293 switch (product) {
295 return PokitMeter::maxValue(static_cast<PokitMeter::VoltageRange>(range));
297 return PokitPro::maxValue(static_cast<PokitPro::VoltageRange>(range));
298 }
299 qCWarning(lc).noquote() << QCoreApplication::translate("VoltageRange",
300 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
301 return QVariant();
302}
303
304}
305
306/// \endcond
Encapsulates convenience functions for working with capacitance ranges.
QString toString(const PokitProduct product, const quint8 range)
Returns product's capacitance range as a human-friendly string.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) nanofarads, or the string "Auto".
Encapsulates convenience functions for working with current ranges.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) microamps, or the string "Auto".
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
CurrentRange
Values supported by the Pokit Meter's Range attributes in *Current modes.
Definition pokitmeter.h:22
QTPOKIT_EXPORT QString toString(const CurrentRange &range)
Returns range as a user-friendly string.
QTPOKIT_EXPORT QVariant maxValue(const CurrentRange &range)
Returns the maximum value for range in (integer) microamps, or the string "Auto".
ResistanceRange
Values supported by the Pokit Meter's Range attributes in Resistance mode.
Definition pokitmeter.h:34
VoltageRange
Values supported by the Pokit Meter's Range attributes in *Voltage modes.
Definition pokitmeter.h:49
QTPOKIT_EXPORT QVariant maxValue(const CapacitanceRange &range)
Returns the maximum value for range in (integer) nanofarads, or the string "Auto".
Definition pokitpro.cpp:40
QTPOKIT_EXPORT QString toString(const CapacitanceRange &range)
Returns range as a user-friendly string.
Definition pokitpro.cpp:25
VoltageRange
Values supported by the Pokit Pro's Range attributes in *Voltage modes.
Definition pokitpro.h:65
CurrentRange
Values supported by the Pokit Pro's Range attributes in *Current modes.
Definition pokitpro.h:33
ResistanceRange
Values supported by the Pokit Pro's Range attributes in Resistance mode.
Definition pokitpro.h:47
CapacitanceRange
Values supported by the Pokit Pro's Range attributes in Capacitance mode.
Definition pokitpro.h:22
Encapsulates convenience functions for working with resistance ranges.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) ohms, or the string "Auto".
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
Encapsulates convenience functions for working with voltage ranges.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) millivolts, or the string "Auto".
Declares the PokitMeter namespace.
Declares the PokitPro namespace.
PokitProduct pokitProduct(const QBluetoothDeviceInfo &info)
Returns the PokitProduct corresponding the Bluetotoh device info.
bool isPokitProduct(const QBluetoothDeviceInfo &info)
Returns true if info describes a Pokit device.
QTPOKIT_BEGIN_NAMESPACE QString toString(const PokitProduct product)
Returns product as user-friendly string.
static Q_LOGGING_CATEGORY(lc, "dokit.pokit.products", QtInfoMsg)
Logging category for this file.
Declares the PokitProduct enumeration, and related helper functions.
PokitProduct
Pokit products known to, and supported by, the QtPokit library.
@ PokitPro
Pokit Pro.
@ PokitMeter
Pokit Meter.
QList< QBluetoothUuid > serviceUuids(QBluetoothDeviceInfo::DataCompleteness *completeness) const const
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
bool contains(const T &value) const const
QList< QBluetoothUuid > services() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
#define QTPOKIT_BEGIN_NAMESPACE
Macro for starting the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_END_NAMESPACE
Macro for ending the QtPokit library's top-most namespace (if one is defined).
Declares the StatusService class.
static const QBluetoothUuid pokitPro
UUID of the Pokit Pro's Pokit Status service.
static const QBluetoothUuid pokitMeter
UUID of the Pokit Meter's Pokit Status service.