Improve:Leds handle.
This commit is contained in:
parent
11203a87c5
commit
6a107520f7
|
@ -19,6 +19,7 @@
|
||||||
void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime,
|
void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime,
|
||||||
const unsigned int &blinkPeriod)
|
const unsigned int &blinkPeriod)
|
||||||
{
|
{
|
||||||
|
DeleteDeviceStatusLed();
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DeviceStatus::NORMAL:
|
case DeviceStatus::NORMAL:
|
||||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
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:
|
case DeviceStatus::SD_CARD_REMOVE:
|
||||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
||||||
break;
|
break;
|
||||||
case DeviceStatus::SD_CARD_INSERT:
|
case DeviceStatus::SD_CARD_ABNORMAL:
|
||||||
/**
|
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::RED, keepAliveTime, blinkPeriod);
|
||||||
* @brief When the SD card is normal, there is no need to change the state of the status light, but the status
|
break;
|
||||||
* light resources need to be released and the status light needs to be restored to its proper state.
|
case DeviceStatus::TAKING_PICTURE_OR_VIDEO:
|
||||||
*/
|
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
||||||
mDeviceStatus.reset();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -42,7 +42,7 @@ void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void inline LedsHandle::DeleteDeviceStatusLed(void)
|
void LedsHandle::DeleteDeviceStatusLed(void)
|
||||||
{
|
{
|
||||||
if (mDeviceStatus) {
|
if (mDeviceStatus) {
|
||||||
mDeviceStatus->DeleteState();
|
mDeviceStatus->DeleteState();
|
||||||
|
|
|
@ -22,8 +22,12 @@ enum class DeviceStatus
|
||||||
FORMATTING,
|
FORMATTING,
|
||||||
SD_CARD_REMOVE,
|
SD_CARD_REMOVE,
|
||||||
SD_CARD_INSERT,
|
SD_CARD_INSERT,
|
||||||
|
SD_CARD_ABNORMAL,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* @brief LedsHandle-LED light control class, mainly used to inherit LED light control functions in different states.
|
||||||
|
*/
|
||||||
class LedsHandle
|
class LedsHandle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -44,6 +48,11 @@ protected:
|
||||||
void DeleteAllLeds(void);
|
void DeleteAllLeds(void);
|
||||||
|
|
||||||
private:
|
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
|
#endif
|
|
@ -43,6 +43,7 @@ void MediaHandleState::GoInState()
|
||||||
void MediaHandleState::GoOutState()
|
void MediaHandleState::GoOutState()
|
||||||
{
|
{
|
||||||
LogInfo(" ========== MediaHandleState::GoOutState.\n");
|
LogInfo(" ========== MediaHandleState::GoOutState.\n");
|
||||||
|
LedsHandle::DeleteAllLeds();
|
||||||
}
|
}
|
||||||
bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,8 @@ void MediaHandleState::TaskResponse(const MediaTaskInfo &taskinfo)
|
||||||
bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
MediaTaskHandle::MakeSingleTask(InternalStateEvent::RESET_KEY_MEDIA_TASK, shared_from_this());
|
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;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
||||||
|
@ -78,6 +81,8 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
||||||
files.push_back(file);
|
files.push_back(file);
|
||||||
}
|
}
|
||||||
IFilesManager::GetInstance()->SaveFiles(files);
|
IFilesManager::GetInstance()->SaveFiles(files);
|
||||||
|
LedsHandle::DeleteDeviceStatusLed();
|
||||||
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
int MediaHandleState::GetFileSize_KB(const char *filePath)
|
int MediaHandleState::GetFileSize_KB(const char *filePath)
|
||||||
|
|
|
@ -16,12 +16,14 @@
|
||||||
#define MEDIA_HANDLE_STATE_H
|
#define MEDIA_HANDLE_STATE_H
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
|
#include "LedsHandle.h"
|
||||||
#include "MediaTaskHandle.h"
|
#include "MediaTaskHandle.h"
|
||||||
constexpr int FILE_SIZE_ERROR = -1;
|
constexpr int FILE_SIZE_ERROR = -1;
|
||||||
class MediaHandleState : public State,
|
class MediaHandleState : public State,
|
||||||
public DataProcessing,
|
public DataProcessing,
|
||||||
public MediaTaskHandle,
|
public MediaTaskHandle,
|
||||||
public VMediaTaskIniator,
|
public VMediaTaskIniator,
|
||||||
|
public LedsHandle,
|
||||||
public std::enable_shared_from_this<MediaHandleState>
|
public std::enable_shared_from_this<MediaHandleState>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -142,7 +142,10 @@ void SdCardHandleState::SetSdCardLedsStatus(const StorageEvent &event)
|
||||||
LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_REMOVE, KEEP_ALIVE_FOREVER, BLINKING_SLOW_MS);
|
LedsHandle::ControlDeviceStatusLed(DeviceStatus::SD_CARD_REMOVE, KEEP_ALIVE_FOREVER, BLINKING_SLOW_MS);
|
||||||
break;
|
break;
|
||||||
case StorageEvent::SD_CARD_INSERT:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -170,9 +170,16 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
||||||
constexpr int BUF_LENGTH = 128;
|
constexpr int BUF_LENGTH = 128;
|
||||||
char cmd[BUF_LENGTH] = {0};
|
char cmd[BUF_LENGTH] = {0};
|
||||||
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
||||||
fx_system(cmd);
|
int ret = fx_system(cmd);
|
||||||
mountedStatus = SdCardHalStatus::MOUNTED;
|
constexpr int SYSTEM_SUCCESS = 0;
|
||||||
mStatus = SdCardHalStatus::MOUNTED;
|
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();
|
auto monitor = mMonitor.lock();
|
||||||
if (mMonitor.expired()) {
|
if (mMonitor.expired()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
constexpr unsigned int NEW_TOP_LED_STATE = 0;
|
constexpr unsigned int NEW_TOP_LED_STATE = 0;
|
||||||
constexpr unsigned int LED_NOT_BLINK = 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_FAST_MS = 500;
|
||||||
constexpr unsigned int BLINKING_SLOW_MS = 1000;
|
constexpr unsigned int BLINKING_SLOW_MS = 1000;
|
||||||
constexpr long int KEEP_ALIVE_FOREVER = 0;
|
constexpr long int KEEP_ALIVE_FOREVER = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user