application: fix cable finder
This commit is contained in:
parent
8519698af6
commit
c0bd9291cc
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue