Dokit
Internal development documentation
Loading...
Searching...
No Matches
flashledcommand.cpp
1// SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#include "flashledcommand.h"
5
8
9#include <iostream>
10
11/*!
12 * \class FlashLedCommand
13 *
14 * The FlashLedCommand class implements the `flash-led` CLI command.
15 */
16
17/*!
18 * Construct a new FlashLedCommand object with \a parent.
19 */
21{
22
23}
24
30
35
36/*!
37 * \copybrief DeviceCommand::processOptions
38 *
39 * This implementation extends DeviceCommand::processOptions to process additional CLI options
40 * supported (or required) by this command.
41 */
43{
45 if (!errors.isEmpty()) {
46 return errors;
47 }
48
49 return errors;
50}
51
52/*!
53 * \copybrief DeviceCommand::getService
54 *
55 * This override returns a pointer to a StatusService object.
56 */
68
69/*!
70 * \copybrief DeviceCommand::serviceDetailsDiscovered
71 *
72 * This override flashes the device's LED, via the Pokit Status service.
73 */
75{
76 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
77 qCInfo(lc).noquote() << tr("Flashing Pokit device LED...");
78 if (!service->flashLed()) {
79 QCoreApplication::exit(EXIT_FAILURE);
80 }
81}
82
83/*!
84 * Handles StatusService::deviceLedFlashed events, by outputting the result and exiting.
85 */
87{
88 switch (format) {
90 std::cout << qUtf8Printable(tr("flash_led_result\nsuccess\n"));
91 break;
93 std::cout << qUtf8Printable(QLatin1String("true\n"));
94 break;
96 std::cout << qUtf8Printable(tr("Done.\n"));
97 break;
98 }
99 if (device) disconnect(); // Will exit the application once disconnected.
100}
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.
The AbstractCommand class extends AbstractCommand to add a PokitDevice instance.
PokitDevice * device
Pokit Bluetooth device (if any) this command interracts with.
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 interracts 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.
StatusService * status()
Returns a pointer to StatusService instance that uses this device's controller for access.
bool flashLed()
Flash the Pokit device's LED.
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
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
Declares the StatusService class.