• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "compatible_light_connection.h"
16 
17 #include <ctime>
18 #include <string>
19 #include <vector>
20 
21 #include "sensors_errors.h"
22 
23 namespace OHOS {
24 namespace Sensors {
25 namespace {
26 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "CompatibleLightConnection" };
27 } // namespace
28 std::vector<LightInfo> lightInfo = {
29     {"light_test", 1, 3, 1}
30 };
31 std::vector<int32_t> supportLights = { 1 };
32 
ConnectHdi()33 int32_t CompatibleLightConnection::ConnectHdi()
34 {
35     CALL_LOG_ENTER;
36     return ERR_OK;
37 }
38 
GetLightList(std::vector<LightInfo> & lightList) const39 int32_t CompatibleLightConnection::GetLightList(std::vector<LightInfo>& lightList) const
40 {
41     CALL_LOG_ENTER;
42     lightList.assign(lightInfo.begin(), lightInfo.end());
43     return ERR_OK;
44 }
45 
TurnOn(int32_t lightId,const LightColor & color,const LightAnimation & animation)46 int32_t CompatibleLightConnection::TurnOn(int32_t lightId,  const LightColor &color, const LightAnimation &animation)
47 {
48     CALL_LOG_ENTER;
49     if (std::find(supportLights.begin(), supportLights.end(), lightId) == supportLights.end()) {
50         MISC_HILOGE("Not support TurnOn lightId:%{public}d", lightId);
51         return LIGHT_ID_NOT_SUPPORT;
52     }
53     if ((animation.mode == LIGHT_MODE_BLINK || animation.mode == LIGHT_MODE_GRADIENT) &&
54         (animation.onTime <= 0 || animation.offTime <= 0)) {
55         MISC_HILOGE("animation parameter error");
56         return LIGHT_ERR;
57     }
58     if (std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId) != turnOnLights_.end()) {
59         MISC_HILOGI("lightId:%{public}d has been turnOn", lightId);
60         return ERR_OK;
61     }
62     turnOnLights_.push_back(lightId);
63     return ERR_OK;
64 }
65 
TurnOff(int32_t lightId)66 int32_t CompatibleLightConnection::TurnOff(int32_t lightId)
67 {
68     CALL_LOG_ENTER;
69     if (std::find(supportLights.begin(), supportLights.end(), lightId) == supportLights.end()) {
70         MISC_HILOGE("Not support TurnOff lightId:%{public}d", lightId);
71         return LIGHT_ID_NOT_SUPPORT;
72     }
73     if (std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId) == turnOnLights_.end()) {
74         MISC_HILOGE("lightId:%{public}d should not be turn off", lightId);
75         return LIGHT_END_ERROR;
76     }
77     std::vector<int32_t>::iterator iter = std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId);
78     turnOnLights_.erase(iter);
79     return ERR_OK;
80 }
81 
DestroyHdiConnection()82 int32_t CompatibleLightConnection::DestroyHdiConnection()
83 {
84     CALL_LOG_ENTER;
85     return ERR_OK;
86 }
87 }  // namespace Sensors
88 }  // namespace OHOS
89