fine tune waveform and ook again (#2322)

This commit is contained in:
sommermorgentraum 2024-11-04 03:19:29 +08:00 committed by GitHub
parent abd6177303
commit bea9f444c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 6 deletions

View File

@ -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);
}
waveform.set_length(length);
// 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 + PADDING_LEFT + PADDING_RIGHT);
waveform.set_dirty();
}

View File

@ -32,6 +32,8 @@
#include <memory>
#include <vector>
#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();

View File

@ -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;