Skip to content

Commit

Permalink
Beep-on-packet support in Weather app (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotherNgineer committed Mar 29, 2024
1 parent 746bf1c commit f1ebb1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
13 changes: 13 additions & 0 deletions firmware/application/apps/ui_weatherstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using namespace portapack;
using namespace ui;

namespace pmem = portapack::persistent_memory;

namespace ui {

void WeatherRecentEntryDetailView::update_data() {
Expand Down Expand Up @@ -91,6 +93,7 @@ WeatherView::WeatherView(NavigationView& nav)
&field_rf_amp,
&field_lna,
&field_vga,
&field_volume,
&field_frequency,
&options_temperature,
&button_clear_list,
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions firmware/application/apps/ui_weatherstation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_};
Expand Down
20 changes: 18 additions & 2 deletions firmware/baseband/proc_weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions firmware/baseband/proc_weather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit f1ebb1a

Please sign in to comment.