Improve:Leds handle.

This commit is contained in:
Fancy code 2024-07-20 20:41:55 +08:00
parent 11203a87c5
commit 6a107520f7
7 changed files with 39 additions and 12 deletions

View File

@ -19,6 +19,7 @@
void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime,
const unsigned int &blinkPeriod)
{
DeleteDeviceStatusLed();
switch (status) {
case DeviceStatus::NORMAL:
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
@ -29,12 +30,11 @@ void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long i
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();
case DeviceStatus::SD_CARD_ABNORMAL:
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::RED, keepAliveTime, blinkPeriod);
break;
case DeviceStatus::TAKING_PICTURE_OR_VIDEO:
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
break;
default:
@ -42,7 +42,7 @@ void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long i
break;
}
}
void inline LedsHandle::DeleteDeviceStatusLed(void)
void LedsHandle::DeleteDeviceStatusLed(void)
{
if (mDeviceStatus) {
mDeviceStatus->DeleteState();

View File

@ -22,8 +22,12 @@ enum class DeviceStatus
FORMATTING,
SD_CARD_REMOVE,
SD_CARD_INSERT,
SD_CARD_ABNORMAL,
END
};
/**
* @brief LedsHandle-LED light control class, mainly used to inherit LED light control functions in different states.
*/
class LedsHandle
{
public:
@ -44,6 +48,11 @@ protected:
void DeleteAllLeds(void);
private:
std::shared_ptr<SetLedState> mDeviceStatus;
/**
* @brief Definitions of various LED indicators.
* NOTE: When indicator lights with different functions switch states, the previous light state should be cleared by
* calling the DeleteState function.
*/
std::shared_ptr<SetLedState> mDeviceStatus; ///< Device status indicator.
};
#endif

View File

@ -43,6 +43,7 @@ void MediaHandleState::GoInState()
void MediaHandleState::GoOutState()
{
LogInfo(" ========== MediaHandleState::GoOutState.\n");
LedsHandle::DeleteAllLeds();
}
bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg)
{
@ -57,6 +58,8 @@ void MediaHandleState::TaskResponse(const MediaTaskInfo &taskinfo)
bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
{
MediaTaskHandle::MakeSingleTask(InternalStateEvent::RESET_KEY_MEDIA_TASK, shared_from_this());
LedsHandle::ControlDeviceStatusLed(
DeviceStatus::TAKING_PICTURE_OR_VIDEO, KEEP_ALIVE_FOREVER, BLINKING_SUPER_FAST_MS);
return EXECUTED;
}
bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
@ -78,6 +81,8 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
files.push_back(file);
}
IFilesManager::GetInstance()->SaveFiles(files);
LedsHandle::DeleteDeviceStatusLed();
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
return EXECUTED;
}
int MediaHandleState::GetFileSize_KB(const char *filePath)

View File

@ -16,12 +16,14 @@
#define MEDIA_HANDLE_STATE_H
#include "DataProcessing.h"
#include "IStateMachine.h"
#include "LedsHandle.h"
#include "MediaTaskHandle.h"
constexpr int FILE_SIZE_ERROR = -1;
class MediaHandleState : public State,
public DataProcessing,
public MediaTaskHandle,
public VMediaTaskIniator,
public LedsHandle,
public std::enable_shared_from_this<MediaHandleState>
{
public:

View File

@ -142,7 +142,10 @@ void SdCardHandleState::SetSdCardLedsStatus(const StorageEvent &event)
LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_REMOVE, KEEP_ALIVE_FOREVER, BLINKING_SLOW_MS);
break;
case StorageEvent::SD_CARD_INSERT:
LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_INSERT);
LedsHandle::DeleteDeviceStatusLed();
break;
case StorageEvent::SD_ABNORMAL:
LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_ABNORMAL, KEEP_ALIVE_FOREVER, BLINKING_SUPER_FAST_MS);
break;
default:

View File

@ -170,9 +170,16 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
constexpr int BUF_LENGTH = 128;
char cmd[BUF_LENGTH] = {0};
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
fx_system(cmd);
mountedStatus = SdCardHalStatus::MOUNTED;
mStatus = SdCardHalStatus::MOUNTED;
int ret = fx_system(cmd);
constexpr int SYSTEM_SUCCESS = 0;
if (SYSTEM_SUCCESS == ret) {
LogInfo("mount sd card SUCCESS.\n");
mountedStatus = SdCardHalStatus::MOUNTED;
mStatus = SdCardHalStatus::MOUNTED;
}
else {
LogError("mount sd card failed.\n");
}
}
auto monitor = mMonitor.lock();
if (mMonitor.expired()) {

View File

@ -19,6 +19,7 @@
#include <vector>
constexpr unsigned int NEW_TOP_LED_STATE = 0;
constexpr unsigned int LED_NOT_BLINK = 0;
constexpr unsigned int BLINKING_SUPER_FAST_MS = 200;
constexpr unsigned int BLINKING_FAST_MS = 500;
constexpr unsigned int BLINKING_SLOW_MS = 1000;
constexpr long int KEEP_ALIVE_FOREVER = 0;