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.
26 #include "display-ops.h"
27 #include "core/common.h"
28 #include "core/device-notifier.h"
29 #include "core/edbus-handler.h"
30 #include "core/config-parser.h"
32 #define BOARD_CONF_FILE "/etc/deviced/display.conf"
42 #define SIGNAL_HBM_OFF "HBMOff"
44 #define DEFAULT_BRIGHTNESS_LEVEL 80
46 struct hbm_config hbm_conf = {
50 .off_count = OFF_COUNT,
53 static Ecore_Timer *timer = NULL;
54 static struct timespec offtime;
55 static char *hbm_path;
57 static void broadcast_hbm_off(void)
59 broadcast_edbus_signal(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
60 SIGNAL_HBM_OFF, NULL, NULL);
63 static void hbm_set_offtime(int timeout)
72 clock_gettime(CLOCK_REALTIME, &now);
73 offtime.tv_sec = now.tv_sec + timeout;
76 static Eina_Bool hbm_off_cb(void *data)
82 if (pm_cur_state != S_NORMAL) {
83 _D("hbm timeout! but it's not lcd normal");
88 ret = sys_set_str(hbm_path, OFF);
90 _E("Failed to off hbm");
92 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
93 DEFAULT_BRIGHTNESS_LEVEL);
94 backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL);
95 backlight_ops.update();
101 static void hbm_start_timer(int timeout)
104 ecore_timer_del(timer);
108 timer = ecore_timer_add(timeout,
113 static void hbm_end_timer(void)
116 ecore_timer_del(timer);
121 int hbm_get_state(void)
129 ret = sys_get_str(hbm_path, state);
133 if (!strncmp(state, ON, strlen(ON)))
135 else if (!strncmp(state, OFF, strlen(OFF)))
143 int hbm_set_state(int hbm)
148 return sys_set_str(hbm_path, (hbm ? ON : OFF));
151 int hbm_set_state_with_timeout(int hbm, int timeout)
155 if (hbm && (timeout <= 0))
158 ret = hbm_set_state(hbm);
162 _D("timeout is %d", timeout);
166 * hbm is turned off after timeout.
168 hbm_set_offtime(timeout);
169 hbm_start_timer(timeout);
179 void hbm_check_timeout(void)
185 ecore_timer_del(timer);
189 if (offtime.tv_sec == 0) {
190 if (hbm_get_state() == true) {
191 _E("It's invalid state. hbm is off");
192 hbm_set_state(false);
197 clock_gettime(CLOCK_REALTIME, &now);
198 _D("now %d, offtime %d", now.tv_sec, offtime.tv_sec);
200 /* check it's timeout */
201 if (now.tv_sec >= offtime.tv_sec) {
204 ret = sys_set_str(hbm_path, OFF);
206 _E("Failed to off hbm");
207 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
208 DEFAULT_BRIGHTNESS_LEVEL);
209 backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL);
210 backlight_ops.update();
213 _D("hbm state is restored!");
215 hbm_start_timer(offtime.tv_sec - now.tv_sec);
219 static int lcd_state_changed(void *data)
221 int state = (int)data;
226 /* restore hbm when old state is dim */
227 if (pm_old_state == S_LCDDIM)
231 if (hbm_get_state() == true) {
232 ret = hbm_set_state(false);
234 _E("Failed to off hbm!");
246 static int hbm_load_config(struct parse_result *result, void *user_data)
248 struct hbm_config *c = user_data;
250 _D("%s,%s,%s", result->section, result->name, result->value);
255 if (!MATCH(result->section, "HBM"))
258 if (MATCH(result->name, "on")) {
259 SET_CONF(c->on, atoi(result->value));
260 _D("on lux is %d", c->on);
261 } else if (MATCH(result->name, "off")) {
262 SET_CONF(c->off, atoi(result->value));
263 _D("off lux is %d", c->off);
264 } else if (MATCH(result->name, "on_count")) {
265 SET_CONF(c->on_count, atoi(result->value));
266 _D("on count is %d", c->on_count);
267 } else if (MATCH(result->name, "off_count")) {
268 SET_CONF(c->off_count, atoi(result->value));
269 _D("off count is %d", c->off_count);
275 static void hbm_init(void *data)
279 hbm_path = getenv("HBM_NODE");
281 /* Check HBM node is valid */
282 fd = open(hbm_path, O_RDONLY);
289 /* load configutation */
290 ret = config_parse(BOARD_CONF_FILE, hbm_load_config, &hbm_conf);
292 _W("Failed to load %s, %s Use default value!",
293 BOARD_CONF_FILE, ret);
295 /* register notifier */
296 register_notifier(DEVICE_NOTIFIER_LCD, lcd_state_changed);
299 static void hbm_exit(void *data)
301 /* unregister notifier */
302 unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_state_changed);
305 * set default brightness
306 * if display logic is stopped in hbm state.
308 if (hbm_get_state() == true) {
310 vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,
311 DEFAULT_BRIGHTNESS_LEVEL);
312 _I("set brightness to default value!");
316 static const struct display_ops display_hbm_ops = {
322 DISPLAY_OPS_REGISTER(&display_hbm_ops)