From c0bd9291cc1d5cb37e5a9d4bd11950784887ce46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 7 Dec 2019 16:58:56 +0100 Subject: [PATCH] application: fix cable finder --- application.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/application.c b/application.c index c8fab29..402fd4f 100644 --- a/application.c +++ b/application.c @@ -183,24 +183,24 @@ static void command_find(void* argument) { (void)argument; // we won't use the argument + printf("= cable finder =\n"); usb_pins_float(); // start with all pins in safe floating state // figure out which connectors are used bool connected[LENGTH(usb_connectors)]; usb_cables_check_inter(usb_connectors, LENGTH(usb_connectors), connected); uint8_t connected_nb = 0; - printf("connectors:"); + printf("connectors:\n"); for (uint8_t i = 0; i < LENGTH(connected); i++) { if (connected[i]) { - printf(" %s", usb_connectors[i]->name); + printf("- %s (%s)\n", usb_connectors[i]->name, usb_connectors[i]->host ? "host" : "device"); connected_nb++; } } - printf("\n"); // find matching cable uint8_t matches = 0; // number of matching cables - printf("matching cables:"); + printf("matching cables:\n"); for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // ensure we have the same number of connections as the cable if (usb_cables[cable].connectors_nb != connected_nb) { @@ -208,7 +208,7 @@ static void command_find(void* argument) } // ensure all the connectors we have are also in the cable bool match = true; - for (uint8_t i = 0; i < LENGTH(connected) && match; i++) { + for (uint8_t i = 0; i < LENGTH(usb_connectors) && match; i++) { if (!connected[i]) { continue; } @@ -225,8 +225,8 @@ static void command_find(void* argument) // ensure we also have all the connectors which are in the cable for (uint8_t i = 0; i < usb_cables[cable].connectors_nb && match; i++) { bool found = false; - for (uint8_t j = 0; j < LENGTH(connected); j++) { - if (!connected[i]) { + for (uint8_t j = 0; j < LENGTH(usb_connectors); j++) { + if (!connected[j]) { continue; } if (usb_connectors[j] == usb_cables[cable].connectors[i]) { @@ -245,10 +245,10 @@ static void command_find(void* argument) match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, &pair_error); if (match) { matches++; - printf("%s, ", usb_cables[cable].name); + printf("- %s\n", usb_cables[cable].name); } - printf("\n%u matching cables found\n"); } + printf("%u matching cable(s) found\n", matches++); usb_pins_float(); // put all pins back in safe floating state }