Merge USB session safety and preserve GPS preference compatibility

This commit is contained in:
mikecarper committed 2026-10-03 16:12:32 -07:00
commit 24fcbf3247
62 files changed
+2479 -240

No files matched your search

+95
View File
@@ -1,6 +1,8 @@
#include <helpers/NonBlockingWriteStream.h>
#include <helpers/nrf52/EthernetCLI.h>
#include "NetworkLoggingMacro.h"
#include <helpers/ui/CHSC6XTouch.h>
#include <helpers/ethernet/ch390/CH390Config.h>
#include <iostream>
@@ -8,6 +10,8 @@ uint32_t mock_millis = 0;
RawSerial Serial;
MockFicr mock_ficr;
MockEthernet Ethernet;
TwoWire Wire;
MockCh390 CH390;
std::string ethernet_output;
std::string ethernet_input;
bool accept_client = false;
@@ -153,5 +157,96 @@ int main() {
assert(evaluated == 0 && usb.output.empty() && usb.tries == 0);
#endif
assert(mock_millis == 0);
// Touch probe, late-presence and optional raw frames use the same runtime
// logging gate as every other diagnostic, including protected boot mode.
reset();
logging_enabled = false;
Wire = TwoWire();
CHSC6XTouch found;
assert(found.begin());
Wire.frame[0] = 0x1F;
assert(!found.checkTap(500));
assert(found.checkTap(600));
assert(usb.output.empty() && usb.tries == 0);
Wire = TwoWire();
Wire.present = false;
CHSC6XTouch late;
assert(!late.begin());
assert(Wire.probes == 1); // No diagnostic I2C scan when logging is off.
Wire.present = true;
Wire.frame[0] = 0x1F;
assert(!late.checkTap(500));
assert(late.checkTap(600));
Wire.reply_length = 2;
late.checkTap(700);
assert(usb.output.empty() && usb.tries == 0);
reset();
debug_enabled = false;
Wire = TwoWire();
CHSC6XTouch packet_only;
assert(packet_only.begin());
Wire.frame[0] = 0x1F;
assert(!packet_only.checkTap(500));
assert(packet_only.checkTap(600));
assert(logging_enabled && usb.output.empty() && usb.tries == 0);
Wire = TwoWire();
Wire.present = false;
CHSC6XTouch quiet_scan;
assert(!quiet_scan.begin() && Wire.probes == 1);
reset();
Wire = TwoWire();
CHSC6XTouch visible;
assert(visible.begin());
assert(usb.output == "Touch: CHSC6X found at 0x2E\n");
visible.checkTap(500);
#if defined(DISPLAY_TOUCH_DEBUG)
assert(usb.output.find("Touch: raw 00 01 02 03 04") != std::string::npos);
#endif
usb.output.clear();
usb.capacity = 0;
CHSC6XTouch stalled;
assert(stalled.begin());
stalled.checkTap(500);
assert(usb.output.empty());
reset();
Wire = TwoWire();
Wire.present = false;
Wire.all_addresses_present = false;
CHSC6XTouch absent;
assert(!absent.begin());
assert(usb.output.find("Touch: idle or absent at 0x2E; I2C bus currently answers:\n") == 0);
assert(Wire.probes == 113);
reset();
usb.capacity = 640;
Wire = TwoWire();
Wire.all_addresses_present = true;
Wire.fail_probe_count = 1; // Idle boot probe, then every scan address replies.
CHSC6XTouch full_scan;
assert(!full_scan.begin());
assert(usb.output.size() > 600 && usb.output.size() < 640 && usb.tries == 1);
assert(usb.output.substr(usb.output.size() - 6) == " 0x77\n");
reset();
CH390 = MockCh390();
logging_enabled = false;
assert(beginConfiguredCH390("invalid hostname"));
assert(CH390.begins == 1 && usb.output.empty() && usb.tries == 0);
logging_enabled = true;
debug_enabled = false;
assert(beginConfiguredCH390("invalid hostname"));
assert(usb.output.empty() && usb.tries == 0);
debug_enabled = true;
assert(beginConfiguredCH390("invalid hostname"));
assert(usb.output == "Network: invalid Ethernet hostname invalid hostname\n");
usb.output.clear();
usb.capacity = 0;
assert(beginConfiguredCH390("invalid hostname"));
assert(usb.output.empty());
std::cout << "PASS: gated USB diagnostics\n";
}