diff --git a/firmware/application/analog_audio_app.cpp b/firmware/application/analog_audio_app.cpp index ce7dc4bf..cb8684cd 100644 --- a/firmware/application/analog_audio_app.cpp +++ b/firmware/application/analog_audio_app.cpp @@ -84,6 +84,8 @@ AnalogAudioView::AnalogAudioView( &field_vga, &options_modulation, &field_volume, + &button_record, + &text_record_filename, &waterfall, } }); @@ -136,6 +138,10 @@ AnalogAudioView::AnalogAudioView( this->on_headphone_volume_changed(v); }; + button_record.on_select = [this](ImageButton&) { + this->on_record(); + }; + audio::output::start(); update_modulation(static_cast(modulation)); @@ -281,7 +287,7 @@ void AnalogAudioView::on_headphone_volume_changed(int32_t v) { void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) { audio::output::mute(); - capture_thread.reset(); + record_stop(); const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis); receiver_model.set_baseband_configuration({ @@ -293,12 +299,36 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) { receiver_model.enable(); if( !is_wideband_spectrum_mode ) { - const auto filename = next_filename_matching_pattern("AUD_????.S16"); - if( !filename.empty() ) { - capture_thread = std::make_unique(filename); - } audio::output::unmute(); } } +bool AnalogAudioView::is_recording() const { + return (bool)capture_thread; +} + +void AnalogAudioView::on_record() { + if( is_recording() ) { + record_stop(); + } else { + record_start(); + } +} + +void AnalogAudioView::record_start() { + const auto filename = next_filename_matching_pattern("AUD_????.S16"); + text_record_filename.set(filename); + if( filename.empty() ) { + return; + } + + capture_thread = std::make_unique(filename); + button_record.set_bitmap(&bitmap_stop); +} + +void AnalogAudioView::record_stop() { + capture_thread.reset(); + button_record.set_bitmap(&bitmap_record); +} + } /* namespace ui */ diff --git a/firmware/application/analog_audio_app.hpp b/firmware/application/analog_audio_app.hpp index b72443e5..4f988823 100644 --- a/firmware/application/analog_audio_app.hpp +++ b/firmware/application/analog_audio_app.hpp @@ -93,7 +93,7 @@ public: void focus() override; private: - static constexpr ui::Dim header_height = 2 * 16; + static constexpr ui::Dim header_height = 3 * 16; const Rect options_view_rect { 0 * 8, 1 * 16, 30 * 8, 1 * 16 }; @@ -142,6 +142,18 @@ private: std::unique_ptr options_widget; + ImageButton button_record { + { 0 * 8, 2 * 16, 2 * 8, 1 * 16 }, + &bitmap_record, + Color::red(), + Color::black() + }; + + Text text_record_filename { + { 3 * 8, 2 * 16, 12 * 8, 16 }, + "", + }; + spectrum::WaterfallWidget waterfall; std::unique_ptr capture_thread; @@ -164,6 +176,11 @@ private: void set_options_widget(std::unique_ptr new_widget); void update_modulation(const ReceiverModel::Mode modulation); + + void on_record(); + bool is_recording() const; + void record_start(); + void record_stop(); }; } /* namespace ui */