Skip to content

Commit

Permalink
fine tune waveform and ook again (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxkmm authored Nov 3, 2024
1 parent abd6177 commit bea9f44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
31 changes: 28 additions & 3 deletions firmware/application/apps/ui_encoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion firmware/application/apps/ui_encoders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <memory>
#include <vector>

#define WAVEFORM_BUFFER_SIZE 550

using namespace encoders;

namespace ui {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions firmware/common/ui_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bea9f44

Please sign in to comment.