Skip to content

Commit

Permalink
Include switch and charging status in CLI output
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolby committed Dec 2, 2023
1 parent 422432c commit 073bce8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
29 changes: 26 additions & 3 deletions src/cli/statuscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void StatusCommand::outputDeviceStatus(const StatusService::DeviceCharacteristic
const std::optional<StatusService::ButtonStatus> buttonStatus = service->buttonPress();
const QString statusLabel = StatusService::toString(status.deviceStatus);
const QString batteryLabel = StatusService::toString(status.batteryStatus);
const QString switchLabel = status.switchPosition ? StatusService::toString(*status.switchPosition) : QString();
const QString chargingLabel = status.chargingStatus ? StatusService::toString(*status.chargingStatus) : QString();
const QString torchLabel = (torchStatus) ? StatusService::toString(*torchStatus) : QString();
const QString buttonLabel = (buttonStatus) ? StatusService::toString(*buttonStatus) : QString();

Expand All @@ -102,13 +104,14 @@ void StatusCommand::outputDeviceStatus(const StatusService::DeviceCharacteristic
std::cout << qUtf8Printable(tr("device_name,device_status,firmware_version,maximum_voltage,"
"maximum_current,maximum_resistance,maximum_sampling_rate,"
"sampling_buffer_size,capability_mask,mac_address,battery_voltage,"
"battery_status,torch_status,button_status\n"));
std::cout << qUtf8Printable(QString::fromLatin1("%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14\n")
"battery_status,torch_status,button_status,switch_position,charging_status\n"));
std::cout << qUtf8Printable(QString::fromLatin1("%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16\n")
.arg(escapeCsvField(deviceName),statusLabel.toLower(),chrs.firmwareVersion.toString())
.arg(chrs.maximumVoltage).arg(chrs.maximumCurrent).arg(chrs.maximumResistance)
.arg(chrs.maximumSamplingRate).arg(chrs.samplingBufferSize).arg(chrs.capabilityMask)
.arg(chrs.macAddress.toString()).arg(status.batteryVoltage)
.arg(batteryLabel.toLower(), torchLabel.toLower(), buttonLabel.toLower()));
.arg(batteryLabel.toLower(), torchLabel.toLower(), buttonLabel.toLower(), switchLabel.toLower(),
chargingLabel.toLower()));
break;
case OutputFormat::Json: {
QJsonObject battery{
Expand Down Expand Up @@ -148,6 +151,18 @@ void StatusCommand::outputDeviceStatus(const StatusService::DeviceCharacteristic
{ QLatin1String("label"), buttonLabel },
});
}
if (status.switchPosition) {
object.insert(QStringLiteral("switchStatus"), QJsonObject{
{ QLatin1String("code"), (quint8)*status.switchPosition },
{ QLatin1String("label"), switchLabel },
});
}
if (status.chargingStatus) {
object.insert(QStringLiteral("chargingStatus"), QJsonObject{
{ QLatin1String("code"), (quint8)*status.chargingStatus },
{ QLatin1String("label"), chargingLabel },
});
}
std::cout << QJsonDocument(object).toJson().toStdString();
} break;
case OutputFormat::Text:
Expand All @@ -166,6 +181,14 @@ void StatusCommand::outputDeviceStatus(const StatusService::DeviceCharacteristic
std::cout << qUtf8Printable(tr("Battery status: %1 (%2)\n")
.arg(batteryLabel.isNull() ? QString::fromLatin1("N/A") : batteryLabel)
.arg((quint8)status.batteryStatus));
if (status.switchPosition) {
std::cout << qUtf8Printable(tr("Switch position: %1 (%2)\n")
.arg(switchLabel).arg((quint8)*status.switchPosition));
}
if (status.chargingStatus) {
std::cout << qUtf8Printable(tr("Charging status: %1 (%2)\n")
.arg(chargingLabel).arg((quint8)*status.chargingStatus));
}
break;
}
if (device) disconnect(); // Will exit the application once disconnected.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status
,idle,1.4,60,2,1000,1000,8192,0,84:2E:14:2C:03:A8,nan,low,,
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status,switch_position,charging_status
,idle,1.4,60,2,1000,1000,8192,0,84:2E:14:2C:03:A8,nan,low,,,,
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status
,idle,1.3,850,10,3000,1000,16384,0,5C:02:72:09:AA:25,nan,low,,
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status,switch_position,charging_status
,idle,1.3,850,10,3000,1000,16384,0,5C:02:72:09:AA:25,nan,low,,,,
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status
,idle,,0,0,0,0,0,0,00:00:00:00:00:00,nan,low,,
device_name,device_status,firmware_version,maximum_voltage,maximum_current,maximum_resistance,maximum_sampling_rate,sampling_buffer_size,capability_mask,mac_address,battery_voltage,battery_status,torch_status,button_status,switch_position,charging_status
,idle,,0,0,0,0,0,0,00:00:00:00:00:00,nan,low,,,,

0 comments on commit 073bce8

Please sign in to comment.