diff --git a/firmware/application/ui/ui_spectrum.cpp b/firmware/application/ui/ui_spectrum.cpp index 8e7e98ca9..19e7ae47d 100644 --- a/firmware/application/ui/ui_spectrum.cpp +++ b/firmware/application/ui/ui_spectrum.cpp @@ -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(cursor_position, 119); + cursor_position = std::max(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() { diff --git a/firmware/application/ui/ui_spectrum.hpp b/firmware/application/ui/ui_spectrum.hpp index 9d0d70cb9..c8be71b74 100644 --- a/firmware/application/ui/ui_spectrum.hpp +++ b/firmware/application/ui/ui_spectrum.hpp @@ -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 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);