From 9dc12fca3cee556e50c30542d0a51878abd0a194 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 12 May 2016 21:59:46 -0700 Subject: [PATCH] Check for filesystem errors in RecordView. --- firmware/application/ui_record_view.cpp | 29 ++++++++++++++++++++----- firmware/application/ui_record_view.hpp | 4 ++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/firmware/application/ui_record_view.cpp b/firmware/application/ui_record_view.cpp index 0eb67bc7..8473838e 100644 --- a/firmware/application/ui_record_view.cpp +++ b/firmware/application/ui_record_view.cpp @@ -235,12 +235,19 @@ void RecordView::start() { }; if( writer ) { - text_record_filename.set(filename_stem); - button_record.set_bitmap(&bitmap_stop); - capture_thread = std::make_unique( - std::move(writer), - write_size, buffer_count - ); + const auto error = writer->error(); + if( error.is_valid() ) { + report_error(error.value().what()); + } else { + text_record_filename.set(filename_stem); + button_record.set_bitmap(&bitmap_stop); + capture_thread = std::make_unique( + std::move(writer), + write_size, buffer_count + ); + } + } else { + report_error("file type"); } } @@ -259,6 +266,10 @@ void RecordView::write_metadata_file(const std::string& filename) { void RecordView::on_tick_second() { if( is_active() ) { + const auto error = capture_thread->error(); + if( error.is_valid() ) { + report_error(error.value()); + } const auto dropped_percent = std::min(99U, capture_thread->state().dropped_percent()); const auto s = to_string_dec_uint(dropped_percent, 2, ' ') + "\%"; text_record_dropped.set(s); @@ -280,4 +291,10 @@ void RecordView::on_tick_second() { } } +void RecordView::report_error(const std::string& message) { + if( on_error ) { + on_error(message); + } +} + } /* namespace ui */ diff --git a/firmware/application/ui_record_view.hpp b/firmware/application/ui_record_view.hpp index 5cbaabb4..8f987b3d 100644 --- a/firmware/application/ui_record_view.hpp +++ b/firmware/application/ui_record_view.hpp @@ -37,6 +37,8 @@ namespace ui { class RecordView : public View { public: + std::function on_error; + enum FileType { RawS16 = 2, WAV = 3, @@ -71,6 +73,8 @@ private: void on_tick_second(); + void report_error(const std::string& message); + const std::string filename_stem_pattern; const FileType file_type; const size_t write_size;