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 "light_agent.h"
16
17 #include "light_client.h"
18 #include "sensors_errors.h"
19
20 #undef LOG_TAG
21 #define LOG_TAG "LightNDK"
22
23 namespace OHOS {
24 namespace Sensors {
25
GetLightList(LightInfo ** lightInfo,int32_t & count)26 int32_t GetLightList(LightInfo **lightInfo, int32_t &count)
27 {
28 CHKPR(lightInfo, ERROR);
29 auto &client = LightClient::GetInstance();
30 int32_t ret = client.GetLightList(lightInfo, count);
31 if (ret != ERR_OK) {
32 MISC_HILOGE("GetLightList failed");
33 return ERROR;
34 }
35 return SUCCESS;
36 }
37
TurnOn(int32_t lightId,const LightColor & color,const LightAnimation & animation)38 int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation)
39 {
40 if (lightId < 0) {
41 MISC_HILOGE("lightId is invalid");
42 return ERROR;
43 }
44 auto &client = LightClient::GetInstance();
45 int32_t ret = client.TurnOn(lightId, color, animation);
46 if (ret != ERR_OK) {
47 MISC_HILOGE("TurnOn failed, lightId:%{public}d, ret:%{public}d ", lightId, ret);
48 return ERROR;
49 }
50 return SUCCESS;
51 }
52
TurnOff(int32_t lightId)53 int32_t TurnOff(int32_t lightId)
54 {
55 if (lightId < 0) {
56 MISC_HILOGE("lightId is error");
57 return ERROR;
58 }
59 auto &client = LightClient::GetInstance();
60 int32_t ret = client.TurnOff(lightId);
61 if (ret != ERR_OK) {
62 MISC_HILOGE("TurnOff failed, lightId:%{public}d, ret:%{public}d", lightId, ret);
63 return ERROR;
64 }
65 return SUCCESS;
66 }
67 } // namespace Sensors
68 } // namespace OHOS
69