Dokit
Internal development documentation
Loading...
Searching...
No Matches
pokitproducts.cpp
Go to the documentation of this file.
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 * 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 range in nanofarads, or 0 if \a range is not a known value for \a product.
154 *
155 * \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
156 *
157 * \see PokitPro::maxValue(const PokitPro::CapacitanceRange &range)
158 */
159quint32 maxValue(const PokitProduct product, const quint8 range)
160{
161 switch (product) {
163 qCWarning(lc).noquote() << Private::tr("Pokit Meter has no capacitance support");
164 return 0;
166 return PokitPro::maxValue(static_cast<PokitPro::CapacitanceRange>(range));
167 }
168 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
169 return 0;
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() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
192 return QString();
193}
194
195/*!
196 * Returns the maximum value for \a range in microamps, or 0 if \a range is not a known value for \a product.
197 *
198 * \see PokitMeter::maxValue(const PokitMeter::CurrentRange &range)
199 * \see PokitPro::maxValue(const PokitPro::CurrentRange &range)
200 */
201quint32 maxValue(const PokitProduct product, const quint8 range)
202{
203 switch (product) {
205 return PokitMeter::maxValue(static_cast<PokitMeter::CurrentRange>(range));
207 return PokitPro::maxValue(static_cast<PokitPro::CurrentRange>(range));
208 }
209 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
210 return 0;
211}
212
213}
214
215/// Encapsulates convenience functions for working with resistance ranges.
217
218/*!
219 * Returns \a product's current \a range as a human-friendly string.
220 *
221 * \see PokitMeter::toString(const PokitMeter::ResistanceRange &range)
222 * \see PokitPro::toString(const PokitPro::ResistanceRange &range)
223 */
224QString toString(const PokitProduct product, const quint8 range)
225{
226 switch (product) {
228 return PokitMeter::toString(static_cast<PokitMeter::ResistanceRange>(range));
230 return PokitPro::toString(static_cast<PokitPro::ResistanceRange>(range));
231 }
232 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
233 return QString();
234}
235
236/*!
237 * Returns the maximum value for \a range in ohms, or 0 if \a range is not a known value for \a product.
238 *
239 * \see PokitMeter::maxValue(const PokitMeter::ResistanceRange &range)
240 * \see PokitPro::maxValue(const PokitPro::ResistanceRange &range)
241 */
242quint32 maxValue(const PokitProduct product, const quint8 range)
243{
244 switch (product) {
246 return PokitMeter::maxValue(static_cast<PokitMeter::ResistanceRange>(range));
248 return PokitPro::maxValue(static_cast<PokitPro::ResistanceRange>(range));
249 }
250 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
251 return 0;
252}
253
254}
255
256/// Encapsulates convenience functions for working with voltage ranges.
257namespace VoltageRange {
258
259/*!
260 * Returns \a product's current \a range as a human-friendly string.
261 *
262 * \see PokitMeter::toString(const PokitMeter::VoltageRange &range)
263 * \see PokitPro::toString(const PokitPro::VoltageRange &range)
264 */
265QString toString(const PokitProduct product, const quint8 range)
266{
267 switch (product) {
269 return PokitMeter::toString(static_cast<PokitMeter::VoltageRange>(range));
271 return PokitPro::toString(static_cast<PokitPro::VoltageRange>(range));
272 }
273 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
274 return QString();
275}
276
277/*!
278 * Returns the maximum value for \a range in millivolts, or 0 if \a range is not a known value for \a product.
279 *
280 * \see PokitMeter::maxValue(const PokitMeter::VoltageRange &range)
281 * \see PokitPro::maxValue(const PokitPro::VoltageRange &range)
282 */
283quint32 maxValue(const PokitProduct product, const quint8 range)
284{
285 switch (product) {
287 return PokitMeter::maxValue(static_cast<PokitMeter::VoltageRange>(range));
289 return PokitPro::maxValue(static_cast<PokitPro::VoltageRange>(range));
290 }
291 qCWarning(lc).noquote() << Private::tr("Unknown PokitProduct value: %1").arg((int)product);
292 return 0;
293}
294
295}
296
297/// \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.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in nanofarads, or 0 if range is not a known value for product.
Encapsulates convenience functions for working with current ranges.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in microamps, or 0 if range is not a known value for product.
CurrentRange
Values supported by the Pokit Meter's Range attributes in *Current modes.
Definition pokitmeter.h:20
QTPOKIT_EXPORT QString toString(const CurrentRange &range)
Returns range as a user-friendly string.
ResistanceRange
Values supported by the Pokit Meter's Range attributes in Resistance mode.
Definition pokitmeter.h:32
VoltageRange
Values supported by the Pokit Meter's Range attributes in *Voltage modes.
Definition pokitmeter.h:47
QTPOKIT_EXPORT quint32 maxValue(const CurrentRange &range)
Returns the maximum value for range in microamps, or 0 if range is not a known value for Pokit Meter ...
QTPOKIT_EXPORT QString toString(const CapacitanceRange &range)
Returns range as a user-friendly string.
Definition pokitpro.cpp:35
VoltageRange
Values supported by the Pokit Pro's Range attributes in *Voltage modes.
Definition pokitpro.h:63
CurrentRange
Values supported by the Pokit Pro's Range attributes in *Current modes.
Definition pokitpro.h:31
ResistanceRange
Values supported by the Pokit Pro's Range attributes in Resistance mode.
Definition pokitpro.h:45
CapacitanceRange
Values supported by the Pokit Pro's Range attributes in Capacitance mode.
Definition pokitpro.h:20
QTPOKIT_EXPORT quint32 maxValue(const CapacitanceRange &range)
Returns the maximum value for range in nanofarads, or 0 if range is not a known value for Pokit Pro d...
Definition pokitpro.cpp:49
Encapsulates convenience functions for working with resistance ranges.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in ohms, or 0 if range is not a known value for product.
Encapsulates convenience functions for working with voltage ranges.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in millivolts, or 0 if range is not a known value for product.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
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
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.