diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index ce9a7a2f..fe90b74d 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -133,13 +133,17 @@ private: if( sd_card_present_now != sd_card_present ) { sd_card_present = sd_card_present_now; - SDCardStatusMessage message { false }; + SDCardStatusMessage message { sd_card_present ? SDCardStatusMessage::State::Present : SDCardStatusMessage::State::NotPresent }; if( sd_card_present ) { if( sdcConnect(&SDCD1) == CH_SUCCESS ) { if( sd_card::filesystem::mount() == FR_OK ) { - message.is_mounted = true; + message.state = SDCardStatusMessage::State::Mounted; + } else { + message.state = SDCardStatusMessage::State::MountError; } + } else { + message.state = SDCardStatusMessage::State::ConnectError; } } else { sdcDisconnect(&SDCD1); diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index a4d85698..0ff91feb 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -514,7 +514,7 @@ void ReceiverView::on_show() { message_map.register_handler(Message::ID::SDCardStatus, [this](Message* const p) { const auto message = static_cast(p); - this->on_sd_card_mounted(message->is_mounted); + this->on_sd_card_status(*message); } ); } @@ -585,8 +585,8 @@ void ReceiverView::on_packet_tpms(const TPMSPacketMessage& message) { } } -void ReceiverView::on_sd_card_mounted(const bool is_mounted) { - if( is_mounted ) { +void ReceiverView::on_sd_card_status(const SDCardStatusMessage& message) { + if( message.state == SDCardStatusMessage::State::Mounted ) { const auto open_result = f_open(&fil_tpms, "tpms.txt", FA_WRITE | FA_OPEN_ALWAYS); if( open_result == FR_OK ) { const auto fil_size = f_size(&fil_tpms); diff --git a/firmware/application/ui_receiver.hpp b/firmware/application/ui_receiver.hpp index 50353b9d..6b2bda88 100644 --- a/firmware/application/ui_receiver.hpp +++ b/firmware/application/ui_receiver.hpp @@ -475,7 +475,7 @@ private: void on_packet_ais(const AISPacketMessage& message); void on_packet_tpms(const TPMSPacketMessage& message); - void on_sd_card_mounted(const bool is_mounted); + void on_sd_card_status(const SDCardStatusMessage& message); }; } /* namespace ui */ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 393d3b3d..9ad41875 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -243,14 +243,23 @@ public: class SDCardStatusMessage : public Message { public: + enum class State : int32_t { + IOError = -3, + MountError = -2, + ConnectError = -1, + NotPresent = 0, + Present = 1, + Mounted = 2, + }; + constexpr SDCardStatusMessage( - bool is_mounted + State state ) : Message { ID::SDCardStatus }, - is_mounted { is_mounted } + state { state } { } - bool is_mounted; + State state; }; class MessageHandlerMap {