usb_cables: remove duplicate output parameter

This commit is contained in:
King Kévin 2019-12-09 23:31:13 +01:00
parent 2d5a2b7f4f
commit 549f1c992f
3 changed files with 16 additions and 20 deletions

View File

@ -172,9 +172,9 @@ static void command_cables(void* argument)
// step 2: check for known cable configuration
printf("= cable check =\n");
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test every cable
uint8_t pair_defined, pair_undefined, pair_disconnected;
bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, false);
printf("%s: %s (defined=%u, undefined=%u, disconnected=%u)\n", result ? "OK" : "KO", usb_cables[cable].name, pair_defined, pair_undefined, pair_disconnected);
uint8_t pair_defined, pair_undefined;
bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, false);
printf("%s: %s (defined=%u/%u, undefined=%u)\n", result ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].pin_pairs_nb, pair_undefined);
}
usb_pins_float(); // put all pins back in safe floating state
@ -263,10 +263,10 @@ static void command_find(void* argument)
continue;
}
// match cable
uint8_t pair_defined, pair_undefined, pair_disconnected;
bool match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, false);
printf("- %s: %s (defined=%u, undefined=%u, disconnected=%u)\n", match ? "OK" : "KO", usb_cables[cable].name, pair_defined, pair_undefined, pair_disconnected);
cable_score[cable] = usb_cables[cable].pin_pairs_nb - pair_defined + pair_undefined + pair_disconnected; // calculate score
uint8_t pair_defined, pair_undefined;
bool match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, false);
printf("- %s: %s (defined=%u/%u, undefined=%u)\n", match ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].pin_pairs_nb, pair_undefined);
cable_score[cable] = usb_cables[cable].pin_pairs_nb - pair_defined + pair_undefined; // calculate score
if (match) {
matches++;
}
@ -293,7 +293,7 @@ static void command_find(void* argument)
}
if (cable_score[cable] == best_score) {
printf("- %s\n", usb_cables[cable].name);
usb_cables_check_cable(&usb_cables[cable], NULL, NULL, NULL, true);
usb_cables_check_cable(&usb_cables[cable], NULL, NULL, true);
}
}
@ -461,10 +461,10 @@ static void command_test(void* argument)
}
bool cable_ok = false; // if the cable is connected
while (!cable_ok) { // wait until all pin pairs of cable are connected
uint8_t defined, undefined, disconnected; // pair counting variables
cable_ok = usb_cables_check_cable(&test_cables[cable], &defined, &undefined, &disconnected, true); // test cable
uint8_t defined, undefined; // pair counting variables
cable_ok = usb_cables_check_cable(&test_cables[cable], &defined, &undefined, true); // test cable
if (!cable_ok && defined > 0) { // not all pairs are connected
printf("connection issues: defined=%u/%u, undefined=%u, disconnected=%u\n", defined, test_cables[cable].pin_pairs_nb, undefined, disconnected); // show issue summary
printf("connection issues: defined=%u/%u, undefined=%u\n", defined, test_cables[cable].pin_pairs_nb, undefined); // show issue summary
}
if (!cable_ok) {
if (user_input_available) { // user interruption

View File

@ -1754,12 +1754,12 @@ bool usb_cables_check_load(const struct usb_connector_t* connector)
return loaded;
}
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected, bool print)
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, bool print)
{
if (NULL == usb_cable) {
return false;
}
uint8_t _defined = 0, _undefined = 0, _disconnected = 0; // internal pair counting variables
uint8_t _defined = 0, _undefined = 0; // internal pair counting variables
usb_cables_connectors_float(usb_cable->connectors, usb_cable->connectors_nb); // ensure we start in a safe state
for (uint8_t connector_from = 0; connector_from < usb_cable->connectors_nb; connector_from++) { // test from every connector
@ -1811,7 +1811,7 @@ bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* define
}
} else { // there is no connection
if (pair_defined) {
_disconnected++;
// don't actually count the number of unconnected pair since it can be calculated from pin_pairs_nb - defined
if (print) {
printf("no connection: %s %s to %s %s\n", usb_cable->connectors[connector_from]->name, usb_cable->connectors[connector_from]->pins[pin_from].name, usb_cable->connectors[connector_to]->name, usb_cable->connectors[connector_to]->pins[pin_to].name);
}
@ -1830,8 +1830,5 @@ bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* define
if (undefined) {
*undefined = _undefined;
}
if (disconnected) {
*disconnected = _disconnected;
}
return (0 == _undefined && 0 == _disconnected && usb_cable->pin_pairs_nb <= _defined);
return (0 == _undefined && usb_cable->pin_pairs_nb == _defined);
}

View File

@ -116,9 +116,8 @@ bool usb_cables_check_load(const struct usb_connector_t* connector);
* @param[in] usb_cable USB cable to check
* @param[out] defined number of pin pairs that are connected according to definition
* @param[out] undefined number of pin pairs that are connected but not according to definition
* @param[out] disconnected number of pin pairs that are not connected but should according to definition
* @param[in] print print connection errors
* @return if the connections of the cable correspond to the definition
* @note each pair is checked in both directions
*/
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected, bool print);
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, bool print);