Broaden SD card status detail in message.

This commit is contained in:
Jared Boone 2015-11-29 15:50:58 -08:00
parent 5928086fd9
commit 42104d217a
4 changed files with 22 additions and 9 deletions

View File

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

View File

@ -514,7 +514,7 @@ void ReceiverView::on_show() {
message_map.register_handler(Message::ID::SDCardStatus,
[this](Message* const p) {
const auto message = static_cast<const SDCardStatusMessage*>(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);

View File

@ -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 */

View File

@ -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 {