add literal str print in asyncmsg (#2113)

* add literal str print in asyncmsg

* remove debug things

* accept suggestion per gull

* fix documentary
This commit is contained in:
sommermorgentraum 2024-04-20 18:31:57 +08:00 committed by GitHub
parent b2da21b88a
commit 03ca87b13e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

1
.gitignore vendored
View File

@ -51,6 +51,7 @@
.dep/
/build*
CMakeFiles/
cmake-build-debug/
# Debugging
.gdbinit*

View File

@ -37,6 +37,8 @@ class UsbSerialAsyncmsg {
template <typename VECTORCOVER>
static void asyncmsg(const std::vector<VECTORCOVER>& 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<int64_t>(const int64_t& data) {
if (!portapack::async_tx_enabled) {
return;
@ -130,6 +133,8 @@ void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path>(const std::filesystem::p
}
/// string
// string obj
template <>
// usage: UsbSerialAsyncmsg::asyncmsg(str);
void UsbSerialAsyncmsg::asyncmsg<std::string>(const std::string& data) {
@ -139,6 +144,15 @@ void UsbSerialAsyncmsg::asyncmsg<std::string>(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 <typename VECTORCOVER>