From 03ca87b13eeaeb6693b7410f8aba78b44d22351e Mon Sep 17 00:00:00 2001 From: sommermorgentraum <24917424+zxkmm@users.noreply.github.com> Date: Sat, 20 Apr 2024 18:31:57 +0800 Subject: [PATCH] add literal str print in asyncmsg (#2113) * add literal str print in asyncmsg * remove debug things * accept suggestion per gull * fix documentary --- .gitignore | 1 + firmware/application/usb_serial_asyncmsg.hpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 52f03525..d7ab86ca 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ .dep/ /build* CMakeFiles/ +cmake-build-debug/ # Debugging .gdbinit* diff --git a/firmware/application/usb_serial_asyncmsg.hpp b/firmware/application/usb_serial_asyncmsg.hpp index 58869407..17b22f84 100644 --- a/firmware/application/usb_serial_asyncmsg.hpp +++ b/firmware/application/usb_serial_asyncmsg.hpp @@ -37,6 +37,8 @@ class UsbSerialAsyncmsg { template static void asyncmsg(const std::vector& data); + + static void asyncmsg(const char* data); // string literal }; /*Notes: @@ -45,15 +47,16 @@ class UsbSerialAsyncmsg { * - so delete all debug things before you push your code to production * - use this client to filter only PP devices: https://github.com/zxkmm/Pyserial-Demo-portapack * - usage: - * #include "usb_serial_debug_bridge.hpp" + * portapack::async_tx_enabled = true; // note that use this when debugging, unless the msg would be forbidden. but don't use this in production, since it's not real async and multiple serial transmittions will broken each other. if this class is used in other scene in the future, just use command to cover (protect your serial tramsnitton) in your extern thing: asyncmsg enable --- your cmd --- asyncmsg disable + * #include "usb_serial_asyncmsg.cpp" * UsbSerialAsyncmsg::asyncmsg("Hello PP"); * */ /// 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 +// usage: UsbSerialAsyncmsg::asyncmsg(num); template <> -// usage: UsbSerialAsyncmsg::asyncmsg(num); void UsbSerialAsyncmsg::asyncmsg(const int64_t& data) { if (!portapack::async_tx_enabled) { return; @@ -130,6 +133,8 @@ void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::p } /// string + +// string obj template <> // usage: UsbSerialAsyncmsg::asyncmsg(str); void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { @@ -139,6 +144,15 @@ void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); } +// string literal AKA char[] +// usage: UsbSerialAsyncmsg::asyncmsg("abc"); +void UsbSerialAsyncmsg::asyncmsg(const char* data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data); +} + /// vec worker // ussgae: UsbSerialAsyncmsg::asyncmsg(vec); template