Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
flashledcommand.cpp
1// SPDX-FileCopyrightText: 2022-2025 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#include "flashledcommand.h"
6
9
10#include <iostream>
11
13
14/*!
15 * \class FlashLedCommand
16 *
17 * The FlashLedCommand class implements the `flash-led` CLI command.
18 */
19
20/*!
21 * Construct a new FlashLedCommand object with \a parent.
22 */
27
33
38
39/*!
40 * \copybrief DeviceCommand::processOptions
41 *
42 * This implementation extends DeviceCommand::processOptions to process additional CLI options
43 * supported (or required) by this command.
44 */
46{
48 if (!errors.isEmpty()) {
49 return errors;
50 }
51
52 return errors;
53}
54
55/*!
56 * \copybrief DeviceCommand::getService
57 *
58 * This override returns a pointer to a StatusService object.
59 */
61{
62 Q_ASSERT(device);
63 if (!service) {
64 service = device->status();
65 Q_ASSERT(service);
68 }
69 return service;
70}
71
72/*!
73 * \copybrief DeviceCommand::serviceDetailsDiscovered
74 *
75 * This override flashes the device's LED, via the Pokit Status service.
76 */
78{
79 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
80 qCInfo(lc).noquote() << tr("Flashing Pokit device LED...");
81 if (!service->flashLed()) {
82 QCoreApplication::exit(EXIT_FAILURE);
83 }
84}
85
86/*!
87 * Handles StatusService::deviceLedFlashed events, by outputting the result and exiting.
88 */
90{
91 switch (format) {
93 std::cout << qUtf8Printable(tr("flash_led_result\nsuccess\n"));
94 break;
96 std::cout << qUtf8Printable(u"true\n"_s);
97 break;
99 std::cout << qUtf8Printable(tr("Done.\n"));
100 break;
101 }
102 if (device) disconnect(); // Will exit the application once disconnected.
103}
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.
The AbstractPokitService class provides a common base for Pokit services classes.
PokitDevice * device
Pokit Bluetooth device (if any) this command interacts with.
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
QStringList supportedOptions(const QCommandLineParser &parser) const override
Returns a list of CLI option names supported by this command.
QStringList requiredOptions(const QCommandLineParser &parser) const override
Returns a list of CLI option names required by this command.
StatusService * service
Bluetooth service this command interacts with.
FlashLedCommand(QObject *const parent=nullptr)
Construct a new FlashLedCommand object with parent.
QStringList processOptions(const QCommandLineParser &parser) override
Processes the relevant options from the command line parser.
AbstractPokitService * getService() override
Returns a Pokit service object for the derived command class.
void serviceDetailsDiscovered() override
Handles service detail discovery events.
void deviceLedFlashed()
Handles StatusService::deviceLedFlashed events, by outputting the result and exiting.
void deviceLedFlashed()
This signal is emitted when device's LED has flashed in response to a write of the Flash LED characte...
Declares the PokitDevice class.
void exit(int returnCode)
bool isEmpty() const const
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
Declares the StatusService class.
Declares the DOKIT_USE_STRINGLITERALS macro, and related functions.
#define DOKIT_USE_STRINGLITERALS
Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ...