application: add load test to find action

This commit is contained in:
King Kévin 2019-12-26 18:03:47 +01:00
parent 6b228c18af
commit 66529b28af
1 changed files with 37 additions and 0 deletions

View File

@ -139,6 +139,7 @@ struct cable_t {
uint8_t (*connections)[2]; // the cable connections (pin pairs)
uint8_t connectors_nb; // number of connectors the cable has
bool connectors[LENGTH(usb_connectors)]; // which connectors the cable connects
bool load; // if there is a load on the cable
uint8_t cables_nb; // number of cable definitions the connectors set match to
bool cables[LENGTH(usb_cables)]; // cable definitions the connectors set match to
uint16_t unconnected_nb[LENGTH(usb_cables)]; // number of unconnected pairs which should be connected according to cable specification
@ -251,6 +252,38 @@ static void cable_connectors(struct cable_t* cable)
}
}
/** find if there is a load on any of the connectors of the cable
* @param[in,out] cable cable for which to if there is a load
* @note only updates load based on connectors
*/
static void cable_load(struct cable_t* cable)
{
// check input arguments
if (NULL == cable) {
return;
}
// initialize relevant structure variables
cable->load = false;
// ensure connections are available
if (0 == cable->connectors_nb) {
return;
}
// test of there is a load on any of the connectors of the cable
for (uint8_t i = 0; i < LENGTH(cable->connectors) && i < LENGTH(usb_connectors) && !cable->load; i++) {
if (!cable->connectors[i]) {
continue;
}
const struct usb_connector_t* connector = usb_connectors[i];
bool load = usb_cables_test_load(connector);
if (load) {
cable->load = true;
}
}
}
/** find which cables match the connector set
* @param[in,out] cable cable for which to find matching cable definitions
* @note only updates cables_nb and cables based on connectors
@ -621,6 +654,9 @@ static void command_find(void* argument)
printf("- %02u %s\n", cable_i, usb_cables[cable_i].name);
}
// check if there is a load
cable_load(&cable);
// calculate score for cables
cable_issues_nb(&cable);
if (!print_lcd) {
@ -711,6 +747,7 @@ static void command_find(void* argument)
printf("%s\n", usb_pins[cable.unspecified[i][1]].name);
}
}
printf("there is %s load in the cable\n", cable.load ? "a" : "no");
end:
usb_pins_float(); // put all pins back in safe floating state