Skip to content

Commit

Permalink
Beep-on-packets option in Settings and updated ERT & Sonde apps (#2058)
Browse files Browse the repository at this point in the history
* Beep-on-packets option in Settings
* Add beep to ERT app
  • Loading branch information
NotherNgineer authored Mar 29, 2024
1 parent ba36680 commit fe2fbb8
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 22 deletions.
15 changes: 14 additions & 1 deletion firmware/application/apps/ert_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ert_app.hpp"

#include "baseband_api.hpp"

#include "audio.hpp"
#include "portapack.hpp"
using namespace portapack;

Expand All @@ -33,6 +33,8 @@ using namespace portapack;
#include "string_format.hpp"
#include "file_path.hpp"

namespace pmem = portapack::persistent_memory;

namespace ert {

namespace format {
Expand Down Expand Up @@ -121,6 +123,7 @@ ERTAppView::ERTAppView(NavigationView& nav)
&field_lna,
&field_vga,
&rssi,
&field_volume,
&recent_entries_view,
});

Expand All @@ -132,9 +135,15 @@ ERTAppView::ERTAppView(NavigationView& nav)
if (logger) {
logger->append(logs_dir / u"ERT.TXT");
}

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

ERTAppView::~ERTAppView() {
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}
Expand All @@ -158,6 +167,10 @@ void ERTAppView::on_packet(const ert::Packet& packet) {
entry.update(packet);
recent_entries_view.set_dirty();
}

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

void ERTAppView::on_show_list() {
Expand Down
3 changes: 3 additions & 0 deletions firmware/application/apps/ert_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class ERTAppView : public View {
{21 * 8, 0, 6 * 8, 4},
};

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

MessageHandlerRegistration message_handler_packet{
Message::ID::ERTPacket,
[this](Message* const p) {
Expand Down
4 changes: 4 additions & 0 deletions firmware/application/apps/ui_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,17 @@ void SetPersistentMemoryView::focus() {
SetAudioView::SetAudioView(NavigationView& nav) {
add_children({&labels,
&field_tone_mix,
&checkbox_beep_on_packets,
&button_save,
&button_cancel});

field_tone_mix.set_value(pmem::tone_mix());

checkbox_beep_on_packets.set_value(pmem::beep_on_packets());

button_save.on_select = [&nav, this](Button&) {
pmem::set_tone_mix(field_tone_mix.value());
pmem::set_beep_on_packets(checkbox_beep_on_packets.value());
audio::output::update_audio_mute();
nav.pop();
};
Expand Down
11 changes: 10 additions & 1 deletion firmware/application/apps/ui_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,12 @@ class SetAudioView : public View {
Labels labels{
{{1 * 8, 1 * 16}, "Controls the volume of the", Color::light_grey()},
{{1 * 8, 2 * 16}, "tone when transmitting in", Color::light_grey()},
{{1 * 8, 3 * 16}, "Soundboard or Mic apps.", Color::light_grey()},
{{1 * 8, 3 * 16}, "Soundboard or Mic apps:", Color::light_grey()},
{{2 * 8, 5 * 16}, "Tone key mix: %", Color::light_grey()},
{{1 * 8, 8 * 16}, "Controls whether apps should", Color::light_grey()},
{{1 * 8, 9 * 16}, "beep on speaker & headphone", Color::light_grey()},
{{1 * 8, 10 * 16}, "when a packet is received", Color::light_grey()},
{{1 * 8, 11 * 16}, "(not all apps support this):", Color::light_grey()},
};

NumberField field_tone_mix{
Expand All @@ -517,6 +521,11 @@ class SetAudioView : public View {
1,
'0'};

Checkbox checkbox_beep_on_packets{
{3 * 8, 13 * 16},
16,
"Beep on RX packets"};

Button button_save{
{2 * 8, 16 * 16, 12 * 8, 32},
"Save"};
Expand Down
16 changes: 6 additions & 10 deletions firmware/application/apps/ui_sonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdio.h>

using namespace portapack;
namespace pmem = portapack::persistent_memory;

#include "string_format.hpp"
#include "complex.hpp"
Expand All @@ -54,7 +55,6 @@ SondeView::SondeView(NavigationView& nav)
&field_vga,
&rssi,
&field_volume,
&check_beep,
&check_log,
&check_crc,
&text_signature,
Expand All @@ -72,13 +72,6 @@ SondeView::SondeView(NavigationView& nav)

geopos.set_read_only(true);

check_beep.set_value(beep);
check_beep.on_select = [this](Checkbox&, bool v) {
beep = v;
if (beep)
baseband::request_audio_beep(1000, 24000, 60); // 1khz tone for 60ms to acknowledge enablement
};

check_log.set_value(logging);
check_log.on_select = [this](Checkbox&, bool v) {
logging = v;
Expand Down Expand Up @@ -115,7 +108,10 @@ SondeView::SondeView(NavigationView& nav)
if (logger)
logger->append(logs_dir / u"SONDE.TXT");

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

// inject a PitchRSSIConfigureMessage in order to arm
// the pitch rssi events that will be used by the
Expand Down Expand Up @@ -185,7 +181,7 @@ void SondeView::on_packet(const sonde::Packet& packet) {
logger->on_packet(packet);
}

if (beep) {
if (pmem::beep_on_packets()) {
baseband::request_rssi_beep();
}
}
Expand Down
7 changes: 0 additions & 7 deletions firmware/application/apps/ui_sonde.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ class SondeView : public View {
1750000 /* bandwidth */,
2457600 /* sampling rate */
};
bool beep{false};
bool logging{false};
bool use_crc{false};
app_settings::SettingsManager settings_{
"rx_sonde",
app_settings::Mode::RX,
{
{"beep"sv, &beep},
{"logging"sv, &logging},
{"use_crc"sv, &use_crc},
}};
Expand Down Expand Up @@ -124,11 +122,6 @@ class SondeView : public View {
AudioVolumeField field_volume{
{28 * 8, 0 * 16}};

Checkbox check_beep{
{22 * 8, 6 * 16},
3,
"Beep"};

Checkbox check_log{
{22 * 8, 8 * 16},
3,
Expand Down
2 changes: 0 additions & 2 deletions firmware/baseband/proc_audio_beep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "baseband_processor.hpp"
#include "message.hpp"

#define AUDIO_SAMPLE_RATE 24000

class AudioBeepProcessor : public BasebandProcessor {
public:
AudioBeepProcessor();
Expand Down
11 changes: 11 additions & 0 deletions firmware/baseband/proc_ert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "proc_ert.hpp"
#include "audio_dma.hpp"

#include "portapack_shared_memory.hpp"

Expand Down Expand Up @@ -109,7 +110,17 @@ void ERTProcessor::idm_handler(
shared_memory.application_queue.push(message);
}

void ERTProcessor::on_message(const Message* const msg) {
if (msg->id == Message::ID::AudioBeep)
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(msg));
}

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

int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<ERTProcessor>()};
event_dispatcher.run();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions firmware/baseband/proc_ert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class ERTProcessor : public BasebandProcessor {
void scm_handler(const baseband::Packet& packet);
void scmplus_handler(const baseband::Packet& packet);
void idm_handler(const baseband::Packet& packet);
void on_message(const Message* const msg);
void on_beep_message(const AudioBeepMessage& message);

float sum_half_period[2];
float sum_period[3];
Expand Down
11 changes: 10 additions & 1 deletion firmware/common/portapack_persistent_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct misc_config_t {
bool config_disable_external_tcxo : 1;
bool config_sdcard_high_speed_io : 1;
bool config_disable_config_mode : 1;
bool UNUSED_5 : 1;
bool beep_on_packets : 1;
bool UNUSED_6 : 1;
bool UNUSED_7 : 1;

Expand Down Expand Up @@ -641,6 +641,10 @@ bool config_disable_config_mode() {
return data->misc_config.config_disable_config_mode;
}

bool beep_on_packets() {
return data->misc_config.beep_on_packets;
}

bool config_sdcard_high_speed_io() {
return data->misc_config.config_sdcard_high_speed_io;
}
Expand Down Expand Up @@ -718,6 +722,10 @@ void set_config_disable_config_mode(bool v) {
data->misc_config.config_disable_config_mode = v;
}

void set_beep_on_packets(bool v) {
data->misc_config.beep_on_packets = v;
}

void set_config_sdcard_high_speed_io(bool v, bool save) {
if (v) {
/* 200MHz / (2 * 2) = 50MHz */
Expand Down Expand Up @@ -1247,6 +1255,7 @@ bool debug_dump() {
pmem_dump_file.write_line("misc_config config_disable_external_tcxo: " + to_string_dec_uint(config_disable_external_tcxo()));
pmem_dump_file.write_line("misc_config config_sdcard_high_speed_io: " + to_string_dec_uint(config_sdcard_high_speed_io()));
pmem_dump_file.write_line("misc_config config_disable_config_mode: " + to_string_dec_uint(config_disable_config_mode()));
pmem_dump_file.write_line("misc_config beep_on_packets: " + to_string_dec_int(beep_on_packets()));

// receiver_model
pmem_dump_file.write_line("\n[Receiver Model]");
Expand Down
2 changes: 2 additions & 0 deletions firmware/common/portapack_persistent_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void set_config_cpld(uint8_t i);
bool config_disable_external_tcxo();
bool config_sdcard_high_speed_io();
bool config_disable_config_mode();
bool beep_on_packets();

bool config_splash();
bool config_converter();
Expand All @@ -226,6 +227,7 @@ void set_show_bigger_qr_code(bool v);
void set_config_disable_external_tcxo(bool v);
void set_config_sdcard_high_speed_io(bool v, bool save);
void set_config_disable_config_mode(bool v);
void set_beep_on_packets(bool v);

void set_config_splash(bool v);
bool config_converter();
Expand Down

0 comments on commit fe2fbb8

Please sign in to comment.