Skip to content

Commit

Permalink
Improved --connected for test_device
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Dec 8, 2024
1 parent 6472fa2 commit ea632b2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,30 +948,31 @@ int main(int argc, char* argv[])
}

if (request_connected) {
if (test_device) {
printf("true\n");
return 0;
}

int is_test_device = selected_device == 0 && test_device;
// Check if battery status can be read
// If it isn't supported, the device is
// probably wired meaning it is connected
int battery_error = 0;
BatteryInfo info;

if ((device_selected->capabilities & B(CAP_BATTERY_STATUS)) == B(CAP_BATTERY_STATUS)) {
device_handle = dynamic_connect(&hid_path, device_handle, device_selected, CAP_BATTERY_STATUS);
if (!device_handle)
return 1;

BatteryInfo info = device_selected->request_battery(device_handle);
if (!is_test_device) {
device_handle = dynamic_connect(&hid_path, device_handle, device_selected, CAP_BATTERY_STATUS);
if (!device_handle) {
fprintf(stderr, "Error while getting device handle.\n");
return 1;
}
info = device_selected->request_battery(device_handle);
terminate_hid(&device_handle, &hid_path);
} else {
info = device_selected->request_battery(device_handle);
}

if (info.status != BATTERY_AVAILABLE) {
battery_error = 1;
}
}

terminate_hid(&device_handle, &hid_path);

if (battery_error != 0) {
printf("false\n");
return 1;
Expand Down

0 comments on commit ea632b2

Please sign in to comment.