mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
83 lines
2.8 KiB
C++
83 lines
2.8 KiB
C++
/*
|
|
* 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 "HalCpp.h"
|
|
#include "HalMakePtr.h"
|
|
#include "ILog.h"
|
|
#include "SdCardHal.h"
|
|
StatusCode HalCpp::Init(void)
|
|
{
|
|
LogInfo("HalCpp::Init\n");
|
|
HalMakePtr::GetInstance()->CreateWifiHal(mWifiHal);
|
|
HalMakePtr::GetInstance()->CreateSdCardHal(mSdCardHal);
|
|
std::shared_ptr<SdCardHal> sdCardImpl = std::dynamic_pointer_cast<SdCardHal>(mSdCardHal);
|
|
if (nullptr != sdCardImpl) {
|
|
sdCardImpl->Init();
|
|
}
|
|
HalMakePtr::GetInstance()->CreateAllKeyHal(mKeys);
|
|
// auto checkPinValue = [](std::shared_ptr<HalCpp> impl) {
|
|
// LogInfo("HalCpp::CheckAllPinVauleThread start\n");
|
|
// impl->CheckAllPinVauleThread();
|
|
// };
|
|
// mCheckPinThread = std::thread(checkPinValue, shared_from_this());
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode HalCpp::UnInit(void)
|
|
{
|
|
LogInfo("HalCpp::UnInit\n");
|
|
std::shared_ptr<SdCardHal> sdCardImpl = std::dynamic_pointer_cast<SdCardHal>(mSdCardHal);
|
|
if (nullptr != sdCardImpl) {
|
|
sdCardImpl->UnInit();
|
|
}
|
|
mThreadRuning = false;
|
|
if (mCheckPinThread.joinable()) {
|
|
mCheckPinThread.join();
|
|
}
|
|
mWifiHal.reset();
|
|
mSdCardHal.reset();
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode HalCpp::GetWifiHal(std::shared_ptr<VWifiHal> &wifi)
|
|
{
|
|
wifi = mWifiHal;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode HalCpp::GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard)
|
|
{
|
|
sdCard = mSdCardHal;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode HalCpp::GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
|
{
|
|
LogInfo("GetAllKeys\n");
|
|
for (auto &key : mKeys) {
|
|
std::shared_ptr<VKeyHal> keyControl = std::dynamic_pointer_cast<VKeyHal>(key);
|
|
if (nullptr == keyControl) {
|
|
LogError("keyControl is nullptr\n");
|
|
continue;
|
|
}
|
|
allKeys.insert(std::make_pair(key->GetKeyName(), keyControl));
|
|
}
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
void HalCpp::CheckAllPinVauleThread(void)
|
|
{
|
|
// mThreadRuning = true;
|
|
// while (mThreadRuning) {
|
|
// for (auto &keyHalImpl : mKeys) {
|
|
// }
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(PERIPHERAL_CHECK_PERIOD_MS));
|
|
// }
|
|
}
|