diff options
-rw-r--r-- | plugins/wearable/display/bezel.c | 118 |
1 files changed, 91 insertions, 27 deletions
diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 8723f2df..537fe3fe 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -30,8 +30,15 @@ #define VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE "db/setting/wakeup_by_bezel_enable" #endif +enum bezel_type { + BEZEL_NOTSUP = 0, + BEZEL_HARD, + BEZEL_SOFT, +}; + static struct bezel_device *bezel_dev; -static int bezel_wakeup = -1; +static int bezel_wakeup = 0; +static enum bezel_type bezel_type = BEZEL_NOTSUP; static void bezel_changed_cb(keynode_t *key_nodes, void *data) { @@ -39,48 +46,96 @@ static void bezel_changed_cb(keynode_t *key_nodes, void *data) bezel_wakeup = vconf_keynode_get_bool(key_nodes); - _I("bezel wakeup condition is %d", bezel_wakeup); + _I("Bezel wakeup condition: %d", bezel_wakeup); if (disp_plgn.pm_change_internal) disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); device_notify(DEVICE_NOTIFIER_BEZEL_WAKEUP, (void *)((intptr_t)bezel_wakeup)); } -static void bezel_init(void *data) +static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) +{ + enum bezel_state bezel_state; + int ret; + + assert(key_nodes); + + bezel_state = (enum bezel_state) vconf_keynode_get_bool(key_nodes); + + ret = bezel_dev->set_sw_state(bezel_state); + + if (ret == 0) { + _I("Bezel rotary event condition is %d", bezel_state); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + } else { + _E("Failed to set bezel rotary event condition."); + } +} + +static int bezel_probe(void *data) { struct hw_info *info; - int r; + int ret; if (bezel_dev) - return; + return 0; - r = hw_get_info(BEZEL_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); - if (r < 0) { - _I("bezel shared library is not supported: %d", r); - return; + ret = hw_get_info(BEZEL_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); + if (ret < 0) { + _I("bezel shared library is not supported: %d", ret); + return -ENOTSUP; } if (!info->open) { _E("Fail to open bezel device : open(NULL)"); - return; + return -ENODEV; } - r = info->open(info, NULL, (struct hw_common **)&bezel_dev); - if (r < 0) { - _E("Fail to get bezel device structure: %d", r); - return; + ret = info->open(info, NULL, (struct hw_common **)&bezel_dev); + if (ret < 0) { + _E("Fail to get bezel device structure: %d", ret); + return ret; } - vconf_notify_key_changed(VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE, - bezel_changed_cb, NULL); + return 0; +} - r = vconf_get_bool(VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE, &bezel_wakeup); - if (r < 0) { - _E("Failed to get vconf value for wakeup by bezel enable: %d", vconf_get_ext_errno()); - bezel_wakeup = 1; +static void bezel_init(void *data) +{ + int ret; + int bezel_rotary_event; + + if (bezel_dev->get_state && bezel_dev->set_state) /* hard bezel */ + bezel_type = BEZEL_HARD; + else if (bezel_dev->get_sw_state && bezel_dev->set_sw_state) /* soft bezel */ + bezel_type = BEZEL_SOFT; + else + bezel_type == BEZEL_NOTSUP; + + if (bezel_type == BEZEL_HARD) { + vconf_notify_key_changed(VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE, bezel_changed_cb, NULL); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE, &bezel_wakeup); + if (ret == 0) + _I("Bezel wakeup condition: %d.", bezel_wakeup); + else + _E("Failed to get vconf value for wakeup by bezel enable: %d.", vconf_get_ext_errno()); + + } else if (bezel_type == BEZEL_SOFT) { + vconf_notify_key_changed(VCONFKEY_SETAPPL_ROTARY_EVENT_ENABLED_BOOL, bezel_rotary_event_cb, NULL); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_ROTARY_EVENT_ENABLED_BOOL, &bezel_rotary_event); + if (ret == 0) { + ret = bezel_dev->set_sw_state(bezel_rotary_event); + if (ret == 0) + _I("Bezel rotary event conditoin: %d.", bezel_rotary_event); + else + _E("Failed to set sw bezel state, %d.", ret); + } else { + _E("Failed to get vconf value for rotary event by bezen enabled: %d.", vconf_get_ext_errno()); + } } - - _I("bezel wakeup condition is %d", bezel_wakeup); } static void bezel_exit(void *data) @@ -102,7 +157,12 @@ static int bezel_start(enum device_flags flags) if (!bezel_dev) return 0; - return bezel_dev->set_state(BEZEL_TURNON); + if (bezel_type == BEZEL_HARD) + return bezel_dev->set_state(BEZEL_TURNON); + else if (bezel_type == BEZEL_SOFT) + return bezel_dev->set_sw_state(BEZEL_TURNON); + else + return -ENOTSUP; } static int bezel_stop(enum device_flags flags) @@ -112,10 +172,13 @@ static int bezel_stop(enum device_flags flags) if (!bezel_dev) return 0; - state = (bezel_wakeup ? BEZEL_TURNON : BEZEL_TURNOFF); - _I("set bezel state: %d", state); - - return bezel_dev->set_state(state); + if (bezel_type == BEZEL_HARD) { + state = (bezel_wakeup ? BEZEL_TURNON : BEZEL_TURNOFF); + return bezel_dev->set_state(state); + } else if (bezel_type == BEZEL_SOFT) + return bezel_dev->set_sw_state(BEZEL_TURNOFF); + else + return -ENOTSUP; } /* @@ -124,6 +187,7 @@ static int bezel_stop(enum device_flags flags) static const struct device_ops bezel_device_ops = { .priority = DEVICE_PRIORITY_HIGH, DECLARE_NAME_LEN("bezel"), + .probe = bezel_probe, .init = bezel_init, .exit = bezel_exit, .start = bezel_start, |