From bea9f444c6c4f8cd6ae725b8db71595997b738ab Mon Sep 17 00:00:00 2001 From: sommermorgentraum <24917424+zxkmm@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:19:29 +0800 Subject: [PATCH] fine tune waveform and ook again (#2322) --- firmware/application/apps/ui_encoders.cpp | 31 ++++++++++++++++++++--- firmware/application/apps/ui_encoders.hpp | 4 ++- firmware/common/ui_widget.cpp | 4 +-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/firmware/application/apps/ui_encoders.cpp b/firmware/application/apps/ui_encoders.cpp index 727796676..da174f6b0 100644 --- a/firmware/application/apps/ui_encoders.cpp +++ b/firmware/application/apps/ui_encoders.cpp @@ -25,6 +25,9 @@ #include "baseband_api.hpp" #include "string_format.hpp" +#define PADDING_LEFT 1 +#define PADDING_RIGHT 1 + using namespace portapack; namespace ui { @@ -154,12 +157,34 @@ void EncodersConfigView::on_show() { } void EncodersConfigView::draw_waveform() { + // padding reason: + // in real world the signal would always start with low level and became low level again after yout turn off the radio; + // the waveform_buffer only controls drawing, the real send logic that been sent is controlled by frame_fragments + // so just for out of looking things + size_t length = frame_fragments.length(); - for (size_t n = 0; n < length; n++) - waveform_buffer[n] = (frame_fragments[n] == '0') ? 0 : 1; + // currently not needed since all the supported OOK protocol wont exceed 550 yet + if (length + (PADDING_LEFT + PADDING_RIGHT) >= WAVEFORM_BUFFER_SIZE) { + length = WAVEFORM_BUFFER_SIZE - (PADDING_LEFT + PADDING_RIGHT); + } + + // padding l + for (size_t i = 0; i < PADDING_LEFT; i++) { + waveform_buffer[i] = 0; + } + + // real wf + for (size_t n = 0; n < length; n++) { + waveform_buffer[n + PADDING_LEFT] = (frame_fragments[n] == '0') ? 0 : 1; + } + + // padding r + for (size_t i = length + PADDING_LEFT; i < WAVEFORM_BUFFER_SIZE; i++) { + waveform_buffer[i] = 0; + } - waveform.set_length(length); + waveform.set_length(length + PADDING_LEFT + PADDING_RIGHT); waveform.set_dirty(); } diff --git a/firmware/application/apps/ui_encoders.hpp b/firmware/application/apps/ui_encoders.hpp index e16618915..39879d490 100644 --- a/firmware/application/apps/ui_encoders.hpp +++ b/firmware/application/apps/ui_encoders.hpp @@ -32,6 +32,8 @@ #include #include +#define WAVEFORM_BUFFER_SIZE 550 + using namespace encoders; namespace ui { @@ -56,7 +58,7 @@ class EncodersConfigView : public View { std::string frame_fragments = "0"; private: - int16_t waveform_buffer[550]; + int16_t waveform_buffer[WAVEFORM_BUFFER_SIZE]; const encoder_def_t* encoder_def{}; void draw_waveform(); diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 11465958d..9f405bb95 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -2681,9 +2681,9 @@ void Waveform::paint(Painter& painter) { x = prev_x + x_inc; h /= 2; - prev_y = y_offset + h + (*(data_start++) * y_scale); + prev_y = y_offset + h - (*(data_start++) * y_scale); for (n = 1; n < length_; n++) { - y = y_offset + h + (*(data_start++) * y_scale); + y = y_offset + h - (*(data_start++) * y_scale); display.draw_line({prev_x, prev_y}, {(Coord)x, y}, color_); prev_x = x;