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
16 #include "light_interface_impl.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include "light_if.h"
20
21 #define HDF_LOG_TAG hdf_light_dal
22
23 namespace OHOS {
24 namespace HDI {
25 namespace Light {
26 namespace V1_0 {
GetLightInfo(std::vector<HdfLightInfo> & info)27 int32_t LightInterfaceImpl::GetLightInfo(std::vector<HdfLightInfo>& info)
28 {
29 const struct LightInterface *lightInterface = NewLightInterfaceInstance();
30 if (lightInterface == NULL || lightInterface->GetLightInfo == NULL) {
31 HDF_LOGE("%{public}s: get light Module instance failed", __func__);
32 return HDF_FAILURE;
33 }
34
35 struct LightInfo *lightInfo = nullptr;
36 uint32_t count = 0;
37 int32_t ret = lightInterface->GetLightInfo(&lightInfo, &count);
38 if (ret != HDF_SUCCESS) {
39 HDF_LOGE("%{public}s failed, error code is %d", __func__, ret);
40 return ret;
41 }
42
43 while (count--) {
44 HdfLightInfo hdfLightInfo;
45 hdfLightInfo.lightId = lightInfo->lightId;
46 hdfLightInfo.reserved = lightInfo->reserved;
47 info.push_back(hdfLightInfo);
48 lightInfo++;
49 }
50 return HDF_SUCCESS;
51 }
52
TurnOnLight(int32_t lightId,const HdfLightEffect & effect)53 int32_t LightInterfaceImpl::TurnOnLight(int32_t lightId, const HdfLightEffect& effect)
54 {
55 const struct LightInterface *lightInterface = NewLightInterfaceInstance();
56 if (lightInterface == NULL || lightInterface->TurnOnLight == NULL) {
57 HDF_LOGE("%{public}s: get light Module instance failed", __func__);
58 return HDF_FAILURE;
59 }
60
61 LightEffect lightEffect;
62 lightEffect.lightBrightness = effect.lightBrightness;
63 lightEffect.flashEffect.flashMode = effect.flashEffect.flashMode;
64 lightEffect.flashEffect.onTime = effect.flashEffect.onTime;
65 lightEffect.flashEffect.offTime = effect.flashEffect.offTime;
66 int32_t ret = lightInterface->TurnOnLight(lightId, &lightEffect);
67 if (ret != HDF_SUCCESS) {
68 HDF_LOGE("%{public}s failed, error code is %d", __func__, ret);
69 }
70
71 return ret;
72 }
73
TurnOffLight(int32_t LightId)74 int32_t LightInterfaceImpl::TurnOffLight(int32_t LightId)
75 {
76 const struct LightInterface *lightInterface = NewLightInterfaceInstance();
77 if (lightInterface == NULL || lightInterface->TurnOffLight == NULL) {
78 HDF_LOGE("%{public}s: get light Module instance faild", __func__);
79 return HDF_FAILURE;
80 }
81 int32_t ret = lightInterface->TurnOffLight(LightId);
82 if (ret != HDF_SUCCESS) {
83 HDF_LOGE("%{public}s failed, error code is %d", __func__, ret);
84 }
85
86 return ret;
87 }
88 } // V1_0
89 } // Light
90 } // HDI
91 } // OHOS
92