From bb1c8f4a97a8ac713d38a9cd1e34fad39cc5da14 Mon Sep 17 00:00:00 2001 From: awalol Date: Sat, 9 May 2026 14:22:46 +0800 Subject: [PATCH] add Log Verbose option --- CMakeLists.txt | 7 +++++++ src/bt.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ee574c..c6dff95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,12 @@ if (ENABLE_SERIAL) else () set(ENABLE_SERIAL_VALUE 0) endif () +option(ENABLE_VERBOSE "Enable Log Verbose" OFF) +if(ENABLE_VERBOSE) + set(ENABLE_VERBOSE_VALUE 1) +else() + set(ENABLE_VERBOSE_VALUE 0) +endif () # Pull in Raspberry Pi Pico SDK (must be before project) include(pico_sdk_import.cmake) @@ -81,6 +87,7 @@ target_compile_definitions(ds5-bridge PRIVATE PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS=0 PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE=0 PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=0 + ENABLE_VERBOSE=${ENABLE_VERBOSE_VALUE} ) pico_set_program_name(ds5-bridge "ds5-bridge") diff --git a/src/bt.cpp b/src/bt.cpp index 0cddee5..e766dda 100644 --- a/src/bt.cpp +++ b/src/bt.cpp @@ -360,10 +360,14 @@ static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t if (packet[0] == 0xA3) { uint8_t report_id = packet[1]; feature_data[report_id].assign(packet + 1, packet + size); +#if ENABLE_VERBOSE printf("[L2CAP] Stored Feature Report 0x%02X, len=%u\n", report_id, size - 1); +#endif } +#if ENABLE_VERBOSE printf("[L2CAP] HID Control data len=%u\n", size); printf_hexdump(packet, size); +#endif bt_data_callback(CONTROL, packet, size); } else { printf("[L2CAP] Data on unknown channel 0x%04X (Interrupt: 0x%04X, Control: 0x%04X)\n", @@ -514,7 +518,9 @@ vector get_feature_data(uint8_t reportId, uint16_t len) { if (hid_control_cid != 0) { uint8_t get_feature[] = {0x43, reportId}; l2cap_send(hid_control_cid, get_feature, sizeof(get_feature)); +#if ENABLE_VERBOSE printf("[L2CAP] Requesting Get Feature Report 0x%02X\n", reportId); +#endif } } return ret; @@ -528,8 +534,10 @@ void set_feature_data(uint8_t reportId, uint8_t *data, uint16_t len) { memcpy(get_feature + 2, data, len); fill_feature_report_checksum(get_feature + 1, len + 1); l2cap_send(hid_control_cid, get_feature, len + 2); +#if ENABLE_VERBOSE printf("[L2CAP] Requesting Set Feature Report 0x%02X\n", reportId); printf_hexdump(get_feature, len + 2); +#endif } }