2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <hal/hal-common.h>
20 #include "hal-led-interface.h"
22 static hal_backend_led_funcs *hal_led_funcs = NULL;
24 -1 : failed to initialize
26 1 : succeeded to initialize
28 static int hal_initialized = 0;
30 int hal_device_led_get_backend(void)
37 ret = hal_common_get_backend(HAL_MODULE_DEVICE_LED, (void **)&hal_led_funcs);
39 _E("Failed to get led backend");
48 int hal_device_led_put_backend(void)
53 hal_common_put_backend(HAL_MODULE_DEVICE_LED, (void *)hal_led_funcs);
60 int hal_device_led_set_state(enum led_device_type type, struct led_state *state)
64 if (!hal_led_funcs && !hal_initialized) {
65 if ((ret = hal_device_led_get_backend()) < 0)
72 !(hal_led_funcs->camera_front) ||
73 !(hal_led_funcs->camera_front->set_state))
75 return hal_led_funcs->camera_front->set_state(type, state);
79 !(hal_led_funcs->camera_back) ||
80 !(hal_led_funcs->camera_back->set_state))
82 return hal_led_funcs->camera_back->set_state(type, state);
86 !(hal_led_funcs->notification) ||
87 !(hal_led_funcs->notification->set_state))
89 return hal_led_funcs->notification->set_state(type, state);
93 !(hal_led_funcs->touch_key) ||
94 !(hal_led_funcs->touch_key->set_state))
96 return hal_led_funcs->touch_key->set_state(type, state);
99 _E("Invalid led type: %d", type);
104 int hal_device_led_get_state(enum led_device_type type, struct led_state **state)
108 if (!hal_led_funcs && !hal_initialized) {
109 if ((ret = hal_device_led_get_backend()) < 0)
115 if (!hal_led_funcs ||
116 !(hal_led_funcs->camera_front) ||
117 !(hal_led_funcs->camera_front->get_state))
119 return hal_led_funcs->camera_front->get_state(type, state);
122 if (!hal_led_funcs ||
123 !(hal_led_funcs->camera_back) ||
124 !(hal_led_funcs->camera_back->get_state))
126 return hal_led_funcs->camera_back->get_state(type, state);
129 if (!hal_led_funcs ||
130 !(hal_led_funcs->notification) ||
131 !(hal_led_funcs->notification->get_state))
133 return hal_led_funcs->notification->get_state(type, state);
136 if (!hal_led_funcs ||
137 !(hal_led_funcs->touch_key) ||
138 !(hal_led_funcs->touch_key->get_state))
140 return hal_led_funcs->touch_key->get_state(type, state);
143 _E("Invalid led type: %d", type);
148 int hal_device_led_get_number(void)
152 if (!hal_led_funcs && !hal_initialized) {
153 if ((ret = hal_device_led_get_backend()) < 0)
157 if (!hal_led_funcs ||
158 !(hal_led_funcs->notification) ||
159 !(hal_led_funcs->notification->get_number))
162 return hal_led_funcs->notification->get_number();
165 int hal_device_led_set_number(int number)
169 if (!hal_led_funcs && !hal_initialized) {
170 if ((ret = hal_device_led_get_backend()) < 0)
174 if (!hal_led_funcs ||
175 !(hal_led_funcs->notification) ||
176 !(hal_led_funcs->notification->set_num))
179 hal_led_funcs->notification->set_num(number);
184 int hal_device_led_get_max_num(void)
188 if (!hal_led_funcs && !hal_initialized) {
189 if ((ret = hal_device_led_get_backend()) < 0)
193 if (!hal_led_funcs ||
194 !(hal_led_funcs->notification) ||
195 !(hal_led_funcs->notification->get_max_num))
198 return hal_led_funcs->notification->get_max_num();
201 int hal_device_keyled_set_state(struct keyled_state *state)
205 if (!hal_led_funcs && !hal_initialized) {
206 if ((ret = hal_device_led_get_backend()) < 0)
210 if (!hal_led_funcs ||
211 !(hal_led_funcs->touch_key) ||
212 !(hal_led_funcs->touch_key->keyled_set_state))
215 return hal_led_funcs->touch_key->keyled_set_state(state);
218 int hal_device_keyled_get_state(int *keycode, int *brightness)
222 if (!hal_led_funcs && !hal_initialized) {
223 if ((ret = hal_device_led_get_backend()) < 0)
227 if (!hal_led_funcs ||
228 !(hal_led_funcs->touch_key) ||
229 !(hal_led_funcs->touch_key->keyled_get_state))
232 return hal_led_funcs->touch_key->keyled_get_state(keycode, brightness);