This commit is contained in:
zxkmm 2025-04-12 11:35:25 +08:00
parent 319ed3e7b4
commit b79dd08dc3
2 changed files with 41 additions and 0 deletions

View File

@ -102,6 +102,15 @@ void FrequencyScale::set_channel_filter(
}
}
void FrequencyScale::set_cursor_position(const int32_t position) {
cursor_position = position;
cursor_position = std::min<int32_t>(cursor_position, 119);
cursor_position = std::max<int32_t>(cursor_position, -120);
set_dirty();
}
void FrequencyScale::paint(Painter& painter) {
const auto r = screen_rect();
@ -242,6 +251,15 @@ bool FrequencyScale::on_key(const KeyEvent key) {
return false;
}
bool FrequencyScale::on_touch(const TouchEvent touch) {
if (touch.type == TouchEvent::Type::Start) {
if (on_select) {
on_select((touch.point.x() * spectrum_sampling_rate) / 240);
}
}
return true;
}
void FrequencyScale::on_tick_second() {
set_dirty();
_blink = !_blink;
@ -287,6 +305,15 @@ void WaterfallWidget::on_channel_spectrum(
pixel_row);
}
bool WaterfallWidget::on_touch(const TouchEvent event) {
if (event.type == TouchEvent::Type::Start) {
if (on_touch_select) {
on_touch_select(event.point.x());
}
}
return true;
}
void WaterfallWidget::clear() {
display.fill_rectangle(
screen_rect(),
@ -305,6 +332,15 @@ WaterfallView::WaterfallView(const bool cursor) {
frequency_scale.on_select = [this](int32_t offset) {
if (on_select) on_select(offset);
};
// Add touch event handler for waterfall widget
waterfall_widget.on_touch_select = [this](int32_t x) {
if (sampling_rate) {
// screen x to frequency scale x, NB we need two widgets aligh
int32_t cursor_position = x - (screen_width / 2);
frequency_scale.set_cursor_position(cursor_position);
}
};
}
void WaterfallView::on_show() {

View File

@ -78,9 +78,11 @@ class FrequencyScale : public Widget {
bool on_encoder(const EncoderEvent delta) override;
bool on_key(const KeyEvent key) override;
bool on_touch(const TouchEvent touch) override;
void set_spectrum_sampling_rate(const int new_sampling_rate);
void set_channel_filter(const int low_frequency, const int high_frequency, const int transition);
void set_cursor_position(const int32_t position);
void paint(Painter& painter) override;
@ -111,9 +113,12 @@ class FrequencyScale : public Widget {
class WaterfallWidget : public Widget {
public:
std::function<void(int32_t offset)> on_touch_select{};
void on_show() override;
void on_hide() override;
void paint(Painter&) override {}
bool on_touch(const TouchEvent event) override;
void on_channel_spectrum(const ChannelSpectrum& spectrum);