File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -948,30 +948,31 @@ int main(int argc, char* argv[])
948
948
}
949
949
950
950
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 ;
956
952
// Check if battery status can be read
957
953
// If it isn't supported, the device is
958
954
// probably wired meaning it is connected
959
955
int battery_error = 0 ;
956
+ BatteryInfo info ;
960
957
961
958
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
+ }
967
970
968
971
if (info .status != BATTERY_AVAILABLE ) {
969
972
battery_error = 1 ;
970
973
}
971
974
}
972
975
973
- terminate_hid (& device_handle , & hid_path );
974
-
975
976
if (battery_error != 0 ) {
976
977
printf ("false\n" );
977
978
return 1 ;
You can’t perform that action at this time.
0 commit comments