| 296 | } |
| 297 | |
| 298 | void output_json(HeadsetControlStatus* status, HeadsetInfo* infos) |
| 299 | { |
| 300 | printf("{\n"); |
| 301 | |
| 302 | json_print_key_value("name", status->name, 2); |
| 303 | printf(",\n"); |
| 304 | json_print_key_value("version", status->version, 2); |
| 305 | printf(",\n"); |
| 306 | json_print_key_value("api_version", status->api_version, 2); |
| 307 | printf(",\n"); |
| 308 | json_print_key_value("hidapi_version", status->hid_version, 2); |
| 309 | printf(",\n"); |
| 310 | |
| 311 | if (infos != NULL) { |
| 312 | for (int j = 0; j < status->device_count; j++) { |
| 313 | HeadsetInfo* info = &infos[j]; |
| 314 | if (info->action_count > 0) { |
| 315 | printf(" \"actions\": [\n"); |
| 316 | for (int i = 0; i < info->action_count; i++) { |
| 317 | printf(" {\n"); |
| 318 | |
| 319 | json_print_key_value("capability", info->actions[i].capability, 6); |
| 320 | printf(",\n"); |
| 321 | json_print_key_value("device", info->actions[i].device, 6); |
| 322 | printf(",\n"); |
| 323 | json_print_key_value("status", status_to_string(info->actions[i].status), 6); |
| 324 | |
| 325 | if (info->actions[i].value > 0) { |
| 326 | printf(",\n"); |
| 327 | json_printint_key_value("value", info->actions[i].value, 6); |
| 328 | } |
| 329 | |
| 330 | if (info->actions[i].error_message != NULL && strlen(info->actions[i].error_message) > 0) { |
| 331 | printf(",\n"); |
| 332 | json_print_key_value("error_message", info->actions[i].error_message, 6); |
| 333 | } |
| 334 | |
| 335 | printf("\n }"); |
| 336 | if (i < info->action_count - 1) { |
| 337 | printf(",\n"); |
| 338 | } |
| 339 | } |
| 340 | printf("\n ],\n"); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // For integers, direct printing is still simplest |
| 346 | printf(" \"device_count\": %d,\n", status->device_count); |
| 347 | |
| 348 | printf(" \"devices\": [\n"); |
| 349 | for (int i = 0; i < status->device_count; i++) { |
| 350 | HeadsetInfo* info = &infos[i]; |
| 351 | printf(" {\n"); |
| 352 | |
| 353 | json_print_key_value("status", status_to_string(info->status), 6); |
| 354 | printf(",\n"); |
| 355 | json_print_key_value("device", info->device_name, 6); |
no test coverage detected