From 19491ce3f72c96e877abbdf7377147a6ac9af999 Mon Sep 17 00:00:00 2001 From: Kyle Reed Date: Mon, 12 Jun 2023 23:14:26 -0700 Subject: [PATCH] Add debug_log, fix tx_bht (#1149) --- firmware/application/app_settings.cpp | 13 ------------- firmware/application/apps/ui_bht_tx.cpp | 15 +++++++-------- firmware/application/debug.cpp | 14 ++++++++++++++ firmware/application/debug.hpp | 6 ++++++ firmware/application/protocols/bht.cpp | 4 +++- firmware/common/ui_widget.cpp | 4 ++-- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/firmware/application/app_settings.cpp b/firmware/application/app_settings.cpp index 7d662dbd..ccd5e8ba 100644 --- a/firmware/application/app_settings.cpp +++ b/firmware/application/app_settings.cpp @@ -36,19 +36,6 @@ namespace fs = std::filesystem; using namespace portapack; using namespace std::literals; -/*#include "log_file.hpp" -LogFile* g_pLog = nullptr; -static void log_it(const std::string& msg) { - static LogFile s_log; - if (g_pLog == nullptr) { - delete_file("appset.txt"); - s_log.append("appset.txt"); - g_pLog = &s_log; - } - - g_pLog->write_entry(msg); -}*/ - namespace app_settings { template diff --git a/firmware/application/apps/ui_bht_tx.cpp b/firmware/application/apps/ui_bht_tx.cpp index 82143971..e8c61856 100644 --- a/firmware/application/apps/ui_bht_tx.cpp +++ b/firmware/application/apps/ui_bht_tx.cpp @@ -220,7 +220,6 @@ EPARView::EPARView( field_city.set_value(0); field_group.set_selected_index(2); - field_city.on_change = [this](int32_t) { generate_message(); }; field_group.on_change = [this](size_t, int32_t) { generate_message(); }; @@ -230,11 +229,11 @@ EPARView::EPARView( size_t n = 0; for (auto& relay_state : relay_states) { - relay_state.on_change = relay_state_fn; relay_state.set_parent_rect({static_cast(90 + (n * 36)), 80, 24, 24}); relay_state.set_options(relay_options); + relay_state.on_change = relay_state_fn; // NB: set after set_options to avoid startup call. add_child(&relay_state); n++; } @@ -303,11 +302,11 @@ XylosView::XylosView( }; field_header_a.on_change = field_fn; - field_header_b.on_change = [this](int32_t) { generate_message(); }; - field_city.on_change = [this](int32_t) { generate_message(); }; - field_family.on_change = [this](int32_t) { generate_message(); }; - field_subfamily.on_change = [this](int32_t) { generate_message(); }; - field_receiver.on_change = [this](int32_t) { generate_message(); }; + field_header_b.on_change = field_fn; + field_city.on_change = field_fn; + field_family.on_change = field_fn; + field_subfamily.on_change = field_fn; + field_receiver.on_change = field_fn; checkbox_wcsubfamily.on_select = [this](Checkbox&, bool v) { field_subfamily.set_focusable(!v); @@ -328,11 +327,11 @@ XylosView::XylosView( size_t n = 0; for (auto& relay_state : relay_states) { - relay_state.on_change = relay_state_fn; relay_state.set_parent_rect({static_cast(54 + (n * 36)), 134, 24, 24}); relay_state.set_options(relay_options); + relay_state.on_change = relay_state_fn; // NB: set after set_options to avoid startup call. add_child(&relay_state); n++; } diff --git a/firmware/application/debug.cpp b/firmware/application/debug.cpp index b6d151c8..2df10015 100644 --- a/firmware/application/debug.cpp +++ b/firmware/application/debug.cpp @@ -26,12 +26,26 @@ #include #include +#include "log_file.hpp" #include "portapack.hpp" #include "string_format.hpp" #include "ui_styles.hpp" using namespace ui; +#define DEBUG_LOG_FILE "debug_log.txt" +LogFile* pg_debug_log = nullptr; +void __debug_log(const std::string& msg) { + static LogFile s_log; + if (pg_debug_log == nullptr) { + delete_file(DEBUG_LOG_FILE); + s_log.append(DEBUG_LOG_FILE); + pg_debug_log = &s_log; + } + + pg_debug_log->write_entry(msg); +} + void runtime_error(LED); std::string number_to_hex_string(uint32_t); void draw_line(int32_t, const char*, regarm_t); diff --git a/firmware/application/debug.hpp b/firmware/application/debug.hpp index 995f851e..ce265a18 100644 --- a/firmware/application/debug.hpp +++ b/firmware/application/debug.hpp @@ -24,6 +24,12 @@ #define __DEBUG_H__ #include "hackrf_gpio.hpp" +#include + +void __debug_log(const std::string& msg); +#define __LOG2(l, msg) __debug_log(std::string{#l} + ":" + msg) +#define __LOG1(l, msg) __LOG2(l, msg) +#define DEBUG_LOG(msg) __LOG1(__LINE__, msg) extern void draw_guru_meditation(uint8_t, const char*); extern void draw_guru_meditation(uint8_t, const char*, struct extctx*, uint32_t); diff --git a/firmware/application/protocols/bht.cpp b/firmware/application/protocols/bht.cpp index 6291caee..1abe90e0 100644 --- a/firmware/application/protocols/bht.cpp +++ b/firmware/application/protocols/bht.cpp @@ -28,7 +28,9 @@ size_t gen_message_ep(uint8_t city_code, size_t family_code_ep, uint32_t relay_n const encoder_def_t* um3750_def; uint8_t bits[12]; std::string ep_fragments; - // char ep_message[13] = { 0 }; + + // Pre-allocate to avoid fragmentation. + ep_fragments.reserve(384); // Repeated 2x 26 times // Whole frame + space = 128ms, data only = 64ms diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 7b17a83a..e5e05302 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -1358,7 +1358,7 @@ void ImageOptionsField::set_selected_index(const size_t new_index) { } void ImageOptionsField::set_by_value(value_t v) { - size_t new_index{0}; + size_t new_index = 0; for (const auto& option : options) { if (option.second == v) { set_selected_index(new_index); @@ -1377,7 +1377,7 @@ void ImageOptionsField::set_options(options_t new_options) { // Set an invalid index to force on_change. selected_index_ = (size_t)-1; - set_by_value(0); + set_selected_index(0); set_dirty(); }