4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include "display-ops.h"
26 #include "core/common.h"
27 #include "core/device-notifier.h"
28 #include "core/edbus-handler.h"
33 #define SIGNAL_HBM_OFF "HBMOff"
35 #define DEFAULT_BRIGHTNESS_LEVEL 80
37 static Ecore_Timer *timer = NULL;
38 static struct timespec offtime;
39 static char *hbm_path;
41 static void broadcast_hbm_off(void)
43 broadcast_edbus_signal(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
44 SIGNAL_HBM_OFF, NULL, NULL);
47 static void hbm_set_offtime(int timeout)
56 clock_gettime(CLOCK_REALTIME, &now);
57 offtime.tv_sec = now.tv_sec + timeout;
60 static Eina_Bool hbm_off_cb(void *data)
66 if (pm_cur_state != S_NORMAL) {
67 _D("hbm timeout! but it's not lcd normal");
72 ret = sys_set_str(hbm_path, OFF);
74 _E("Failed to off hbm");
76 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
77 DEFAULT_BRIGHTNESS_LEVEL);
78 backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL);
79 backlight_ops.update();
85 static void hbm_start_timer(int timeout)
88 ecore_timer_del(timer);
92 timer = ecore_timer_add(timeout,
97 static void hbm_end_timer(void)
100 ecore_timer_del(timer);
105 int hbm_get_state(void)
113 ret = sys_get_str(hbm_path, state);
117 if (!strncmp(state, ON, strlen(ON)))
119 else if (!strncmp(state, OFF, strlen(OFF)))
127 int hbm_set_state(int hbm)
132 return sys_set_str(hbm_path, (hbm ? ON : OFF));
135 int hbm_set_state_with_timeout(int hbm, int timeout)
139 if (hbm && (timeout <= 0))
142 ret = hbm_set_state(hbm);
146 _D("timeout is %d", timeout);
150 * hbm is turned off after timeout.
152 hbm_set_offtime(timeout);
153 hbm_start_timer(timeout);
163 void hbm_check_timeout(void)
169 ecore_timer_del(timer);
173 if (offtime.tv_sec == 0) {
174 if (hbm_get_state() == true) {
175 _E("It's invalid state. hbm is off");
176 hbm_set_state(false);
181 clock_gettime(CLOCK_REALTIME, &now);
182 _D("now %d, offtime %d", now.tv_sec, offtime.tv_sec);
184 /* check it's timeout */
185 if (now.tv_sec >= offtime.tv_sec) {
188 ret = sys_set_str(hbm_path, OFF);
190 _E("Failed to off hbm");
191 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
192 DEFAULT_BRIGHTNESS_LEVEL);
193 backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL);
194 backlight_ops.update();
197 _D("hbm state is restored!");
199 hbm_start_timer(offtime.tv_sec - now.tv_sec);
203 static int lcd_state_changed(void *data)
205 int state = (int)data;
210 /* restore hbm when old state is dim */
211 if (pm_old_state == S_LCDDIM)
215 if (hbm_get_state() == true) {
216 ret = hbm_set_state(false);
218 _E("Failed to off hbm!");
230 static void hbm_init(void *data)
234 hbm_path = getenv("HBM_NODE");
236 /* Check HBM node is valid */
237 fd = open(hbm_path, O_RDONLY);
244 /* register notifier */
245 register_notifier(DEVICE_NOTIFIER_LCD, lcd_state_changed);
248 static void hbm_exit(void *data)
250 /* unregister notifier */
251 unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_state_changed);
254 static const struct display_ops display_hbm_ops = {
260 DISPLAY_OPS_REGISTER(&display_hbm_ops)