Skip to content

Commit

Permalink
Beep-on-packet support in TPMS app (#2062)
Browse files Browse the repository at this point in the history
* Beep-on-packet support in TPMS app
* audio::output::stop when exiting
  • Loading branch information
NotherNgineer committed Mar 29, 2024
1 parent 0db65cc commit 746bf1c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion firmware/application/apps/tpms_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "tpms_app.hpp"

#include "baseband_api.hpp"

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

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

namespace pmem = portapack::persistent_memory;

namespace tpms {

namespace format {
Expand Down Expand Up @@ -147,6 +149,7 @@ TPMSAppView::TPMSAppView(NavigationView&) {
baseband::run_image(portapack::spi_flash::image_tag_tpms);

add_children({&rssi,
&field_volume,
&channel,
&options_band,
&options_pressure,
Expand Down Expand Up @@ -179,9 +182,15 @@ TPMSAppView::TPMSAppView(NavigationView&) {
if (logger) {
logger->append(logs_dir / u"TPMS.TXT");
}

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

TPMSAppView::~TPMSAppView() {
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}
Expand Down Expand Up @@ -214,6 +223,10 @@ void TPMSAppView::on_packet(const tpms::Packet& packet) {
entry.update(reading);
recent_entries_view.set_dirty();
}

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

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

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

Channel channel{
{21 * 8, 5, 6 * 8, 4},
};
Expand Down
11 changes: 11 additions & 0 deletions firmware/baseband/proc_tpms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "proc_tpms.hpp"
#include "audio_dma.hpp"

#include "dsp_fir_taps.hpp"

Expand Down Expand Up @@ -60,7 +61,17 @@ void TPMSProcessor::execute(const buffer_c8_t& buffer) {
}
}

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

void TPMSProcessor::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<TPMSProcessor>()};
event_dispatcher.run();
return 0;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_tpms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class TPMSProcessor : public BasebandProcessor {
shared_memory.application_queue.push(message);
}};

void on_message(const Message* const 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, /*auto_start*/ false};
Expand Down

0 comments on commit 746bf1c

Please sign in to comment.