@@ -651,7 +651,7 @@ int main(int argc, char* argv[])
651
651
case 'd' : {
652
652
int parsed_correctly = get_two_ids (optarg , & selected_vendor_id , & selected_product_id );
653
653
if (parsed_correctly == 1 ) {
654
- fprintf (stderr , "Usage: %s -d [vendorid:deviceid] (N = Number of connected devices - 1) \n" , argv [0 ]);
654
+ fprintf (stderr , "Usage: %s -d, --device [vendorid:deviceid]\n" , argv [0 ]);
655
655
return 1 ;
656
656
}
657
657
break ;
@@ -930,7 +930,6 @@ int main(int argc, char* argv[])
930
930
// We open connection to HID devices on demand
931
931
hid_device * device_handle = NULL ;
932
932
char * hid_path = NULL ;
933
- FeatureRequest * feature_requests [headset_available ];
934
933
935
934
// Initialize signal handler for CTRL + C
936
935
#ifdef _WIN32
@@ -961,10 +960,16 @@ int main(int argc, char* argv[])
961
960
int numFeatures = sizeof (featureRequests ) / sizeof (featureRequests [0 ]);
962
961
assert (numFeatures == NUM_CAPABILITIES );
963
962
963
+ FeatureRequest * feature_requests [headset_available ];
964
+ for (int i = 0 ; i < headset_available ; i ++ ) {
965
+ feature_requests [i ] = memcpy (malloc (sizeof (featureRequests )), featureRequests , sizeof (featureRequests ));
966
+ devices_found [i ].featureRequests = feature_requests [i ];
967
+ devices_found [i ].size = numFeatures ;
968
+ }
969
+
964
970
// For specific output types, like YAML, we will do all actions - even when not specified - to aggreate all information
965
971
if (output_format == OUTPUT_YAML || output_format == OUTPUT_JSON || output_format == OUTPUT_ENV ) {
966
972
for (int i = 0 ; i < headset_available ; i ++ ) {
967
- feature_requests [i ] = memcpy (malloc (sizeof (featureRequests )), featureRequests , sizeof (featureRequests ));
968
973
for (int j = 0 ; j < numFeatures ; j ++ ){
969
974
if (feature_requests [i ][j ].type == CAPABILITYTYPE_INFO && !feature_requests [i ][j ].should_process ) {
970
975
if ((devices_found [i ].device -> capabilities & B (feature_requests [i ][j ].cap )) == B (feature_requests [i ][j ].cap )) {
@@ -973,9 +978,6 @@ int main(int argc, char* argv[])
973
978
}
974
979
}
975
980
}
976
- devices_found [i ].featureRequests = feature_requests [i ];
977
- devices_found [i ].size = numFeatures ;
978
-
979
981
terminate_device_hid (& device_handle , & hid_path );
980
982
}
981
983
}
@@ -1013,39 +1015,32 @@ int main(int argc, char* argv[])
1013
1015
1014
1016
if (battery_error != 0 ) {
1015
1017
printf ("false\n" );
1016
- return 1 ;
1017
1018
} else {
1018
1019
printf ("true\n" );
1019
- return 0 ;
1020
1020
}
1021
- }
1022
-
1023
- do {
1024
- if ( device_selected != NULL ) {
1025
- FeatureRequest * deviceFeatureRequests = device_selected -> featureRequests ;
1026
- for ( int i = 0 ; i < numFeatures ; i ++ ) {
1027
- if ( deviceFeatureRequests [ i ]. should_process ) {
1028
- // Assuming handle_feature now returns FeatureResult
1029
- deviceFeatureRequests [ i ]. result = handle_feature ( device_selected -> device , & device_handle , & hid_path , deviceFeatureRequests [ i ]. cap , deviceFeatureRequests [ i ]. param );
1030
- } else {
1031
- // Populate with a default "not processed" result
1032
- deviceFeatureRequests [i ].result .status = FEATURE_NOT_PROCESSED ;
1033
- deviceFeatureRequests [i ].result .message = strdup ( "Not processed" ) ;
1034
- deviceFeatureRequests [ i ]. result . value = 0 ;
1021
+ } else {
1022
+ do {
1023
+ if ( device_selected != NULL ) {
1024
+ FeatureRequest * deviceFeatureRequests = device_selected -> featureRequests ;
1025
+ for ( int i = 0 ; i < numFeatures ; i ++ ) {
1026
+ if ( deviceFeatureRequests [ i ]. should_process ) {
1027
+ // Assuming handle_feature now returns FeatureResult
1028
+ deviceFeatureRequests [ i ]. result = handle_feature ( device_selected -> device , & device_handle , & hid_path , deviceFeatureRequests [ i ]. cap , deviceFeatureRequests [ i ]. param );
1029
+ } else {
1030
+ // Populate with a default "not processed" result
1031
+ deviceFeatureRequests [ i ]. result . status = FEATURE_NOT_PROCESSED ;
1032
+ deviceFeatureRequests [i ].result .message = strdup ( "Not processed" ) ;
1033
+ deviceFeatureRequests [i ].result .value = 0 ;
1034
+ }
1035
1035
}
1036
1036
}
1037
- }
1038
1037
1039
- output (devices_found , print_capabilities != -1 , output_format );
1038
+ output (devices_found , print_capabilities != -1 , output_format );
1040
1039
1041
- if (follow )
1042
- sleep (follow_sec );
1040
+ if (follow )
1041
+ sleep (follow_sec );
1043
1042
1044
- } while (follow );
1045
-
1046
- // Free memory from features
1047
- for (int i = 0 ; i < numFeatures ; i ++ ) {
1048
- //free(devices_found[device_index].featureRequests[i].result.message);
1043
+ } while (follow );
1049
1044
}
1050
1045
1051
1046
if (equalizer != NULL ) {
@@ -1054,8 +1049,13 @@ int main(int argc, char* argv[])
1054
1049
free (equalizer );
1055
1050
1056
1051
for (int i = 0 ; i < headset_available ; i ++ ) {
1057
- if (output_format != OUTPUT_STANDARD )
1058
- free (feature_requests [i ]);
1052
+ if (output_format != OUTPUT_STANDARD ){
1053
+ // Free memory from features
1054
+ for (int j = 0 ; j < numFeatures ; j ++ ) {
1055
+ free (devices_found [i ].featureRequests [j ].result .message );
1056
+ }
1057
+ }
1058
+ free (devices_found [i ].featureRequests );
1059
1059
free (devices_found [i ].device );
1060
1060
}
1061
1061
0 commit comments