mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-20 14:39:01 +00:00
b048b8f4f1
* Add sliding-frequency audio receiver tuning * Move ADS-B receiver to external app * Move AIS receiver to external app * Move APRS receiver to external app * Move APRS transmitter to external app * Isolate filtered spectrum collection from WFM * Fixed the issues #3280 * fpga_bridge.c: init registers per reference fpga_init, add quarter-shift mode setter * radio.hpp: expose cached FPGA quarter-rate shift * radio.cpp: program FPGA quarter-rate shift together with tuning offset * tuning.hpp: pass AFE rate and direction to tuning config, add quarter_shift field * tuning.cpp: import full PRALINE RX/TX tuning tables with quarter-shift offsets * clock_manager: stop writing bogus RX digital gain, keep quarter shift across rate changes * receiver_model: port LPF bandwidth from reference auto_bandwidth, use cached quarter shift * adsb_rx: enable RF amp by default on first run * ui_geomap.hpp: add hemisphere fields, degrees become magnitude * ui_geomap: use hemisphere selector for lat/lon sign, fix minute/second wrap carry * ui_menu: guard select against empty menu * waterfall_designer: header updates for profile file handling * waterfall_designer: exception-free profile parsing, CRLF handling, deferred nav callbacks, backup cleanup * external.ld: scope app section globs to their own object directories * CMakeLists: relink when external.ld changes * tools: add external app symbol placement checker * tools: add guru meditation address lookup script * tools: add per-function stack usage report script Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
228 lines
7.1 KiB
C++
228 lines
7.1 KiB
C++
/*
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
* copyleft 2025 zxkmm
|
|
*
|
|
* This file is part of PortaPack.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
* Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#ifndef __UI_SPECTRUM_H__
|
|
#define __UI_SPECTRUM_H__
|
|
|
|
#include "ui.hpp"
|
|
#include "ui_widget.hpp"
|
|
#include "gradient.hpp"
|
|
|
|
#include "event_m0.hpp"
|
|
|
|
#include "message.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
|
|
namespace ui {
|
|
namespace spectrum {
|
|
|
|
class AudioSpectrumView : public View {
|
|
public:
|
|
AudioSpectrumView(const Rect parent_rect);
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
void on_audio_spectrum(const AudioSpectrum* spectrum);
|
|
|
|
private:
|
|
static constexpr int cursor_band_height = 4;
|
|
|
|
int16_t audio_spectrum[128]{0};
|
|
|
|
Labels labels{
|
|
{{6 * 8, UI_POS_Y(0)}, "Hz", Theme::getInstance()->fg_light->foreground}};
|
|
|
|
NumberField field_frequency{
|
|
{UI_POS_X(0), UI_POS_Y(0)},
|
|
5,
|
|
{0, 48000},
|
|
48000 / 240,
|
|
' '};
|
|
|
|
Waveform waveform{
|
|
{0, 1 * 16 + cursor_band_height, screen_width, 2 * 16},
|
|
audio_spectrum,
|
|
128,
|
|
0,
|
|
false,
|
|
Theme::getInstance()->bg_darkest->foreground,
|
|
true};
|
|
};
|
|
|
|
class FrequencyScale : public Widget {
|
|
public:
|
|
/* Receives a frequency offset in Hz for key/touch selection. With live
|
|
* tuning enabled, encoder events instead pass the raw encoder delta. */
|
|
std::function<void(int32_t offset)> on_select{};
|
|
|
|
void on_show() override;
|
|
void on_focus() override;
|
|
void on_blur() override;
|
|
|
|
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 offset, const int low_frequency, const int high_frequency, const int transition);
|
|
void set_cursor_position(const int32_t position);
|
|
void set_live_tuning(const bool enabled) { live_tuning = enabled; }
|
|
bool is_live_tuning() const { return live_tuning; }
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
private:
|
|
static constexpr int filter_band_height = 4;
|
|
|
|
int32_t cursor_position{0};
|
|
int spectrum_sampling_rate{0};
|
|
const int spectrum_bins = std::tuple_size<decltype(ChannelSpectrum::db)>::value;
|
|
int channel_filter_offset{0};
|
|
int channel_filter_low_frequency{0};
|
|
int channel_filter_high_frequency{0};
|
|
int channel_filter_transition{0};
|
|
bool live_tuning{false};
|
|
|
|
void clear();
|
|
void clear_background(Painter& painter, const Rect r);
|
|
|
|
void draw_frequency_ticks(Painter& painter, const Rect r);
|
|
void draw_filter_ranges(Painter& painter, const Rect r);
|
|
void redraw_filter_cursor(const int old_offset);
|
|
void restore_tick_lines(Painter& painter, const Rect r, const Rect dirty);
|
|
};
|
|
|
|
/* NB: These visualizations rely on having a baseband image running.
|
|
* If the baseband is shutdown or otherwise not running when interacting
|
|
* with these, they will almost certainly hang the device. */
|
|
|
|
class WaterfallWidget : public Widget {
|
|
public:
|
|
std::function<void(int32_t offset, int32_t y)> on_touch_select{};
|
|
|
|
Gradient gradient{};
|
|
|
|
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);
|
|
|
|
private:
|
|
void clear();
|
|
};
|
|
|
|
class WaterfallView : public View {
|
|
public:
|
|
std::function<void(int32_t offset)> on_select{};
|
|
|
|
WaterfallView(const bool cursor = false);
|
|
|
|
WaterfallView(const WaterfallView&) = delete;
|
|
WaterfallView(WaterfallView&&) = delete;
|
|
WaterfallView& operator=(const WaterfallView&) = delete;
|
|
WaterfallView& operator=(WaterfallView&&) = delete;
|
|
|
|
// TODO: remove these, use start/stop directly instead.
|
|
void on_show() override;
|
|
void on_hide() override;
|
|
|
|
void start();
|
|
void stop();
|
|
|
|
void set_parent_rect(const Rect new_parent_rect) override;
|
|
void show_audio_spectrum_view(const bool show);
|
|
void load_gradient();
|
|
void set_live_tuning(const bool enabled) { frequency_scale.set_live_tuning(enabled); }
|
|
|
|
private:
|
|
void update_widgets_rect();
|
|
|
|
const Rect audio_spectrum_view_rect{UI_POS_X(0), UI_POS_Y(0), UI_POS_MAXWIDTH, 2 * 16 + 20};
|
|
static constexpr Dim audio_spectrum_height = 16 * 2 + 20;
|
|
static constexpr Dim scale_height = 20;
|
|
|
|
WaterfallWidget waterfall_widget{};
|
|
FrequencyScale frequency_scale{};
|
|
bool running_{false};
|
|
|
|
ChannelSpectrumFIFO* channel_fifo{nullptr};
|
|
AudioSpectrum* audio_spectrum_data{nullptr};
|
|
bool audio_spectrum_update{false};
|
|
|
|
std::unique_ptr<AudioSpectrumView> audio_spectrum_view{};
|
|
|
|
int sampling_rate{0};
|
|
int32_t cursor_position{0};
|
|
ui::Rect waterfall_normal_rect{};
|
|
ui::Rect waterfall_reduced_rect{};
|
|
|
|
MessageHandlerRegistration message_handler_channel_spectrum_config{
|
|
Message::ID::ChannelSpectrumConfig,
|
|
[this](const Message* const p) {
|
|
if (!running_)
|
|
return;
|
|
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
|
|
this->channel_fifo = message.fifo;
|
|
}};
|
|
MessageHandlerRegistration message_handler_audio_spectrum{
|
|
Message::ID::AudioSpectrum,
|
|
[this](const Message* const p) {
|
|
if (!running_)
|
|
return;
|
|
const auto message = *reinterpret_cast<const AudioSpectrumMessage*>(p);
|
|
this->audio_spectrum_data = message.data;
|
|
this->audio_spectrum_update = true;
|
|
}};
|
|
MessageHandlerRegistration message_handler_frame_sync{
|
|
Message::ID::DisplayFrameSync,
|
|
[this](const Message* const) {
|
|
if (!running_)
|
|
return;
|
|
if (this->channel_fifo) {
|
|
ChannelSpectrum channel_spectrum;
|
|
while (channel_fifo->out(channel_spectrum)) {
|
|
this->on_channel_spectrum(channel_spectrum);
|
|
}
|
|
}
|
|
if (this->audio_spectrum_update) {
|
|
this->audio_spectrum_update = false;
|
|
this->on_audio_spectrum();
|
|
}
|
|
}};
|
|
|
|
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
|
void on_audio_spectrum();
|
|
};
|
|
|
|
} /* namespace spectrum */
|
|
|
|
/* Calculates the best anti_alias_baseband_bandwidth_filter for the given sampling rate. */
|
|
uint32_t filter_bandwidth_for_sampling_rate(int32_t sampling_rate);
|
|
|
|
} /* namespace ui */
|
|
|
|
#endif /*__UI_SPECTRUM_H__*/
|