Beep-on-packet support in Weather app (#2063)

This commit is contained in:
Mark Thompson 2024-03-29 15:29:50 -05:00 committed by GitHub
parent 746bf1c15f
commit f1ebb1a6e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 2 deletions

View File

@ -30,6 +30,8 @@
using namespace portapack;
using namespace ui;
namespace pmem = portapack::persistent_memory;
namespace ui {
void WeatherRecentEntryDetailView::update_data() {
@ -91,6 +93,7 @@ WeatherView::WeatherView(NavigationView& nav)
&field_rf_amp,
&field_lna,
&field_vga,
&field_volume,
&field_frequency,
&options_temperature,
&button_clear_list,
@ -120,6 +123,11 @@ WeatherView::WeatherView(NavigationView& nav)
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
on_tick_second();
};
if (pmem::beep_on_packets()) {
audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
}
}
void WeatherView::on_tick_second() {
@ -142,10 +150,15 @@ void WeatherView::on_data(const WeatherDataMessage* data) {
truncate_entries(recent, 64);
}
recent_entries_view.set_dirty();
if (pmem::beep_on_packets()) {
baseband::request_audio_beep(1000, 24000, 60);
}
}
WeatherView::~WeatherView() {
rtc_time::signal_tick_second -= signal_token_tick_second;
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}

View File

@ -126,6 +126,10 @@ class WeatherView : public View {
{18 * 8, 0 * 16}};
RSSI rssi{
{21 * 8, 0, 6 * 8, 4}};
AudioVolumeField field_volume{
{28 * 8, 0 * 16}};
RxFrequencyField field_frequency{
{0 * 8, 0 * 16},
nav_};

View File

@ -23,6 +23,7 @@
#include "proc_weather.hpp"
#include "portapack_shared_memory.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
void WeatherProcessor::execute(const buffer_c8_t& buffer) {
if (!configured) return;
@ -66,8 +67,18 @@ void WeatherProcessor::execute(const buffer_c8_t& buffer) {
}
void WeatherProcessor::on_message(const Message* const message) {
if (message->id == Message::ID::SubGhzFPRxConfigure)
configure(*reinterpret_cast<const SubGhzFPRxConfigureMessage*>(message));
switch (message->id) {
case Message::ID::SubGhzFPRxConfigure:
configure(*reinterpret_cast<const SubGhzFPRxConfigureMessage*>(message));
break;
case Message::ID::AudioBeep:
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(message));
break;
default:
break;
}
}
void WeatherProcessor::configure(const SubGhzFPRxConfigureMessage& message) {
@ -84,7 +95,12 @@ void WeatherProcessor::configure(const SubGhzFPRxConfigureMessage& message) {
configured = true;
}
void WeatherProcessor::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<WeatherProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -66,6 +66,7 @@ class WeatherProcessor : public BasebandProcessor {
FProtoListGeneral* protoList = new WeatherProtos(); // holds all the protocols we can parse
void configure(const SubGhzFPRxConfigureMessage& message);
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};