From e75fb59169c6356534f522980997b27e3d96022b Mon Sep 17 00:00:00 2001 From: sommermorgentraum <24917424+zxkmm@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:17:40 +0800 Subject: [PATCH] fix issue from #1444 (#2278) --- firmware/application/apps/ui_encoders.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/firmware/application/apps/ui_encoders.cpp b/firmware/application/apps/ui_encoders.cpp index 60d386a0..72779667 100644 --- a/firmware/application/apps/ui_encoders.cpp +++ b/firmware/application/apps/ui_encoders.cpp @@ -58,6 +58,7 @@ EncodersConfigView::EncodersConfigView( options_enctype.on_change = [this](size_t index, int32_t) { on_type_change(index); + set_dirty(); }; options_enctype.set_options(enc_options); @@ -104,7 +105,18 @@ void EncodersConfigView::on_type_change(size_t index) { // Add new SymFields. Point pos{2 * 8, 9 * 8}; - std::string format_string; + std::string format_string = encoder_def->word_format; + + /*important notes of this format_String + * previously before PR#1444, this code using the for loop below to generate the format_string, which MAYBE to prevent showing the S symble. + * but after PR#1444, the entireh of symfield code not compatible with this design anymore. + * however the encoder_def struct itself has a field called word_format, which exactly be avle to use as the format_string, + * because itself is ONLY a hint text, not impact protocol things. + * When you find OOK protocol is broken and see this commit from git blame, please be aware that it's not from here. + * previously me and @cusspvz already found it broken, this commit is just to fix the broken that from PR#1444. + * @zxkmm + */ + uint8_t word_length = encoder_def->word_length; auto on_change_handler = [this](SymField&) { generate_frame(); @@ -119,11 +131,9 @@ void EncodersConfigView::on_type_change(size_t index) { switch (symbol_type) { case 'A': symfield->set_symbol_list(encoder_def->address_symbols); - format_string += 'A'; break; case 'D': symfield->set_symbol_list(encoder_def->data_symbols); - format_string += 'D'; break; } @@ -131,8 +141,8 @@ void EncodersConfigView::on_type_change(size_t index) { pos += Point{8, 0}; } - // Ugly :( Pad to erase - format_string.append(24 - format_string.size(), ' '); + // cut the S, cuz sync bit isn't in symfield for user to chage/edit. + format_string.erase(std::remove(format_string.begin(), format_string.end(), 'S'), format_string.end()); text_format.set(format_string); generate_frame();