Improve:key event handle.
This commit is contained in:
parent
2d9e3711b1
commit
a0070c5747
|
@ -16,12 +16,20 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
const bool NOT_EXECUTED = false;
|
const bool NOT_EXECUTED = false;
|
||||||
const bool EXECUTED = true;
|
const bool EXECUTED = true;
|
||||||
|
key_event_data::key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime)
|
||||||
|
: mKeyName(keyName), mKeyEvent(keyEvent), mHoldTime(holdTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
DataProcessing::DataProcessing()
|
||||||
|
{
|
||||||
|
mEventHandle[InternalStateEvent::KEY_EVENT_HANDLE] = std::bind(&DataProcessing::KeyEventHandle, this, _1);
|
||||||
|
}
|
||||||
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
if (nullptr == msg) {
|
if (nullptr == msg) {
|
||||||
|
@ -37,3 +45,29 @@ bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||||
}
|
}
|
||||||
return NOT_EXECUTED;
|
return NOT_EXECUTED;
|
||||||
}
|
}
|
||||||
|
bool DataProcessing::KeyEventHandle(VStateMachineData *msg)
|
||||||
|
{
|
||||||
|
if (nullptr == msg) {
|
||||||
|
LogError("nullptr pointer.\n");
|
||||||
|
return NOT_EXECUTED;
|
||||||
|
}
|
||||||
|
std::map<std::string, KeyHandleFunc>::iterator iter;
|
||||||
|
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||||
|
std::shared_ptr<VMissionDataV2<KeyEventData>> data =
|
||||||
|
std::dynamic_pointer_cast<VMissionDataV2<KeyEventData>>(message->mMissionData);
|
||||||
|
if (!data) {
|
||||||
|
LogError("nullptr pointer.\n");
|
||||||
|
return NOT_EXECUTED;
|
||||||
|
}
|
||||||
|
iter = mKeyClickHandle.find(data->mData.mKeyName);
|
||||||
|
if (iter != mKeyClickHandle.end() && KeyEvent::SHORT_CLICK == data->mData.mKeyEvent) {
|
||||||
|
return mKeyClickHandle[data->mData.mKeyName](data->mData);
|
||||||
|
}
|
||||||
|
if (iter != mKeyHoldDownHandle.end() && KeyEvent::HOLD_DOWN == data->mData.mKeyEvent) {
|
||||||
|
return mKeyHoldDownHandle[data->mData.mKeyName](data->mData);
|
||||||
|
}
|
||||||
|
if (iter != mKeyHoldUpHandle.end() && KeyEvent::HOLD_UP == data->mData.mKeyEvent) {
|
||||||
|
return mKeyHoldUpHandle[data->mData.mKeyName](data->mData);
|
||||||
|
}
|
||||||
|
return NOT_EXECUTED;
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
#define DATA_PROCESSING_H
|
#define DATA_PROCESSING_H
|
||||||
#include "IMissionManager.h"
|
#include "IMissionManager.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
|
#include "KeyControl.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
|
@ -27,8 +28,17 @@ enum class InternalStateEvent
|
||||||
ANY_STATE_SD_STATUS_PERORIED,
|
ANY_STATE_SD_STATUS_PERORIED,
|
||||||
CHECK_UPGRADE_FILE,
|
CHECK_UPGRADE_FILE,
|
||||||
MEDIA_REPORT_EVENT,
|
MEDIA_REPORT_EVENT,
|
||||||
|
KEY_EVENT_HANDLE,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
|
typedef struct key_event_data
|
||||||
|
{
|
||||||
|
key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime);
|
||||||
|
const std::string mKeyName;
|
||||||
|
const KeyEvent mKeyEvent;
|
||||||
|
const unsigned int mHoldTime;
|
||||||
|
} KeyEventData;
|
||||||
|
using KeyHandleFunc = std::function<bool(const KeyEventData &)>;
|
||||||
class MissionData : public VStateMachineData
|
class MissionData : public VStateMachineData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -51,11 +61,16 @@ public:
|
||||||
class DataProcessing
|
class DataProcessing
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DataProcessing() = default;
|
DataProcessing();
|
||||||
virtual ~DataProcessing() = default;
|
virtual ~DataProcessing() = default;
|
||||||
bool EventHandle(VStateMachineData *msg);
|
bool EventHandle(VStateMachineData *msg);
|
||||||
|
virtual bool KeyEventHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<InternalStateEvent, DataProcessingFunc> mEventHandle;
|
std::map<InternalStateEvent, DataProcessingFunc> mEventHandle;
|
||||||
|
std::map<std::string, DataProcessingFunc> mKeyEventHandle;
|
||||||
|
std::map<std::string, KeyHandleFunc> mKeyClickHandle;
|
||||||
|
std::map<std::string, KeyHandleFunc> mKeyHoldDownHandle;
|
||||||
|
std::map<std::string, KeyHandleFunc> mKeyHoldUpHandle;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -21,6 +21,7 @@ TestMissionState::TestMissionState() : MissionState("TestMissionState")
|
||||||
{
|
{
|
||||||
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||||
std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1);
|
std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1);
|
||||||
|
mKeyClickHandle["reset"] = std::bind(&TestMissionState::ClickResetKey, this, _1);
|
||||||
}
|
}
|
||||||
void TestMissionState::GoInState()
|
void TestMissionState::GoInState()
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,10 @@ bool TestMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||||
IAppManager::GetInstance()->SetSdCardStatus(status);
|
IAppManager::GetInstance()->SetSdCardStatus(status);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
|
bool TestMissionState::ClickResetKey(const KeyEventData &data)
|
||||||
|
{
|
||||||
|
return EXECUTED;
|
||||||
|
}
|
||||||
SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event)
|
SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||||
|
bool ClickResetKey(const KeyEventData &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||||
|
|
|
@ -55,6 +55,10 @@ void TopState::KeyEventReport(const std::string &keyName, const VirtualKeyEvent
|
||||||
keyName.c_str(),
|
keyName.c_str(),
|
||||||
PrintKeyEvent(static_cast<KeyEvent>(event)),
|
PrintKeyEvent(static_cast<KeyEvent>(event)),
|
||||||
timeMs);
|
timeMs);
|
||||||
|
KeyEventData data(keyName, static_cast<KeyEvent>(event), timeMs);
|
||||||
|
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<KeyEventData>>(
|
||||||
|
static_cast<MissionEvent>(InternalStateEvent::KEY_EVENT_HANDLE), data);
|
||||||
|
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||||
}
|
}
|
||||||
bool TopState::StorageStartInitHandle(VStateMachineData *msg)
|
bool TopState::StorageStartInitHandle(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,9 +20,9 @@ bool CreateMcuManager(void);
|
||||||
bool DestroyMcuManager(void);
|
bool DestroyMcuManager(void);
|
||||||
enum class IpcMission
|
enum class IpcMission
|
||||||
{
|
{
|
||||||
PIR_TRIGGERED = 0,
|
PIR_TRIGGERED = 1,
|
||||||
ON,
|
|
||||||
TEST,
|
TEST,
|
||||||
|
ON,
|
||||||
CONTINUOUS_SHOOTING,
|
CONTINUOUS_SHOOTING,
|
||||||
PIR_TRIGGERED_DELAY,
|
PIR_TRIGGERED_DELAY,
|
||||||
REGULAR_START,
|
REGULAR_START,
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Fancy Code.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#include "AppManagerTestTool.h"
|
||||||
|
#include "GtestUsing.h"
|
||||||
|
#include "HalTestTool.h"
|
||||||
|
#include "HuntingCameraTest.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
#include "MainThread.h"
|
||||||
|
#include "McuManagerTestTool.h"
|
||||||
|
#include "MissionManagerTestTool.h"
|
||||||
|
#include "TestManager.h"
|
||||||
|
#include <thread>
|
||||||
|
namespace TestMissionState_Mock_Test
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Construct a new test f object
|
||||||
|
* ../output_files/test/bin/HuntingCameraTest
|
||||||
|
* --gtest_filter=HuntingCameraTest.HS_INTEGRATION_HunttingCamera_EXAMPLE_TestMissionResetKeyCapture
|
||||||
|
*/
|
||||||
|
TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_TestMissionResetKeyCapture)
|
||||||
|
{
|
||||||
|
McuManagerTestTool::MockOtherSideIpcMissionReply(IpcMission::TEST);
|
||||||
|
MainThread::GetInstance()->Init();
|
||||||
|
TestManager::ResetTimeOut(1000 * 3);
|
||||||
|
HalTestTool::MockKeyClick("reset", 200); // Simulate pressing a button.
|
||||||
|
MainThread::GetInstance()->Runing();
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/LinuxApi/include
|
${UTILS_SOURCE_PATH}/LinuxApi/include
|
||||||
${UTILS_SOURCE_PATH}/UpgradeTool/include
|
${UTILS_SOURCE_PATH}/UpgradeTool/include
|
||||||
|
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||||
${TEST_SOURCE_PATH}
|
${TEST_SOURCE_PATH}
|
||||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/include
|
${TEST_SOURCE_PATH}/middleware/AppManager/tool/include
|
||||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/src
|
${TEST_SOURCE_PATH}/middleware/AppManager/tool/src
|
||||||
|
@ -36,7 +37,7 @@ include_directories(
|
||||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET MissionManagerTestTool)
|
set(TEST_TOOL_TARGET MissionManagerTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
target_link_libraries(${TEST_TOOL_TARGET} MissionManager AppManagerTestTool MediaManagerTestTool UpgradeTool StatusCode Log)
|
target_link_libraries(${TEST_TOOL_TARGET} MissionManager AppManagerTestTool MediaManagerTestTool KeyControl UpgradeTool StatusCode Log)
|
||||||
|
|
||||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user