Skip to content

Commit

Permalink
add shift feat for protcol view tool (#2258)
Browse files Browse the repository at this point in the history
* add shift

* add shift

* format

* add padding (wrote by AI)

* layout fine tune

* remove debug thing

* edit per request

* remove torjan (jk)

* int 16 should be good enough for it
  • Loading branch information
zxkmm authored Sep 22, 2024
1 parent 89b5109 commit 9390317
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
27 changes: 22 additions & 5 deletions firmware/application/external/protoview/ui_protoview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ProtoView::ProtoView(NavigationView& nav)
&field_frequency,
&labels,
&options_zoom,
&number_shift,
&button_reset,
&waveform,
&waveform2,
Expand All @@ -63,6 +64,11 @@ ProtoView::ProtoView(NavigationView& nav)
draw();
draw2();
};
number_shift.on_change = [this](int32_t value) {
waveform_shift = value;
draw();
draw2();
};
button_reset.on_select = [this](Button&) {
reset();
};
Expand All @@ -74,6 +80,8 @@ ProtoView::ProtoView(NavigationView& nav)

void ProtoView::reset() {
cnt = 0;
number_shift.set_value(0);
waveform_shift = 0;
for (uint16_t i = 0; i < MAXSIGNALBUFFER; i++) time_buffer[i] = 0;
needCntReset = false;
draw();
Expand Down Expand Up @@ -126,9 +134,19 @@ void ProtoView::draw() {
drawcnt = 0;
for (uint16_t i = 0; i < MAXDRAWCNT; i++) waveform_buffer[i] = 0; // reset

for (uint16_t i = 0; i < MAXSIGNALBUFFER; ++i) {
state = time_buffer[i] >= 0;
int32_t timeabs = state ? time_buffer[i] : -1 * time_buffer[i];
// add empty data for padding (so you can shift left/nagetive)
for (int32_t i = 0;
i < ((waveform_shift > 0) ? 0 : -waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift nagetive (left side)
++i) {
waveform_buffer[drawcnt++] = 0;
}

for (uint16_t i = ((waveform_shift < 0) ? -waveform_shift : 0); // this is for shift positive aka right side
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
++i) {
uint16_t buffer_index = (i + waveform_shift + MAXSIGNALBUFFER) % MAXSIGNALBUFFER;
state = time_buffer[buffer_index] >= 0;
int32_t timeabs = state ? time_buffer[buffer_index] : -1 * time_buffer[buffer_index];
int32_t timesize = timeabs / zoom;
if (timesize == 0) {
remain += timeabs;
Expand All @@ -145,9 +163,8 @@ void ProtoView::draw() {
}
remain = 0;
lmax = 0;
for (int32_t ii = 0; ii < timesize; ++ii) {
for (int32_t ii = 0; ii < timesize && drawcnt < MAXDRAWCNT; ++ii) {
waveform_buffer[drawcnt++] = state;
if (drawcnt >= MAXDRAWCNT) return;
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions firmware/application/external/protoview/ui_protoview.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
Expand Down Expand Up @@ -76,7 +75,8 @@ class ProtoView : public View {
{0 * 8, 0 * 16},
nav_};
Labels labels{
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground}};
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 2 * 16}, "Shift: ", Theme::getInstance()->fg_light->foreground}};

OptionsField options_zoom{
{7 * 8, 1 * 16},
Expand All @@ -92,36 +92,43 @@ class ProtoView : public View {
{"500", 500},
{"1000", 1000}}};

NumberField number_shift{
{7 * 8, 2 * 16},
5,
{-MAXSIGNALBUFFER, MAXSIGNALBUFFER},
1,
' '};

Button button_reset{
{screen_width - 12 * 8, 1 * 16, 96, 24},
LanguageHelper::currentMessages[LANG_RESET]};

Waveform waveform{
{0, 5 * 8, 240, 50},
{0, 8 * 8, 240, 50},
waveform_buffer,
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};

Waveform waveform2{
{0, 5 * 8 + 55, 240, 50},
{0, 8 * 8 + 55, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF],
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};

Waveform waveform3{
{0, 5 * 8 + 110, 240, 50},
{0, 8 * 8 + 110, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF * 2],
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};

Waveform waveform4{
{0, 5 * 8 + 165, 240, 50},
{0, 8 * 8 + 165, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF * 3],
0,
0,
Expand All @@ -131,6 +138,7 @@ class ProtoView : public View {
bool needCntReset = false;

int16_t zoom = 1; // one value in ms
int16_t waveform_shift = 0;

uint16_t cnt = 0; // pointer to next element
uint16_t drawcnt = 0; // pointer to draw next element
Expand Down Expand Up @@ -170,4 +178,4 @@ class ProtoView : public View {

} // namespace ui::external_app::protoview

#endif /*__UI_PROTOVIEW_H__*/
#endif /*__UI_PROTOVIEW_H__*/

0 comments on commit 9390317

Please sign in to comment.