Beep-on-packet support in TPMS app (#2062)

* Beep-on-packet support in TPMS app
* audio::output::stop when exiting
This commit is contained in:
Mark Thompson 2024-03-29 15:28:27 -05:00 committed by GitHub
parent 0db65ccb6b
commit 746bf1c15f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 1 deletions

View File

@ -23,7 +23,7 @@
#include "tpms_app.hpp"
#include "baseband_api.hpp"
#include "audio.hpp"
#include "portapack.hpp"
using namespace portapack;
@ -32,6 +32,8 @@ using namespace portapack;
#include "utility.hpp"
#include "file_path.hpp"
namespace pmem = portapack::persistent_memory;
namespace tpms {
namespace format {
@ -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,
@ -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();
}
@ -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() {

View File

@ -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},
};

View File

@ -21,6 +21,7 @@
*/
#include "proc_tpms.hpp"
#include "audio_dma.hpp"
#include "dsp_fir_taps.hpp"
@ -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;

View File

@ -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};