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 }
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 (std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId) != turnOnLights_.end()) {
54 MISC_HILOGI("lightId:%{public}d has been turnOn", lightId);
55 return ERR_OK;
56 }
57 turnOnLights_.push_back(lightId);
58 return ERR_OK;
59 }
60
TurnOff(int32_t lightId)61 int32_t CompatibleLightConnection::TurnOff(int32_t lightId)
62 {
63 CALL_LOG_ENTER;
64 if (std::find(supportLights.begin(), supportLights.end(), lightId) == supportLights.end()) {
65 MISC_HILOGE("not support TurnOff lightId:%{public}d", lightId);
66 return LIGHT_ID_NOT_SUPPORT;
67 }
68 if (std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId) == turnOnLights_.end()) {
69 MISC_HILOGE("lightId:%{public}d should not be turn off", lightId);
70 return LIGHT_END_ERROR;
71 }
72 std::vector<int32_t>::iterator iter = std::find(turnOnLights_.begin(), turnOnLights_.end(), lightId);
73 turnOnLights_.erase(iter);
74 return ERR_OK;
75 }
76
DestroyHdiConnection()77 int32_t CompatibleLightConnection::DestroyHdiConnection()
78 {
79 CALL_LOG_ENTER;
80 return ERR_OK;
81 }
82 } // namespace Sensors
83 } // namespace OHOS
84