diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 8fab990e..1410d95d 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -225,6 +225,7 @@ set(CPPSRC tone_key.cpp transmitter_model.cpp tuning.cpp + usb_serial_asyncmsg.hpp hw/debounce.cpp hw/encoder.cpp hw/max2837.cpp diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index 7358a854..d6e8ca08 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -156,7 +156,6 @@ void SSTVTXView::start_tx() { // The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before // TX start, and asks for fill-up when a new scanline starts being read. This should // leave enough time for the code in prepare_scanline() before it ends. - scanline_counter = 0; prepare_scanline(); // Preload one scanline diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 7a88b57f..6010c604 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -617,4 +617,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt) { usb_serial.setEventDispatcher(evt); } +bool async_tx_enabled = false; // this is for serial tx things, globally + } /* namespace portapack */ diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index 24eae598..f9f23d6e 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -81,4 +81,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt); Backlight* backlight(); +extern bool async_tx_enabled; // this is for serial tx things, globally + } /* namespace portapack */ diff --git a/firmware/application/usb_serial_asyncmsg.hpp b/firmware/application/usb_serial_asyncmsg.hpp new file mode 100644 index 00000000..58869407 --- /dev/null +++ b/firmware/application/usb_serial_asyncmsg.hpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * Copyleft (ɔ) 2024 zxkmm with the GPL license + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef USB_SERIAL_AYNCMSG_HPP +#define USB_SERIAL_AYNCMSG_HPP + +#include +#include +#include +#include +#include "usb_serial_device_to_host.h" + +class UsbSerialAsyncmsg { + public: + template + static void asyncmsg(const STRINGCOVER& data); + + template + static void asyncmsg(const std::vector& data); +}; + +/*Notes: + * - Don't use MayhemHub since it currently not support real time serial output + * - If you don't use this class linker will drop it so it won't use any space + * - 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" + * 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 + +template <> +// usage: UsbSerialAsyncmsg::asyncmsg(num); +void UsbSerialAsyncmsg::asyncmsg(const int64_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const int32_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const int16_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const int8_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const uint8_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const uint16_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const uint32_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialAsyncmsg::asyncmsg(const uint64_t& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +/// fs things + +template <> +// usage: UsbSerialAsyncmsg::asyncmsg(path); +void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::path& data) { + if (!portapack::async_tx_enabled) { + return; + } + std::string path_str = data.string(); + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", path_str.c_str()); +} + +/// string +template <> +// usage: UsbSerialAsyncmsg::asyncmsg(str); +void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { + if (!portapack::async_tx_enabled) { + return; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); +} + +/// vec worker +// ussgae: UsbSerialAsyncmsg::asyncmsg(vec); +template +void UsbSerialAsyncmsg::asyncmsg(const std::vector& data) { + if (!portapack::async_tx_enabled) { + return; + } + for (const auto& item : data) { + asyncmsg(item); + } +} + +#endif // USB_SERIAL_AYNCMSG_HPP diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 3964e6ed..e260b8b8 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -1131,6 +1131,23 @@ static void cmd_sendpocsag(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, "ok\r\n"); } +static void cmd_asyncmsg(BaseSequentialStream* chp, int argc, char* argv[]) { + const char* usage = "usage: asyncmsg x, x can be enable or disable\r\n"; + if (argc != 1) { + chprintf(chp, usage); + return; + } + if (strcmp(argv[0], "disable") == 0) { + portapack::async_tx_enabled = false; + chprintf(chp, "ok\r\n"); + } else if (strcmp(argv[0], "enable") == 0) { + portapack::async_tx_enabled = true; + chprintf(chp, "ok\r\n"); + } else { + chprintf(chp, usage); + } +} + static const ShellCommand commands[] = { {"reboot", cmd_reboot}, {"dfu", cmd_dfu}, @@ -1162,6 +1179,7 @@ static const ShellCommand commands[] = { {"pmemreset", cmd_pmemreset}, {"settingsreset", cmd_settingsreset}, {"sendpocsag", cmd_sendpocsag}, + {"asyncmsg", cmd_asyncmsg}, {NULL, NULL}}; static const ShellConfig shell_cfg1 = {