Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
2 : // SPDX-License-Identifier: LGPL-3.0-or-later
3 :
4 : #ifndef DOKIT_DEVICECOMMAND_H
5 : #define DOKIT_DEVICECOMMAND_H
6 :
7 : #include "abstractcommand.h"
8 : #include "qtpokit/pokitproducts.h"
9 :
10 : #include <QLowEnergyController>
11 :
12 : class AbstractPokitService;
13 : class PokitDevice;
14 :
15 : class DeviceCommand : public AbstractCommand
16 : {
17 342 : Q_OBJECT
18 :
19 : public:
20 : explicit DeviceCommand(QObject * const parent = nullptr);
21 :
22 : public slots:
23 : bool start() override;
24 :
25 : protected:
26 : PokitDevice * device { nullptr }; ///< Pokit Bluetooth device (if any) this command interracts with.
27 : int exitCodeOnDisconnect { EXIT_FAILURE }; ///< Exit code to return on device disconnection.
28 :
29 : void disconnect(int exitCode=EXIT_SUCCESS);
30 : virtual AbstractPokitService * getService() = 0;
31 :
32 : template<typename T> static T minRange(const quint32 maxValue);
33 : static quint8 minCapacitanceRange(const PokitProduct product, const quint32 maxValue);
34 : static quint8 minCurrentRange(const PokitProduct product, const quint32 maxValue);
35 : static quint8 minResistanceRange(const PokitProduct product, const quint32 maxValue);
36 : static quint8 minVoltageRange(const PokitProduct product, const quint32 maxValue);
37 :
38 : protected slots:
39 : virtual void controllerError(const QLowEnergyController::Error error);
40 : virtual void deviceDisconnected();
41 : virtual void serviceError(const QLowEnergyService::ServiceError error);
42 : virtual void serviceDetailsDiscovered();
43 :
44 : private slots:
45 : // These are protected in the base class, but hidden (private) for our descendents.
46 : void deviceDiscovered(const QBluetoothDeviceInfo &info) override;
47 : void deviceDiscoveryFinished() override;
48 :
49 : friend class TestDeviceCommand;
50 : };
51 :
52 : #endif // DOKIT_DEVICECOMMAND_H
|