diff --git a/firmware/application/usb_serial.hpp b/firmware/application/usb_serial.hpp index af3f2c4e..59cddd8a 100644 --- a/firmware/application/usb_serial.hpp +++ b/firmware/application/usb_serial.hpp @@ -37,6 +37,8 @@ class USBSerial { void on_channel_closed(); void setEventDispatcher(EventDispatcher* ed) { _eventDispatcher = ed; } + bool serial_connected() { return connected; } + private: void enable_xtal(); void disable_pll0(); @@ -51,4 +53,4 @@ class USBSerial { EventDispatcher* _eventDispatcher = NULL; }; -} // namespace portapack \ No newline at end of file +} // namespace portapack diff --git a/firmware/application/usb_serial_asyncmsg.cpp b/firmware/application/usb_serial_asyncmsg.cpp index f94277b0..c46c57f1 100644 --- a/firmware/application/usb_serial_asyncmsg.cpp +++ b/firmware/application/usb_serial_asyncmsg.cpp @@ -23,6 +23,7 @@ */ #include "usb_serial_asyncmsg.hpp" +#include "usb_serial.hpp" /// value // to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here @@ -30,7 +31,7 @@ template <> void UsbSerialAsyncmsg::asyncmsg(const int64_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -38,7 +39,7 @@ void UsbSerialAsyncmsg::asyncmsg(const int64_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const int32_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -46,7 +47,7 @@ void UsbSerialAsyncmsg::asyncmsg(const int32_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const int16_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -54,7 +55,7 @@ void UsbSerialAsyncmsg::asyncmsg(const int16_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const int8_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -62,7 +63,7 @@ void UsbSerialAsyncmsg::asyncmsg(const int8_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const uint8_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -70,7 +71,7 @@ void UsbSerialAsyncmsg::asyncmsg(const uint8_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const uint16_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -78,7 +79,7 @@ void UsbSerialAsyncmsg::asyncmsg(const uint16_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const uint32_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -86,7 +87,7 @@ void UsbSerialAsyncmsg::asyncmsg(const uint32_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const uint64_t& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); @@ -94,7 +95,7 @@ void UsbSerialAsyncmsg::asyncmsg(const uint64_t& data) { template <> void UsbSerialAsyncmsg::asyncmsg(const float& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_decimal(data, 7).c_str()); @@ -105,7 +106,7 @@ void UsbSerialAsyncmsg::asyncmsg(const float& data) { template <> // usage: UsbSerialAsyncmsg::asyncmsg(path); void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::path& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } std::string path_str = data.string(); @@ -114,7 +115,7 @@ void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::p template <> void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::path::string_type& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } std::string str_data(data.begin(), data.end()); @@ -127,7 +128,7 @@ void UsbSerialAsyncmsg::asyncmsg(const std:: template <> // usage: UsbSerialAsyncmsg::asyncmsg(str); void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); @@ -136,7 +137,7 @@ void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { // string literal AKA char[] // usage: UsbSerialAsyncmsg::asyncmsg("abc"); void UsbSerialAsyncmsg::asyncmsg(const char* data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data); @@ -146,8 +147,8 @@ void UsbSerialAsyncmsg::asyncmsg(const char* data) { template <> // usage: UsbSerialAsyncmsg::asyncmsg(true); void UsbSerialAsyncmsg::asyncmsg(const bool& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data ? "true" : "false"); -} \ No newline at end of file +} diff --git a/firmware/application/usb_serial_asyncmsg.hpp b/firmware/application/usb_serial_asyncmsg.hpp index fc57148e..35ed7565 100644 --- a/firmware/application/usb_serial_asyncmsg.hpp +++ b/firmware/application/usb_serial_asyncmsg.hpp @@ -61,7 +61,7 @@ class UsbSerialAsyncmsg { // ussgae: UsbSerialAsyncmsg::asyncmsg(vec); template void UsbSerialAsyncmsg::asyncmsg(const std::vector& data) { - if (!portapack::async_tx_enabled) { + if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) { return; } for (const auto& item : data) {