hunting/middleware/DeviceManager/src/LedManager.h

59 lines
2.2 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.
*/
#ifndef LED_MANAGER_H
#define LED_MANAGER_H
#include "IDeviceManager.h"
#include "IHalCpp.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(std::string ledName, LedState &CurrentState,
const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME,
const unsigned int &BlinkPeriod = LED_NOT_BLINK) override;
public:
StatusCode GetLedState(LedState &CurrentState);
StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime);
StatusCode BlinkOff(void);
private:
std::shared_ptr<VLedHal> mLedHal;
LedState mCurrentState; // 当前状态
unsigned int mBlinkPeriod; // 闪烁频率
unsigned int mKeepAliveTime; // 保持存活时间
unsigned int mStateAliveTime; // 状态保持时间
};
#endif