Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
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
23namespace {
24 class Private
25 {
26 Q_DECLARE_TR_FUNCTIONS(PokitProducts)
27 };
28}
29
30/*!
31 * Returns \c product as user-friendly string.
32 */
34{
35 switch (product) {
36 case PokitProduct::PokitMeter: return QStringLiteral("Pokit Meter");
37 case PokitProduct::PokitPro: return QStringLiteral("Pokit Pro");
38 }
39 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
40 return QString();
41}
42
43/*!
44 * Returns \c true if \a info describes a Pokit device.
45 *
46 * Currently, this is based on whether or not \a info's service UUIDs includes a known Pokit
47 * Status service, but this test criteria might be swapped for something else sometime.
48 */
50{
51 return isPokitProduct(info.serviceUuids());
52}
53
54/*!
55 * Returns the #PokitProduct corresponding the Bluetotoh device \a info.
56 *
57 * If \a info is not a Pokit device, then result is undefined.
58 *
59 * \see isPokitProduct
60 */
65
66/// \cond internal
67
68/*!
69 * Returns \c true if \a serviceUuids contains a known Pokit Status service UUID.
70 *
71 * Currently, this is the only known way to detect a Pokit device.
72 */
73bool isPokitProduct(const QList<QBluetoothUuid> &serviceUuids)
74{
77}
78
79
80/*!
81 * Returns \c true if \a controller describes a Pokit device.
82 *
83 * Currently, this is based on whether or not \a controller's service UUIDs includes a known Pokit
84 * Status service, but this test criteria might be swapped for something else sometime.
85 *
86 * \see isPokitProduct
87 */
88bool isPokitProduct(const QLowEnergyController &controller)
89{
90 return isPokitProduct(controller.services());
91}
92
93/*!
94 * Returns the #PokitProduct corresponding to the Bluetooth \a serviceUuids.
95 *
96 * Currently, this is based on whether or not \a servceUuids includes a known Pokit
97 * Status service, but this test criteria might be swapped for something else sometime.
98 *
99 * \see isPokitProduct
100 */
102{
105 } else if (serviceUuids.contains(StatusService::ServiceUuids::pokitPro)) {
107 } else {
108 qCWarning(lc).noquote() << Private::tr("Device is not a Pokit product");
109 qCDebug(lc).noquote() << "Service UUIDs:" << serviceUuids;
110 return PokitProduct::PokitMeter; // Need to fallback to something; Pokit Meter is just the lowest product.
111 }
112}
113
114/*!
115 * Returns the #PokitProduct corresponding to the Bluetooth \a controller.
116 *
117 * Currently, this is based on whether or not \a controller's service UUIDs includes a known Pokit
118 * Status service, but this test criteria might be swapped for something else sometime.
119 *
120 * \see isPokitProduct
121 */
123{
124 return pokitProduct(controller.services());
125}
126
128
129/// Encapsulates convenience functions for working with capacitance ranges.
131
132/*!
133 * Returns \a product's capacitance \a range as a human-friendly string.
134 *
135 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
136 *
137 * \see PokitPro::toString(const PokitPro::CapacitanceRange &range)
138 */
139QString toString(const PokitProduct product, const quint8 range)
140{
141 switch (product) {
143 qCWarning(lc).noquote() << Private::tr("Pokit Meter has no capacitance support");
144 return QString();
146 return PokitPro::toString(static_cast<PokitPro::CapacitanceRange>(range));
147 }
148 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
149 return QString();
150}
151
152/*!
153 * Returns the maximum value for \a product's \a range in (integer) nanofarads, or the string "Auto".
154 * If \a range is not a known valid value, then an null QVariant is returned.
155 *
156 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
157 *
158 * \see PokitPro::maxValue(const PokitPro::CapacitanceRange &range)
159 */
160QVariant maxValue(const PokitProduct product, const quint8 range)
161{
162 switch (product) {
164 qCWarning(lc).noquote() << Private::tr("Pokit Meter has no capacitance support");
165 return QVariant();
167 return PokitPro::maxValue(static_cast<PokitPro::CapacitanceRange>(range));
168 }
169 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
170 return QVariant();
171}
172
173}
174
175/// Encapsulates convenience functions for working with current ranges.
176namespace CurrentRange {
177
178/*!
179 * Returns \a product's current \a range as a human-friendly string.
180 *
181 * \see PokitMeter::toString(const PokitMeter::CurrentRange &range)
182 * \see PokitPro::toString(const PokitPro::CurrentRange &range)
183 */
184QString toString(const PokitProduct product, const quint8 range)
185{
186 switch (product) {
188 return PokitMeter::toString(static_cast<PokitMeter::CurrentRange>(range));
190 return PokitPro::toString(static_cast<PokitPro::CurrentRange>(range));
191 }
192 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").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() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
212 return QVariant();
213}
214
215}
216
217/// Encapsulates convenience functions for working with resistance ranges.
219
220/*!
221 * Returns \a product's current \a range as a human-friendly string.
222 *
223 * \see PokitMeter::toString(const PokitMeter::ResistanceRange &range)
224 * \see PokitPro::toString(const PokitPro::ResistanceRange &range)
225 */
226QString toString(const PokitProduct product, const quint8 range)
227{
228 switch (product) {
230 return PokitMeter::toString(static_cast<PokitMeter::ResistanceRange>(range));
232 return PokitPro::toString(static_cast<PokitPro::ResistanceRange>(range));
233 }
234 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
235 return QString();
236}
237
238/*!
239 * Returns the maximum value for \a product's \a range in (integer) ohms, or the string "Auto".
240 * If \a range is not a known valid value, then an null QVariant is returned.
241 *
242 * \see PokitMeter::maxValue(const PokitMeter::ResistanceRange &range)
243 * \see PokitPro::maxValue(const PokitPro::ResistanceRange &range)
244 */
245QVariant maxValue(const PokitProduct product, const quint8 range)
246{
247 switch (product) {
249 return PokitMeter::maxValue(static_cast<PokitMeter::ResistanceRange>(range));
251 return PokitPro::maxValue(static_cast<PokitPro::ResistanceRange>(range));
252 }
253 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
254 return QVariant();
255}
256
257}
258
259/// Encapsulates convenience functions for working with voltage ranges.
260namespace VoltageRange {
261
262/*!
263 * Returns \a product's current \a range as a human-friendly string.
264 *
265 * \see PokitMeter::toString(const PokitMeter::VoltageRange &range)
266 * \see PokitPro::toString(const PokitPro::VoltageRange &range)
267 */
268QString toString(const PokitProduct product, const quint8 range)
269{
270 switch (product) {
272 return PokitMeter::toString(static_cast<PokitMeter::VoltageRange>(range));
274 return PokitPro::toString(static_cast<PokitPro::VoltageRange>(range));
275 }
276 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
277 return QString();
278}
279
280/*!
281 * Returns the maximum value for \a product's \a range in (integer) millivolts, or the string "Auto".
282 * If \a range is not a known valid value, then an null QVariant is returned.
283 *
284 * \see PokitMeter::maxValue(const PokitMeter::VoltageRange &range)
285 * \see PokitPro::maxValue(const PokitPro::VoltageRange &range)
286 */
287QVariant maxValue(const PokitProduct product, const quint8 range)
288{
289 switch (product) {
291 return PokitMeter::maxValue(static_cast<PokitMeter::VoltageRange>(range));
293 return PokitPro::maxValue(static_cast<PokitPro::VoltageRange>(range));
294 }
295 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
296 return QVariant();
297}
298
299}
300
301/// \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:47
QTPOKIT_EXPORT QString toString(const CapacitanceRange &range)
Returns range as a user-friendly string.
Definition pokitpro.cpp:32
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.
QString toString(const PokitProduct product)
Returns product as user-friendly string.
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.
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
bool contains(const T &value) const const
QList< QBluetoothUuid > services() 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.