Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2023 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/pokitmeter.h" 9 : #include "qtpokit/pokitpro.h" 10 : #include "qtpokit/pokitproducts.h" 11 : 12 : #include <QLowEnergyController> 13 : 14 : class AbstractPokitService; 15 : class PokitDevice; 16 : 17 : class DeviceCommand : public AbstractCommand 18 : { 19 162 : Q_OBJECT 20 : 21 : public: 22 : explicit DeviceCommand(QObject * const parent = nullptr); 23 : 24 : public slots: 25 : bool start() override; 26 : 27 : protected: 28 : PokitDevice * device { nullptr }; ///< Pokit Bluetooth device (if any) this command inerracts with. 29 : int exitCodeOnDisconnect { EXIT_FAILURE }; ///< Exit code to return on device disconnection. 30 : 31 : void disconnect(int exitCode=EXIT_SUCCESS); 32 : virtual AbstractPokitService * getService() = 0; 33 : 34 : template<typename T> static T minRange(const quint32 maxValue); 35 : static quint8 minCapacitanceRange(const PokitProduct product, const quint32 maxValue); 36 : static quint8 minCurrentRange(const PokitProduct product, const quint32 maxValue); 37 : static quint8 minResistanceRange(const PokitProduct product, const quint32 maxValue); 38 : static quint8 minVoltageRange(const PokitProduct product, const quint32 maxValue); 39 : 40 : protected slots: 41 : virtual void controllerError(const QLowEnergyController::Error error); 42 : virtual void deviceDisconnected(); 43 : virtual void serviceError(const QLowEnergyService::ServiceError error); 44 : virtual void serviceDetailsDiscovered(); 45 : 46 : private slots: 47 : // These are protected in the base class, but hidden (private) for our descendents. 48 : void deviceDiscovered(const QBluetoothDeviceInfo &info) override; 49 : void deviceDiscoveryFinished() override; 50 : 51 : friend class TestDeviceCommand; 52 : }; 53 : 54 : /// \cond Doxygen has "only very limited support for member specialization at the moment", so hide these from Doxygen. 55 : template<> PokitMeter::CurrentRange DeviceCommand::minRange(const quint32 maxValue); 56 : template<> PokitMeter::ResistanceRange DeviceCommand::minRange(const quint32 maxValue); 57 : template<> PokitMeter::VoltageRange DeviceCommand::minRange(const quint32 maxValue); 58 : 59 : template<> PokitPro::CapacitanceRange DeviceCommand::minRange(const quint32 maxValue); 60 : template<> PokitPro::CurrentRange DeviceCommand::minRange(const quint32 maxValue); 61 : template<> PokitPro::ResistanceRange DeviceCommand::minRange(const quint32 maxValue); 62 : template<> PokitPro::VoltageRange DeviceCommand::minRange(const quint32 maxValue); 63 : /// \endcond 64 : 65 : #endif // DOKIT_DEVICECOMMAND_H