From 4278452de1578c5dd594bcd1a9ce216b4b00e0fb Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Wed, 17 Jul 2024 19:36:06 +0800 Subject: [PATCH] Improve:sd card status led. --- application/MissionManager/src/LedsHandle.cpp | 10 ++++++++++ application/MissionManager/src/LedsHandle.h | 2 ++ .../MissionManager/src/SdCardHandleState.cpp | 16 ++++++++++++++++ .../MissionManager/src/SdCardHandleState.h | 3 +++ 4 files changed, 31 insertions(+) diff --git a/application/MissionManager/src/LedsHandle.cpp b/application/MissionManager/src/LedsHandle.cpp index 645749f..6399b0f 100644 --- a/application/MissionManager/src/LedsHandle.cpp +++ b/application/MissionManager/src/LedsHandle.cpp @@ -26,6 +26,16 @@ void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long i case DeviceStatus::FORMATTING: mDeviceStatus = SetLedState::ControlLed("device_status", LedState::RED, keepAliveTime, blinkPeriod); break; + case DeviceStatus::SD_CARD_REMOVE: + mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod); + break; + case DeviceStatus::SD_CARD_INSERT: + /** + * @brief When the SD card is normal, there is no need to change the state of the status light, but the status + * light resources need to be released and the status light needs to be restored to its proper state. + */ + mDeviceStatus.reset(); + break; default: LogWarning("unknow device status.\n"); diff --git a/application/MissionManager/src/LedsHandle.h b/application/MissionManager/src/LedsHandle.h index 56a9584..d28a3f2 100644 --- a/application/MissionManager/src/LedsHandle.h +++ b/application/MissionManager/src/LedsHandle.h @@ -20,6 +20,8 @@ enum class DeviceStatus NORMAL = 0, TAKING_PICTURE_OR_VIDEO, FORMATTING, + SD_CARD_REMOVE, + SD_CARD_INSERT, END }; class LedsHandle diff --git a/application/MissionManager/src/SdCardHandleState.cpp b/application/MissionManager/src/SdCardHandleState.cpp index 0546b45..359e3bb 100644 --- a/application/MissionManager/src/SdCardHandleState.cpp +++ b/application/MissionManager/src/SdCardHandleState.cpp @@ -53,6 +53,7 @@ void SdCardHandleState::StateInit(void) void SdCardHandleState::StateUnInit(void) { IFilesManager::GetInstance()->UnInit(); + LedsHandle::DeleteAllLeds(); } bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg) { @@ -102,6 +103,7 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg) std::make_shared(static_cast(InternalStateEvent::CHECK_UPGRADE_FILE)); MissionStateMachine::GetInstance()->SendStateMessage(message); } + SetSdCardLedsStatus(mSdCardStatus); return EXECUTED; } bool SdCardHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg) @@ -130,4 +132,18 @@ bool SdCardHandleState::FormatKeyFormattingSDCardHandle(VStateMachineData *msg) } LogWarning("Sd card is not inserted, ignore format key.\n"); return EXECUTED; +} +void SdCardHandleState::SetSdCardLedsStatus(const StorageEvent &event) +{ + switch (event) { + case StorageEvent::SD_CARD_REMOVE: + LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_REMOVE, KEEP_ALIVE_FOREVER, BLINKING_SLOW_MS); + break; + case StorageEvent::SD_CARD_INSERT: + LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_INSERT); + break; + + default: + break; + } } \ No newline at end of file diff --git a/application/MissionManager/src/SdCardHandleState.h b/application/MissionManager/src/SdCardHandleState.h index 0c9cfa5..5c583a8 100644 --- a/application/MissionManager/src/SdCardHandleState.h +++ b/application/MissionManager/src/SdCardHandleState.h @@ -19,9 +19,11 @@ #include "IMediaManager.h" #include "IStateMachine.h" #include "IStorageManager.h" +#include "LedsHandle.h" #include "VStateBase.h" class SdCardHandleState : public State, public DataProcessing, + public LedsHandle, public VStateBase, public std::enable_shared_from_this { @@ -39,6 +41,7 @@ protected: bool SdCardEventHandle(VStateMachineData *msg); bool ResetKeyMediaTaskHandle(VStateMachineData *msg); bool FormatKeyFormattingSDCardHandle(VStateMachineData *msg); + void SetSdCardLedsStatus(const StorageEvent &event); private: StorageEvent mSdCardStatus;