Skip to content

Commit ea632b2

Browse files
committed
Improved --connected for test_device
1 parent 6472fa2 commit ea632b2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/main.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -948,30 +948,31 @@ int main(int argc, char* argv[])
948948
}
949949

950950
if (request_connected) {
951-
if (test_device) {
952-
printf("true\n");
953-
return 0;
954-
}
955-
951+
int is_test_device = selected_device == 0 && test_device;
956952
// Check if battery status can be read
957953
// If it isn't supported, the device is
958954
// probably wired meaning it is connected
959955
int battery_error = 0;
956+
BatteryInfo info;
960957

961958
if ((device_selected->capabilities & B(CAP_BATTERY_STATUS)) == B(CAP_BATTERY_STATUS)) {
962-
device_handle = dynamic_connect(&hid_path, device_handle, device_selected, CAP_BATTERY_STATUS);
963-
if (!device_handle)
964-
return 1;
965-
966-
BatteryInfo info = device_selected->request_battery(device_handle);
959+
if (!is_test_device) {
960+
device_handle = dynamic_connect(&hid_path, device_handle, device_selected, CAP_BATTERY_STATUS);
961+
if (!device_handle) {
962+
fprintf(stderr, "Error while getting device handle.\n");
963+
return 1;
964+
}
965+
info = device_selected->request_battery(device_handle);
966+
terminate_hid(&device_handle, &hid_path);
967+
} else {
968+
info = device_selected->request_battery(device_handle);
969+
}
967970

968971
if (info.status != BATTERY_AVAILABLE) {
969972
battery_error = 1;
970973
}
971974
}
972975

973-
terminate_hid(&device_handle, &hid_path);
974-
975976
if (battery_error != 0) {
976977
printf("false\n");
977978
return 1;

0 commit comments

Comments
 (0)