application: add fast ground scan

This commit is contained in:
King Kévin 2019-12-31 11:45:32 +01:00
parent bdb5b740db
commit f80f30eb1e
1 changed files with 105 additions and 94 deletions

View File

@ -1385,8 +1385,18 @@ void main(void)
rtc_internal_tick_flag = false; // reset flag
action = true; // action has been performed
if (!interactive) { // periodically check cable when not in interactive mode
// start cable detection
// check if there is a cable by testing the ground connection
bool ground_connected = usb_cables_test_ground(usb_connectors, LENGTH(usb_connectors), NULL);
if (!ground_connected) { // there is no cable
if (cable_current->connections_nb > 0) { // there was a cable before
lcd_hd44780_clear_display(); // be sure the display is cleared
lcd_hd44780_write_line(false, lcd_default_line1, strlen(lcd_default_line1));
lcd_hd44780_write_line(true, lcd_default_line2, strlen(lcd_default_line2));
cable_clear(cable_current); // clear definition
}
goto test_end;
}
// there is a cable, start cable detection
cable_clear(cable_next); // clear definition
cable_detect(cable_next); // detect connected connectors
// if there is a cable, we need to identify it further
@ -1398,7 +1408,9 @@ void main(void)
// compare next to current cable
if (cable_current->connections_nb != cable_next->connections_nb) {
cable_changed = true; // note it changed, but don't do anything until change is confirmed a second time
} else { // same number of connections
goto test_end;
}
// it's a cable with the same number of connections
// check if they are all the same connections (the search order is the same)
bool match = true;
for (uint16_t i = 0; i < cable_current->connections_nb && i < cable_next->connections_nb && match; i++) {
@ -1455,7 +1467,6 @@ void main(void)
snprintf(line, LENGTH(line), "without load");
}
}
} else { // not a perfect match
if (0 == cable_message_i) {
snprintf(line, LENGTH(line), "closest match");
@ -1499,13 +1510,13 @@ void main(void)
lcd_hd44780_write_line(true, line, strlen(line)); // write message
}
}
}
if (cable_changed) {
// next cable because the current one (reuse allocated current for the next)
struct cable_t* cable_tmp = cable_current;
cable_current = cable_next;
cable_next = cable_tmp;
}
test_end:;
} // !interactive
while (!interactive && rtc_get_counter_val() >= last_connect_time + SHUTDOWN_TIMEOUT) { // time to shut down
#if !DEBUG