Dokit
Internal development documentation
Loading...
Searching...
No Matches
pokitproducts.cpp
Go to the documentation of this file.
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 * 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 * \todo The Pokit Android app does this by distinguishing between these two advertiserd services:
66 * "00001800-0000-1000-8000-00805f9b34fb" Meter
67 * "0000180a-0000-1000-8000-00805f9b34fb" Pro
68 * Of course, these are the QBluetoothUuid::ServiceClassUuid::GenericAccess and
69 * QBluetoothUuid::ServiceClassUuid::GenericAttribute services.
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()
109 << QCoreApplication::translate("PokitProducts", "Device is not a Pokit product", "pokitProduct");
110 qCDebug(lc).noquote() << "Service UUIDs:" << serviceUuids;
111 return PokitProduct::PokitMeter; // Need to fallback to something; Pokit Meter is just the lowest product.
112 }
113}
114
115/*!
116 * Returns the #PokitProduct corresponding to the Bluetooth \a controller.
117 *
118 * Currently, this is based on whether or not \a controller's service UUIDs includes a known Pokit
119 * Status service, but this test criteria might be swapped for something else sometime.
120 *
121 * \see isPokitProduct
122 */
124{
125 return pokitProduct(controller.services());
126}
127
129
130/// Encapsulates convenience functions for working with capacitance ranges.
132
133/*!
134 * Returns \a product's capacitance \a range as a human-friendly string.
135 *
136 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
137 *
138 * \see PokitPro::toString(const PokitPro::CapacitanceRange &range)
139 */
140QString toString(const PokitProduct product, const quint8 range)
141{
142 switch (product) {
144 qCWarning(lc).noquote()
145 << QCoreApplication::translate("PokitProducts", "Pokit Meter has no capacitance support", "toString");
146 return QString();
148 return PokitPro::toString(static_cast<PokitPro::CapacitanceRange>(range));
149 }
150 qCWarning(lc).noquote() << QCoreApplication::translate("CapacitanceRange",
151 "Unknown PokitProduct value: %1", "toString").arg((int)product);
152 return QString();
153}
154
155/*!
156 * Returns the maximum value for \a product's \a range in (integer) nanofarads, or the string "Auto".
157 * If \a range is not a known valid value, then an null QVariant is returned.
158 *
159 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
160 *
161 * \see PokitPro::maxValue(const PokitPro::CapacitanceRange &range)
162 */
163QVariant maxValue(const PokitProduct product, const quint8 range)
164{
165 switch (product) {
167 qCWarning(lc).noquote()
168 << QCoreApplication::translate("PokitProducts", "Pokit Meter has no capacitance support", "toString");
169 return QVariant();
171 return PokitPro::maxValue(static_cast<PokitPro::CapacitanceRange>(range));
172 }
173 qCWarning(lc).noquote() << QCoreApplication::translate("CapacitanceRange",
174 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
175 return QVariant();
176}
177
178}
179
180/// Encapsulates convenience functions for working with current ranges.
181namespace CurrentRange {
182
183/*!
184 * Returns \a product's current \a range as a human-friendly string.
185 *
186 * \see PokitMeter::toString(const PokitMeter::CurrentRange &range)
187 * \see PokitPro::toString(const PokitPro::CurrentRange &range)
188 */
189QString toString(const PokitProduct product, const quint8 range)
190{
191 switch (product) {
193 return PokitMeter::toString(static_cast<PokitMeter::CurrentRange>(range));
195 return PokitPro::toString(static_cast<PokitPro::CurrentRange>(range));
196 }
197 qCWarning(lc).noquote() << QCoreApplication::translate("CurrentRange",
198 "Unknown PokitProduct value: %1", "toString").arg((int)product);
199 return QString();
200}
201
202/*!
203 * Returns the maximum value for \a product's \a range in (integer) microamps, or the string "Auto".
204 * If \a range is not a known valid value, then an null QVariant is returned.
205 *
206 * \see PokitMeter::maxValue(const PokitMeter::CurrentRange &range)
207 * \see PokitPro::maxValue(const PokitPro::CurrentRange &range)
208 */
209QVariant maxValue(const PokitProduct product, const quint8 range)
210{
211 switch (product) {
213 return PokitMeter::maxValue(static_cast<PokitMeter::CurrentRange>(range));
215 return PokitPro::maxValue(static_cast<PokitPro::CurrentRange>(range));
216 }
217 qCWarning(lc).noquote() << QCoreApplication::translate("CurrentRange",
218 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
219 return QVariant();
220}
221
222}
223
224/// Encapsulates convenience functions for working with resistance ranges.
226
227/*!
228 * Returns \a product's current \a range as a human-friendly string.
229 *
230 * \see PokitMeter::toString(const PokitMeter::ResistanceRange &range)
231 * \see PokitPro::toString(const PokitPro::ResistanceRange &range)
232 */
233QString toString(const PokitProduct product, const quint8 range)
234{
235 switch (product) {
237 return PokitMeter::toString(static_cast<PokitMeter::ResistanceRange>(range));
239 return PokitPro::toString(static_cast<PokitPro::ResistanceRange>(range));
240 }
241 qCWarning(lc).noquote() << QCoreApplication::translate("ResistanceRange",
242 "Unknown PokitProduct value: %1", "toString").arg((int)product);
243 return QString();
244}
245
246/*!
247 * Returns the maximum value for \a product's \a range in (integer) ohms, or the string "Auto".
248 * If \a range is not a known valid value, then an null QVariant is returned.
249 *
250 * \see PokitMeter::maxValue(const PokitMeter::ResistanceRange &range)
251 * \see PokitPro::maxValue(const PokitPro::ResistanceRange &range)
252 */
253QVariant maxValue(const PokitProduct product, const quint8 range)
254{
255 switch (product) {
257 return PokitMeter::maxValue(static_cast<PokitMeter::ResistanceRange>(range));
259 return PokitPro::maxValue(static_cast<PokitPro::ResistanceRange>(range));
260 }
261 qCWarning(lc).noquote() << QCoreApplication::translate("ResistanceRange",
262 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
263 return QVariant();
264}
265
266}
267
268/// Encapsulates convenience functions for working with voltage ranges.
269namespace VoltageRange {
270
271/*!
272 * Returns \a product's current \a range as a human-friendly string.
273 *
274 * \see PokitMeter::toString(const PokitMeter::VoltageRange &range)
275 * \see PokitPro::toString(const PokitPro::VoltageRange &range)
276 */
277QString toString(const PokitProduct product, const quint8 range)
278{
279 switch (product) {
281 return PokitMeter::toString(static_cast<PokitMeter::VoltageRange>(range));
283 return PokitPro::toString(static_cast<PokitPro::VoltageRange>(range));
284 }
285 qCWarning(lc).noquote() << QCoreApplication::translate("VoltageRange",
286 "Unknown PokitProduct value: %1", "toString").arg((int)product);
287 return QString();
288}
289
290/*!
291 * Returns the maximum value for \a product's \a range in (integer) millivolts, or the string "Auto".
292 * If \a range is not a known valid value, then an null QVariant is returned.
293 *
294 * \see PokitMeter::maxValue(const PokitMeter::VoltageRange &range)
295 * \see PokitPro::maxValue(const PokitPro::VoltageRange &range)
296 */
297QVariant maxValue(const PokitProduct product, const quint8 range)
298{
299 switch (product) {
301 return PokitMeter::maxValue(static_cast<PokitMeter::VoltageRange>(range));
303 return PokitPro::maxValue(static_cast<PokitPro::VoltageRange>(range));
304 }
305 qCWarning(lc).noquote() << QCoreApplication::translate("VoltageRange",
306 "Unknown PokitProduct value: %1", "maxValue").arg((int)product);
307 return QVariant();
308}
309
310}
311
312/// \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.