Improve:sd card status led.

This commit is contained in:
Fancy code 2024-07-17 19:36:06 +08:00
parent 59f6b7ec8b
commit 4278452de1
4 changed files with 31 additions and 0 deletions

View File

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

View File

@ -20,6 +20,8 @@ enum class DeviceStatus
NORMAL = 0,
TAKING_PICTURE_OR_VIDEO,
FORMATTING,
SD_CARD_REMOVE,
SD_CARD_INSERT,
END
};
class LedsHandle

View File

@ -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<VMissionData>(static_cast<MissionEvent>(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;
}
}

View File

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