mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-15 08:47:51 +00:00
Transmit ChannelSpectrum data through separate FIFO.
Allows handling of data during LCD "vertical retrace", independent of other baseband->application messages. A bit kludgy still...
This commit is contained in:
@@ -237,15 +237,20 @@ WaterfallWidget::WaterfallWidget() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WaterfallWidget::on_show() {
|
void WaterfallWidget::on_show() {
|
||||||
context().message_map().register_handler(Message::ID::ChannelSpectrum,
|
context().message_map().register_handler(Message::ID::FIFONotify,
|
||||||
[this](const Message* const p) {
|
[this](const Message* const p) {
|
||||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
const auto message = reinterpret_cast<const FIFONotifyMessage*>(p);
|
||||||
|
auto fifo = reinterpret_cast<ChannelSpectrumFIFO*>(message->fifo);
|
||||||
|
ChannelSpectrum channel_spectrum;
|
||||||
|
if( fifo->out(channel_spectrum) ) {
|
||||||
|
this->on_channel_spectrum(channel_spectrum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterfallWidget::on_hide() {
|
void WaterfallWidget::on_hide() {
|
||||||
context().message_map().unregister_handler(Message::ID::ChannelSpectrum);
|
context().message_map().unregister_handler(Message::ID::FIFONotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {
|
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {
|
||||||
|
@@ -73,8 +73,8 @@ void SpectrumCollector::update() {
|
|||||||
channel_spectrum_request_update = false;
|
channel_spectrum_request_update = false;
|
||||||
fft_c_preswapped(channel_spectrum);
|
fft_c_preswapped(channel_spectrum);
|
||||||
|
|
||||||
ChannelSpectrumMessage spectrum_message;
|
ChannelSpectrum spectrum;
|
||||||
for(size_t i=0; i<spectrum_message.spectrum.db.size(); i++) {
|
for(size_t i=0; i<spectrum.db.size(); i++) {
|
||||||
// Three point Hamming window.
|
// Three point Hamming window.
|
||||||
const auto corrected_sample = channel_spectrum[i] * 0.54f
|
const auto corrected_sample = channel_spectrum[i] * 0.54f
|
||||||
+ (channel_spectrum[(i-1) & 0xff] + channel_spectrum[(i+1) & 0xff]) * -0.23f;
|
+ (channel_spectrum[(i-1) & 0xff] + channel_spectrum[(i+1) & 0xff]) * -0.23f;
|
||||||
@@ -82,14 +82,16 @@ void SpectrumCollector::update() {
|
|||||||
const float db = complex16_mag_squared_to_dbv_norm(mag2);
|
const float db = complex16_mag_squared_to_dbv_norm(mag2);
|
||||||
constexpr float mag_scale = 5.0f;
|
constexpr float mag_scale = 5.0f;
|
||||||
const unsigned int v = (db * mag_scale) + 255.0f;
|
const unsigned int v = (db * mag_scale) + 255.0f;
|
||||||
spectrum_message.spectrum.db[i] = std::max(0U, std::min(255U, v));
|
spectrum.db[i] = std::max(0U, std::min(255U, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */
|
/* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */
|
||||||
spectrum_message.spectrum.db_count = spectrum_message.spectrum.db.size();
|
spectrum.db_count = spectrum.db.size();
|
||||||
spectrum_message.spectrum.sampling_rate = channel_spectrum_sampling_rate;
|
spectrum.sampling_rate = channel_spectrum_sampling_rate;
|
||||||
spectrum_message.spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency;
|
spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency;
|
||||||
spectrum_message.spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency;
|
spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency;
|
||||||
shared_memory.application_queue.push(spectrum_message);
|
fifo.in(spectrum);
|
||||||
|
FIFONotifyMessage message { &fifo };
|
||||||
|
shared_memory.application_queue.push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "message.hpp"
|
||||||
|
|
||||||
class SpectrumCollector {
|
class SpectrumCollector {
|
||||||
public:
|
public:
|
||||||
constexpr SpectrumCollector(
|
constexpr SpectrumCollector(
|
||||||
@@ -49,6 +51,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BlockDecimator<256> channel_spectrum_decimator;
|
BlockDecimator<256> channel_spectrum_decimator;
|
||||||
|
ChannelSpectrumFIFO fifo;
|
||||||
|
|
||||||
volatile bool channel_spectrum_request_update { false };
|
volatile bool channel_spectrum_request_update { false };
|
||||||
std::array<std::complex<float>, 256> channel_spectrum;
|
std::array<std::complex<float>, 256> channel_spectrum;
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "baseband_packet.hpp"
|
#include "baseband_packet.hpp"
|
||||||
#include "ert_packet.hpp"
|
#include "ert_packet.hpp"
|
||||||
#include "dsp_fir_taps.hpp"
|
#include "dsp_fir_taps.hpp"
|
||||||
|
#include "fifo.hpp"
|
||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public:
|
|||||||
RSSIStatistics = 0,
|
RSSIStatistics = 0,
|
||||||
BasebandStatistics = 1,
|
BasebandStatistics = 1,
|
||||||
ChannelStatistics = 2,
|
ChannelStatistics = 2,
|
||||||
ChannelSpectrum = 3,
|
|
||||||
AudioStatistics = 4,
|
AudioStatistics = 4,
|
||||||
BasebandConfiguration = 5,
|
BasebandConfiguration = 5,
|
||||||
TPMSPacket = 6,
|
TPMSPacket = 6,
|
||||||
@@ -55,6 +56,7 @@ public:
|
|||||||
NBFMConfigure = 11,
|
NBFMConfigure = 11,
|
||||||
WFMConfigure = 12,
|
WFMConfigure = 12,
|
||||||
AMConfigure = 13,
|
AMConfigure = 13,
|
||||||
|
FIFONotify = 14,
|
||||||
MAX
|
MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -207,15 +209,7 @@ struct ChannelSpectrum {
|
|||||||
uint32_t channel_filter_stop_frequency { 0 };
|
uint32_t channel_filter_stop_frequency { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChannelSpectrumMessage : public Message {
|
using ChannelSpectrumFIFO = FIFO<ChannelSpectrum, 2>;
|
||||||
public:
|
|
||||||
constexpr ChannelSpectrumMessage(
|
|
||||||
) : Message { ID::ChannelSpectrum }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelSpectrum spectrum;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AISPacketMessage : public Message {
|
class AISPacketMessage : public Message {
|
||||||
public:
|
public:
|
||||||
@@ -333,6 +327,18 @@ public:
|
|||||||
const fir_taps_real<32> channel_filter;
|
const fir_taps_real<32> channel_filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FIFONotifyMessage : public Message {
|
||||||
|
public:
|
||||||
|
constexpr FIFONotifyMessage(
|
||||||
|
void* const fifo
|
||||||
|
) : Message { ID::FIFONotify },
|
||||||
|
fifo { fifo }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void* const fifo;
|
||||||
|
};
|
||||||
|
|
||||||
class MessageHandlerMap {
|
class MessageHandlerMap {
|
||||||
public:
|
public:
|
||||||
using MessageHandler = std::function<void(Message* const p)>;
|
using MessageHandler = std::function<void(Message* const p)>;
|
||||||
|
Reference in New Issue
Block a user