[zhoulongyu]: 完善Led 适配层和中间件的接口
This commit is contained in:
parent
9a6ca65cde
commit
532598fbaa
|
@ -16,6 +16,7 @@
|
||||||
#define IHALCPP_H
|
#define IHALCPP_H
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
constexpr int INVALID_PERIOD = -1;
|
constexpr int INVALID_PERIOD = -1;
|
||||||
constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100;
|
constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100;
|
||||||
|
@ -44,6 +45,55 @@ public:
|
||||||
virtual void SetKeyHalOwner(std::shared_ptr<VKeyHalOwner> owner) {}
|
virtual void SetKeyHalOwner(std::shared_ptr<VKeyHalOwner> owner) {}
|
||||||
virtual const std::string GetKeyName(void) { return "undefine"; }
|
virtual const std::string GetKeyName(void) { return "undefine"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum class LedState
|
||||||
|
{
|
||||||
|
LED_STATE_OFF = 0,
|
||||||
|
LED_STATE_ON,
|
||||||
|
LED_STATE_GREEN,
|
||||||
|
LED_STATE_RED,
|
||||||
|
LED_STATE_YELLOW,
|
||||||
|
LED_STATE_LEVEL_0,
|
||||||
|
LED_STATE_LEVEL_1,
|
||||||
|
LED_STATE_LEVEL_2,
|
||||||
|
LED_STATE_LEVEL_3,
|
||||||
|
LED_STATE_LEVEL_4,
|
||||||
|
LED_STATE_LEVEL_END,
|
||||||
|
LED_STATE_END
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class VLedHal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VLedHal() = default;
|
||||||
|
~VLedHal() = default;
|
||||||
|
virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
virtual StatusCode GetLedName(std::string &LedName) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
class WifiLed : public VLedHalOwner, public VLedHal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WifiLed() = default;
|
||||||
|
~WifiLed() = default;
|
||||||
|
|
||||||
|
// StatusCode SetLedHalOwner(std::shared_ptr<VLedHalOwner> owner) override;
|
||||||
|
StatusCode SetLedState(const LedState &state) override;
|
||||||
|
StatusCode GetLedName(std::string &LedName) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// VLedHalOwner m_LedHalOwner;
|
||||||
|
std::string m_LedName;
|
||||||
|
SF_LED_GPIO_IDX_E mPinRed;
|
||||||
|
SF_LED_GPIO_IDX_E mPinGreen;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class IHalCpp
|
class IHalCpp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -52,6 +102,10 @@ public:
|
||||||
static std::shared_ptr<IHalCpp> &GetInstance(std::shared_ptr<IHalCpp> *impl = nullptr);
|
static std::shared_ptr<IHalCpp> &GetInstance(std::shared_ptr<IHalCpp> *impl = nullptr);
|
||||||
virtual StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
virtual StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
virtual StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
virtual StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
virtual StatusCode GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
};
|
};
|
||||||
void CreateHalCppModule(void);
|
void CreateHalCppModule(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,8 @@ StatusCode HalCpp::UnInit(void)
|
||||||
LogInfo("HalCpp::UnInit\n");
|
LogInfo("HalCpp::UnInit\n");
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
StatusCode HalCpp::GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||||
|
{
|
||||||
|
ledHals = mLedHals;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
|
@ -22,5 +22,10 @@ public:
|
||||||
virtual ~HalCpp() = default;
|
virtual ~HalCpp() = default;
|
||||||
StatusCode Init(void) override;
|
StatusCode Init(void) override;
|
||||||
StatusCode UnInit(void) override;
|
StatusCode UnInit(void) override;
|
||||||
|
StatusCode GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::shared_ptr<VLedHal>> mLedHals;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -16,6 +16,7 @@
|
||||||
#define IDEVICEMANAGER_H
|
#define IDEVICEMANAGER_H
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "IHalCpp.h"
|
||||||
enum class IpcMission
|
enum class IpcMission
|
||||||
{
|
{
|
||||||
TEST = 0,
|
TEST = 0,
|
||||||
|
@ -29,6 +30,15 @@ enum class KeyAction
|
||||||
HOLD_UP,
|
HOLD_UP,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class VLedManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VLedManager() = default;
|
||||||
|
~VLedManager() = default;
|
||||||
|
virtual StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
};
|
||||||
|
|
||||||
class IDeviceManager
|
class IDeviceManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -38,6 +48,8 @@ public:
|
||||||
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||||
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||||
virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; }
|
virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; }
|
||||||
|
virtual const StatusCode GetLedManager(std::vector<std::shared_ptr<VLedManager>> &ledManagers) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
|
||||||
};
|
};
|
||||||
bool CreateDeviceManagerModule(void);
|
bool CreateDeviceManagerModule(void);
|
||||||
#endif
|
#endif
|
49
middleware/DeviceManager/src/DeviceManager.cpp
Normal file
49
middleware/DeviceManager/src/DeviceManager.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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 "DeviceManager.h"
|
||||||
|
|
||||||
|
const StatusCode DeviceManager::Init(void)
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<VLedHal>> ledHals;
|
||||||
|
IHalCpp::GetInstance()->GetLedHal(ledHals);
|
||||||
|
|
||||||
|
for (auto it = ledHals.begin(); it != ledHals.end(); ++it)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VLedHal> ledHal = *it;
|
||||||
|
std::shared_ptr<LedManager> ledOut = std::make_shared<LedManager>(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS);
|
||||||
|
mLedManagers.push_back(ledOut);
|
||||||
|
}
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
const StatusCode DeviceManager::UnInit(void)
|
||||||
|
{
|
||||||
|
if (!mLedManagers.empty())
|
||||||
|
{
|
||||||
|
mLedManagers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
const IpcMission DeviceManager::GetIpcMissiony(void)
|
||||||
|
{
|
||||||
|
return IpcMission::TEST;
|
||||||
|
}
|
||||||
|
const StatusCode DeviceManager::GetLedManager(std::vector<std::shared_ptr<VLedManager>> &ledManagers)
|
||||||
|
{
|
||||||
|
ledManagers = mLedManagers;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
39
middleware/DeviceManager/src/DeviceManager.h
Normal file
39
middleware/DeviceManager/src/DeviceManager.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#ifndef DEVICEMANAGER_H
|
||||||
|
#define DEVICEMANAGER_H
|
||||||
|
#include "LedManager.h"
|
||||||
|
#include "IDeviceManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceManager : public IDeviceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceManager() = default;
|
||||||
|
virtual ~DeviceManager() = default;
|
||||||
|
|
||||||
|
const StatusCode Init(void) override;
|
||||||
|
const StatusCode UnInit(void) override;
|
||||||
|
const IpcMission GetIpcMissiony(void) override;
|
||||||
|
const StatusCode GetLedManager(std::vector<std::shared_ptr<VLedManager>> &ledManagers) override;
|
||||||
|
private:
|
||||||
|
std::vector<std::shared_ptr<VLedManager>> mLedManagers;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
67
middleware/DeviceManager/src/LedManager.cpp
Normal file
67
middleware/DeviceManager/src/LedManager.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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 "LedManager.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LedManager::LedManager()
|
||||||
|
{
|
||||||
|
mLedHal = nullptr;
|
||||||
|
mCurrentState = NEW_LED_STATE;
|
||||||
|
mBlinkPeriod = BLINKING_FAST_MS;
|
||||||
|
mKeepAliveTime = DEFAULT_KEEP_ALIVE_TIME;
|
||||||
|
mStateAliveTime = 0;
|
||||||
|
}
|
||||||
|
LedManager::LedManager(std::shared_ptr<VLedHal> &LedHal, const LedState &CurrentState,
|
||||||
|
const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod)
|
||||||
|
: mLedHal(LedHal), mCurrentState(CurrentState), mKeepAliveTime(KeepAliveTime), mBlinkPeriod(BlinkPeriod)
|
||||||
|
{
|
||||||
|
mStateAliveTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StatusCode LedManager::SetLedState(LedState CurrentState, unsigned int KeepAliveTime)
|
||||||
|
{
|
||||||
|
mCurrentState = CurrentState;
|
||||||
|
mKeepAliveTime = KeepAliveTime;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StatusCode LedManager::GetLedState(LedState &CurrentState)
|
||||||
|
{
|
||||||
|
CurrentState = mCurrentState;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode LedManager::BlinkOn(LedState CurrentState, unsigned int KeepAliveTime)
|
||||||
|
{
|
||||||
|
mKeepAliveTime = KeepAliveTime;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode LedManager::BlinkOff(void)
|
||||||
|
{
|
||||||
|
mCurrentState = LedState::LED_STATE_OFF;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
57
middleware/DeviceManager/src/LedManager.h
Normal file
57
middleware/DeviceManager/src/LedManager.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#ifndef LED_MANAGER_H
|
||||||
|
#define LED_MANAGER_H
|
||||||
|
|
||||||
|
#include "IDeviceManager.h"
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
constexpr LedState NEW_LED_STATE = LedState::LED_STATE_OFF;
|
||||||
|
constexpr unsigned int LED_NOT_BLINK = 0;
|
||||||
|
constexpr unsigned int BLINKING_FAST_MS = 500;
|
||||||
|
constexpr unsigned int BLINKING_SLOW_MS = 1000;
|
||||||
|
constexpr long int DEFAULT_KEEP_ALIVE_TIME = 1500;
|
||||||
|
constexpr unsigned int DELETED_LED_STATE = -1;
|
||||||
|
constexpr unsigned int DO_NOT_KEEP_ALIVE = -2;
|
||||||
|
|
||||||
|
class LedManager : public VLedManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LedManager();
|
||||||
|
LedManager(std::shared_ptr<VLedHal> &LedHal, const LedState &CurrentState,
|
||||||
|
const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME,
|
||||||
|
const unsigned int &BlinkPeriod = BLINKING_FAST_MS
|
||||||
|
);
|
||||||
|
~LedManager() = default;
|
||||||
|
StatusCode Init(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); }
|
||||||
|
StatusCode Unit(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); }
|
||||||
|
StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StatusCode GetLedState(LedState &CurrentState) {return CreateStatusCode(STATUS_CODE_NOT_OK); }
|
||||||
|
StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_NOT_OK); }
|
||||||
|
StatusCode BlinkOff(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<VLedHal> mLedHal;
|
||||||
|
LedState mCurrentState; // 当前状态
|
||||||
|
unsigned int mBlinkPeriod; // 闪烁频率
|
||||||
|
unsigned int mKeepAliveTime; // 保持存活时间
|
||||||
|
unsigned int mStateAliveTime; // 状态保持时间
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user