Skip to content

Commit

Permalink
Beep-on-packet support in ADSB RX app (#2065)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotherNgineer authored Mar 29, 2024
1 parent 6e5eadd commit b473930
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
16 changes: 15 additions & 1 deletion firmware/application/apps/ui_adsb_rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
#include "rtc_time.hpp"
#include "string_format.hpp"
#include "file_path.hpp"
#include "audio.hpp"

using namespace portapack;

namespace pmem = portapack::persistent_memory;

namespace ui {

static std::string get_map_tag(const AircraftRecentEntry& entry) {
Expand Down Expand Up @@ -373,7 +376,8 @@ ADSBRxView::ADSBRxView(NavigationView& nav) {
&rssi,
&recent_entries_view,
&status_frame,
&status_good_frame});
&status_good_frame,
&field_volume});

recent_entries_view.set_parent_rect({0, 16, 240, 272});
recent_entries_view.on_select = [this, &nav](const AircraftRecentEntry& entry) {
Expand All @@ -395,10 +399,16 @@ ADSBRxView::ADSBRxView(NavigationView& nav) {

receiver_model.enable();
baseband::set_adsb();

if (pmem::beep_on_packets()) {
audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
}
}

ADSBRxView::~ADSBRxView() {
rtc_time::signal_tick_second -= signal_token_tick_second;
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}
Expand Down Expand Up @@ -473,6 +483,10 @@ void ADSBRxView::on_frame(const ADSBFrameMessage* message) {
}

logger->log(log_entry);

if (pmem::beep_on_packets()) {
baseband::request_audio_beep(1000, 24000, 60);
}
}

void ADSBRxView::on_tick_second() {
Expand Down
9 changes: 6 additions & 3 deletions firmware/application/apps/ui_adsb_rx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,22 @@ class ADSBRxView : public View {
{18 * 8, 0 * 16}};

RSSI rssi{
{20 * 8, 4, 10 * 7, 8},
{20 * 8, 4, 7 * 8, 8},
};

ActivityDot status_frame{
{screen_width - 3, 5, 2, 2},
{27 * 8 + 2, 5, 2, 2},
Color::white(),
};

ActivityDot status_good_frame{
{screen_width - 3, 9, 2, 2},
{27 * 8 + 2, 9, 2, 2},
Color::green(),
};

AudioVolumeField field_volume{
{28 * 8, 0 * 16}};

MessageHandlerRegistration message_handler_frame{
Message::ID::ADSBFrame,
[this](Message* const p) {
Expand Down
25 changes: 20 additions & 5 deletions firmware/baseband/proc_adsbrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "portapack_shared_memory.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <cstdint>
#include <cstddef>
Expand Down Expand Up @@ -144,16 +145,30 @@ void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
}

void ADSBRXProcessor::on_message(const Message* const message) {
if (message->id == Message::ID::ADSBConfigure) {
bit_count = 0;
sample_count = 0;
decoding = false;
configured = true;
switch (message->id) {
case Message::ID::ADSBConfigure:
bit_count = 0;
sample_count = 0;
decoding = false;
configured = true;
break;

case Message::ID::AudioBeep:
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(message));
break;

default:
break;
}
}

void ADSBRXProcessor::on_beep_message(const AudioBeepMessage& message) {
audio::dma::beep_start(message.freq, message.sample_rate, message.duration_ms);
}

#ifndef _WIN32
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<ADSBRXProcessor>()};
event_dispatcher.run();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions firmware/baseband/proc_adsbrx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ADSBRXProcessor : public BasebandProcessor {

uint32_t shifter[ADSB_PREAMBLE_LENGTH + 1];

void on_beep_message(const AudioBeepMessage& message);

/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
Expand Down

0 comments on commit b473930

Please sign in to comment.