From b892b3f9096c2664b52cb5efe3d636b34978c8f0 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:59:59 +0800 Subject: [PATCH] Add more data in ESP420 for USB Port when connected --- esp3d/src/core/commands/ESP420.cpp | 9 +++++++ .../modules/usb-serial/usb_serial_service.cpp | 26 +++++++++++++++++++ .../modules/usb-serial/usb_serial_service.h | 5 ++++ 3 files changed, 40 insertions(+) diff --git a/esp3d/src/core/commands/ESP420.cpp b/esp3d/src/core/commands/ESP420.cpp index 1a2d30f2..da4cb85a 100644 --- a/esp3d/src/core/commands/ESP420.cpp +++ b/esp3d/src/core/commands/ESP420.cpp @@ -240,6 +240,15 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) { return; } } + if (esp3d_usb_serial_service.isConnected()) { + tmpstr = esp3d_usb_serial_service.getVIDString(); + tmpstr += ":"; + tmpstr += esp3d_usb_serial_service.getPIDString(); + if (!dispatchIdValue(json, "Vid/Pid", tmpstr.c_str(), target, requestId, + false)) { + return; + } + } #endif // defined(USB_SERIAL_FEATURE) #if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL diff --git a/esp3d/src/modules/usb-serial/usb_serial_service.cpp b/esp3d/src/modules/usb-serial/usb_serial_service.cpp index a4450bb4..25ccd2da 100644 --- a/esp3d/src/modules/usb-serial/usb_serial_service.cpp +++ b/esp3d/src/modules/usb-serial/usb_serial_service.cpp @@ -255,6 +255,32 @@ void ESP3DUsbSerialService::connectDevice() { } } +const char *ESP3DUsbSerialService::getVIDString() { + if (_vcp_ptr && _is_connected) { + return esp_usb::getVIDString(); + } + return "None"; +} +const char *ESP3DUsbSerialService::getPIDString() { + if (_vcp_ptr && _is_connected) { + return esp_usb::getPIDString(); + } + return "None"; +} + +uint16_t ESP3DUsbSerialService::getVID() { + if (_vcp_ptr && _is_connected) { + return esp_usb::getVID(); + } + return 0; +} +uint16_t ESP3DUsbSerialService::getPID() { + if (_vcp_ptr && _is_connected) { + return esp_usb::getPID(); + } + return 0; +} + // Setup Serial bool ESP3DUsbSerialService::begin() { _buffer_mutex = xSemaphoreCreateMutex(); diff --git a/esp3d/src/modules/usb-serial/usb_serial_service.h b/esp3d/src/modules/usb-serial/usb_serial_service.h index cf320aa8..cfdbd65b 100644 --- a/esp3d/src/modules/usb-serial/usb_serial_service.h +++ b/esp3d/src/modules/usb-serial/usb_serial_service.h @@ -56,6 +56,11 @@ class ESP3DUsbSerialService final { void connectDevice(); void setConnected(bool connected); void receiveCb(const uint8_t *data, size_t data_len, void *arg = nullptr); + bool isConnected() { return _is_connected; } + const char * getVIDString(); + const char * getPIDString(); + uint16_t getVID(); + uint16_t getPID(); private: uint32_t _baudRate;