summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/iot/display/key-filter.c80
-rw-r--r--plugins/mobile/display/key-filter.c36
-rw-r--r--plugins/tv/display/key-filter.c80
-rw-r--r--plugins/wearable/display/key-filter.c36
-rwxr-xr-xsrc/battery/mrgtmp0426
-rwxr-xr-xsrc/led/mrgtmp0323
6 files changed, 22 insertions, 959 deletions
diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c
index cf6cfa76..6ef373c5 100644
--- a/plugins/iot/display/key-filter.c
+++ b/plugins/iot/display/key-filter.c
@@ -149,11 +149,7 @@ static void longkey_pressed()
return;
}
-
- if (display_conf.lcd_always_on)
- opt = POWEROFF_ACT;
- else
- opt = PWROFF_POPUP_ACT;
+ opt = POWEROFF_ACT;
power_execute(opt);
}
@@ -311,82 +307,10 @@ static int process_menu_key(struct input_event *pinput)
return false;
}
-static int decide_lcdoff(void)
-{
- /* It's not needed if it's already LCD off state */
- if (!current_state_in_on() &&
- backlight_ops.get_lcd_power() != DPMS_ON)
- return false;
-
- /*
- * This flag is set at the moment
- * that LCD is turned on by power key
- * LCD has not to turned off in the situation.
- */
- if (skip_lcd_off)
- return false;
-
- /* LCD is not turned off when powerkey is pressed,not released */
- if (key_combination == KEY_COMBINATION_POWERKEY)
- return false;
-
- /* LCD-off is blocked at the moment poweroff popup shows */
- if (cancel_lcdoff)
- return false;
-
- /* LCD-off is blocked when powerkey and volmedown key are pressed */
- if (skip_combination)
- return false;
-
- /* At booting time, display must do not turn off */
- if (!booting_done(NULL))
- return false;
-
- return true;
-}
-
-static int lcdoff_powerkey(void)
-{
- int ignore = true;
-
- if (decide_lcdoff() == true) {
- check_processes(S_NORMAL);
- check_processes(S_LCDDIM);
-
- if (!check_holdkey_block(S_NORMAL) &&
- !check_holdkey_block(S_LCDDIM)) {
- if (display_info.update_auto_brightness)
- display_info.update_auto_brightness(false);
- switch_off_lcd();
- delete_condition(S_NORMAL);
- delete_condition(S_LCDDIM);
- update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY);
- if (disp_plgn.pm_change_internal)
- disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF);
- }
- } else {
- ignore = false;
- skip_combination = false;
- }
- cancel_lcdoff = 0;
-
- return ignore;
-}
-
static bool release_short_powerkey(void)
{
-// mobile d - no, a - no
-// wearable d - yes, a - no
// tv d - no, a - yes
- if (!display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- lcdoff_powerkey();
- return true;
- } else if (display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- if (skip_lcd_off)
- return false;
- else
- return true;
- } else if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
+ if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
longkey_pressed();
return false;
}
diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c
index cf6cfa76..6789e715 100644
--- a/plugins/mobile/display/key-filter.c
+++ b/plugins/mobile/display/key-filter.c
@@ -149,11 +149,7 @@ static void longkey_pressed()
return;
}
-
- if (display_conf.lcd_always_on)
- opt = POWEROFF_ACT;
- else
- opt = PWROFF_POPUP_ACT;
+ opt = PWROFF_POPUP_ACT;
power_execute(opt);
}
@@ -373,27 +369,6 @@ static int lcdoff_powerkey(void)
return ignore;
}
-static bool release_short_powerkey(void)
-{
-// mobile d - no, a - no
-// wearable d - yes, a - no
-// tv d - no, a - yes
- if (!display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- lcdoff_powerkey();
- return true;
- } else if (display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- if (skip_lcd_off)
- return false;
- else
- return true;
- } else if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
- longkey_pressed();
- return false;
- }
-
- return true;
-}
-
static int process_power_key(struct input_event *pinput)
{
int ignore = true;
@@ -406,7 +381,14 @@ static int process_power_key(struct input_event *pinput)
case KEY_RELEASED:
check_key_pair(pinput->code, pinput->value, &value);
- ignore = release_short_powerkey();
+ if (!display_conf.powerkey_doublepress) {
+ if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF))
+ lcdoff_powerkey();
+ else
+ _D("No lcdoff capability!");
+ } else if (skip_lcd_off) {
+ ignore = false;
+ }
if (!display_has_caps(caps, DISPLAY_CAPA_LCDON))
ignore = true;
diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c
index cf6cfa76..6ef373c5 100644
--- a/plugins/tv/display/key-filter.c
+++ b/plugins/tv/display/key-filter.c
@@ -149,11 +149,7 @@ static void longkey_pressed()
return;
}
-
- if (display_conf.lcd_always_on)
- opt = POWEROFF_ACT;
- else
- opt = PWROFF_POPUP_ACT;
+ opt = POWEROFF_ACT;
power_execute(opt);
}
@@ -311,82 +307,10 @@ static int process_menu_key(struct input_event *pinput)
return false;
}
-static int decide_lcdoff(void)
-{
- /* It's not needed if it's already LCD off state */
- if (!current_state_in_on() &&
- backlight_ops.get_lcd_power() != DPMS_ON)
- return false;
-
- /*
- * This flag is set at the moment
- * that LCD is turned on by power key
- * LCD has not to turned off in the situation.
- */
- if (skip_lcd_off)
- return false;
-
- /* LCD is not turned off when powerkey is pressed,not released */
- if (key_combination == KEY_COMBINATION_POWERKEY)
- return false;
-
- /* LCD-off is blocked at the moment poweroff popup shows */
- if (cancel_lcdoff)
- return false;
-
- /* LCD-off is blocked when powerkey and volmedown key are pressed */
- if (skip_combination)
- return false;
-
- /* At booting time, display must do not turn off */
- if (!booting_done(NULL))
- return false;
-
- return true;
-}
-
-static int lcdoff_powerkey(void)
-{
- int ignore = true;
-
- if (decide_lcdoff() == true) {
- check_processes(S_NORMAL);
- check_processes(S_LCDDIM);
-
- if (!check_holdkey_block(S_NORMAL) &&
- !check_holdkey_block(S_LCDDIM)) {
- if (display_info.update_auto_brightness)
- display_info.update_auto_brightness(false);
- switch_off_lcd();
- delete_condition(S_NORMAL);
- delete_condition(S_LCDDIM);
- update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY);
- if (disp_plgn.pm_change_internal)
- disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF);
- }
- } else {
- ignore = false;
- skip_combination = false;
- }
- cancel_lcdoff = 0;
-
- return ignore;
-}
-
static bool release_short_powerkey(void)
{
-// mobile d - no, a - no
-// wearable d - yes, a - no
// tv d - no, a - yes
- if (!display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- lcdoff_powerkey();
- return true;
- } else if (display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- if (skip_lcd_off)
- return false;
- else
- return true;
- } else if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
+ if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
longkey_pressed();
return false;
}
diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c
index 051a12d1..a6cb3fc6 100644
--- a/plugins/wearable/display/key-filter.c
+++ b/plugins/wearable/display/key-filter.c
@@ -160,11 +160,7 @@ static void longkey_pressed()
return;
}
-
- if (display_conf.lcd_always_on)
- opt = POWEROFF_ACT;
- else
- opt = PWROFF_POPUP_ACT;
+ opt = PWROFF_POPUP_ACT;
power_execute(opt);
}
@@ -392,27 +388,6 @@ static int lcdoff_powerkey(void)
return ignore;
}
-static bool release_short_powerkey(void)
-{
-// mobile d - no, a - no
-// wearable d - yes, a - no
-// tv d - no, a - yes
- if (!display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- lcdoff_powerkey();
- return true;
- } else if (display_conf.powerkey_doublepress && !display_conf.lcd_always_on) {
- if (skip_lcd_off)
- return false;
- else
- return true;
- } else if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) {
- longkey_pressed();
- return false;
- }
-
- return true;
-}
-
static int process_back_key(struct input_event *pinput)
{
int ignore = true;
@@ -438,7 +413,14 @@ static int process_power_key(struct input_event *pinput)
case KEY_RELEASED:
check_key_pair(pinput->code, pinput->value, &value);
- ignore = release_short_powerkey();
+ if (!display_conf.powerkey_doublepress) {
+ if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF))
+ lcdoff_powerkey();
+ else
+ _D("No lcdoff capability!");
+ } else if (skip_lcd_off) {
+ ignore = false;
+ }
if (!display_has_caps(caps, DISPLAY_CAPA_LCDON))
ignore = true;
diff --git a/src/battery/mrgtmp0 b/src/battery/mrgtmp0
deleted file mode 100755
index a56b65a8..00000000
--- a/src/battery/mrgtmp0
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <vconf.h>
-#include <device-node.h>
-#include <hw/battery.h>
-#include <libsyscommon/dbus-system.h>
-
-#include "core/common.h"
-#include "core/devices.h"
-#include "core/log.h"
-#include "core/udev.h"
-#include "display/setting.h"
-#include "display/display-ops.h"
-#include "power-supply.h"
-
-#define CHARGING_STATE(x) ((x) & CHRGR_FLAG)
-#define FULL_CAPACITY (100)
-#define BATTERY_FULL_THRESHOLD (98)
-#define MAX_COUNT_UNCHARGING (10)
-#define MAX_COUNT_CHARGING (10)
-#define PRINT_ALL_BATT_NODE(x) /*print_all_batt_node(x)*/
-#define POLLING_TIME (30) /* seconds */
-
-#define SIGNAL_TIMETOFULL "TimeToFull"
-#define SIGNAL_TIMETOEMPTY "TimeToEmpty"
-
-enum state_b {
- B_UNCHARGING = 0,
- B_CHARGING = 1,
- B_END = 2
-};
-
-struct Batt_node {
- time_t clock;
- int capacity;
- struct Batt_node *preview;
- struct Batt_node *next;
-};
-
-enum state_a {
- A_TIMETOEMPTY = 0,
- A_TIMETOFULL = 1,
- A_END = 2
-};
-
-static guint timeout_id;
-
-static struct Batt_node *batt_head[B_END];
-static struct Batt_node *batt_tail[B_END];
-static int MAX_VALUE_COUNT[B_END] = {MAX_COUNT_UNCHARGING, MAX_COUNT_CHARGING};
-static double avg_factor[B_END] = {-1.0, -1.0};
-static int old_capacity;
-static int charging_state;
-static int time_to_full = -1;
-static int time_to_empty = -1;
-
-int get_charging_status(int *val)
-{
- int ret;
-
- ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
- if (ret < 0)
- _E("Failed to get vconf value for battery charge now: %d", ret);
-
- return ret;
-}
-
-static int add_batt_node(enum state_b b_index, time_t clock, int capacity)
-{
- struct Batt_node *node = NULL;
-
- PRINT_ALL_BATT_NODE(b_index);
-
- if (b_index < 0 || b_index >= B_END)
- return -1;
-
- node = (struct Batt_node *) malloc(sizeof(struct Batt_node));
- if (node == NULL) {
- _E("Failed to add battery node. Not enough memory.");
- return -1;
- }
-
- node->clock = clock;
- node->capacity = capacity;
-
- if (batt_head[b_index] == NULL && batt_tail[b_index] == NULL) {
- batt_head[b_index] = batt_tail[b_index] = node;
- node->preview = NULL;
- node->next = NULL;
- } else {
- node->next = batt_head[b_index];
- node->preview = NULL;
- batt_head[b_index]->preview = node;
- batt_head[b_index] = node;
- }
- PRINT_ALL_BATT_NODE(b_index);
- return 0;
-}
-
-static int reap_batt_node(enum state_b b_index, int max_count)
-{
- struct Batt_node *node = NULL;
- struct Batt_node *tmp = NULL;
- int cnt = 0;
-
- PRINT_ALL_BATT_NODE(b_index);
-
- if (b_index < 0 || b_index >= B_END)
- return -1;
-
- if (max_count <= 0)
- return -1;
-
- node = batt_head[b_index];
-
- while (node != NULL) {
- if (cnt >= max_count) break;
- cnt++;
- node = node->next;
- }
-
- if (node != NULL && node != batt_tail[b_index]) {
- batt_tail[b_index] = node;
- node = node->next;
- batt_tail[b_index]->next = NULL;
- while (node != NULL) {
- tmp = node;
- node = node->next;
- free(tmp);
- }
- }
- PRINT_ALL_BATT_NODE(b_index);
- return 0;
-}
-
-static int del_all_batt_node(enum state_b b_index)
-{
- struct Batt_node *node = NULL;
-
- PRINT_ALL_BATT_NODE(b_index);
-
- if (b_index < 0 || b_index >= B_END)
- return -1;
- if (batt_head[b_index] == NULL)
- return 0;
-
- while (batt_head[b_index] != NULL) {
- node = batt_head[b_index];
- batt_head[b_index] = batt_head[b_index]->next;
- free(node);
- }
- batt_tail[b_index] = NULL;
- PRINT_ALL_BATT_NODE(b_index);
- return 0;
-}
-
-static float update_factor(enum state_b b_index)
-{
- struct Batt_node *node = NULL;
- double factor = 0.0;
- double total_factor = 0.0;
- int cnt = 0;
- double timediff = 0.0;
- double capadiff = 0.0;
-
- if (b_index < 0 || b_index >= B_END)
- return 0;
-
- if (batt_head[b_index] == NULL || batt_head[b_index]->next == NULL)
- return avg_factor[b_index];
-
- node = batt_head[b_index];
- while (1) {
- timediff = difftime(node->clock, node->next->clock);
- capadiff = node->capacity - node->next->capacity;
- if (capadiff < 0)
- capadiff *= (-1);
- if (capadiff != 0)
- factor = timediff / capadiff;
- total_factor += factor;
-
- node = node->next;
- cnt++;
-
- /*_I("[%d] timediff(%lf) / capadiff(%lf) = factor(%lf)",
- cnt, timediff, capadiff, factor);*/
- factor = 0.0;
-
- if (node == NULL || node->next == NULL)
- break;
- if (cnt >= MAX_VALUE_COUNT[b_index]) {
- reap_batt_node(b_index, MAX_VALUE_COUNT[b_index]);
- break;
- }
- }
- total_factor /= (float)cnt;
-
- return total_factor;
-}
-
-static void broadcast_battery_time(char *signal, int time)
-{
- if (!signal)
- return;
-
- dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
- signal, g_variant_new("(i)", time));
-}
-
-static void update_time(enum state_a a_index, int seconds)
-{
- if (a_index < 0 || a_index >= A_END)
- return;
-
- if (seconds <= 0)
- return;
-
- switch (a_index) {
- case A_TIMETOFULL:
- broadcast_battery_time(SIGNAL_TIMETOFULL, seconds);
- time_to_full = seconds;
- break;
- case A_TIMETOEMPTY:
- broadcast_battery_time(SIGNAL_TIMETOEMPTY, seconds);
- time_to_empty = seconds;
- break;
- default:
- break;
- }
-}
-
-static int battinfo_calculation(void)
-{
- time_t clock;
- int capacity = 0;
- int estimated_time = 0;
- int tmp = 0;
-
- capacity = battery.capacity;
-
- if (capacity <= 0)
- return -1;
- if (capacity == old_capacity)
- return 0;
-
- old_capacity = capacity;
-
- if (get_charging_status(&tmp) == 0)
- charging_state = (tmp > 0 ? TRUE : FALSE);
-
- clock = time(NULL);
- if (charging_state == TRUE) {
- del_all_batt_node(B_UNCHARGING);
- if ((capacity * 100 / FULL_CAPACITY)
- >= BATTERY_FULL_THRESHOLD) {
- if (battery.charge_full == CHARGING_FULL) {
- del_all_batt_node(B_CHARGING);
- _I("Battery fully charged.");
- update_time(A_TIMETOFULL, 0);
- return 0;
- }
- }
- if (batt_head[B_CHARGING] == NULL) {
- add_batt_node(B_CHARGING, clock, capacity);
- } else {
- add_batt_node(B_CHARGING, clock, capacity);
- avg_factor[B_CHARGING] = update_factor(B_CHARGING);
- }
- estimated_time = (float)(FULL_CAPACITY - capacity) *
- avg_factor[B_CHARGING];
- update_time(A_TIMETOFULL, estimated_time);
- } else {
- del_all_batt_node(B_CHARGING);
- if (disp_plgn.system_wakeup_flag == true) {
- del_all_batt_node(B_UNCHARGING);
- disp_plgn.system_wakeup_flag = false;
- }
- if (batt_head[B_UNCHARGING] == NULL) {
- add_batt_node(B_UNCHARGING, clock, capacity);
- } else {
- add_batt_node(B_UNCHARGING, clock, capacity);
- avg_factor[B_UNCHARGING] = update_factor(B_UNCHARGING);
- }
- estimated_time = (float)capacity * avg_factor[B_UNCHARGING];
- update_time(A_TIMETOEMPTY, estimated_time);
- }
- return 0;
-}
-
-static gboolean battinfo_cb(void *data)
-{
- battinfo_calculation();
- return G_SOURCE_CONTINUE;
-}
-
-static int start_battinfo_gathering(int timeout)
-{
- _I("Start battery gathering.");
-
- if (timeout <= 0) {
- _E("Invalid timeout value(%d).", timeout);
- return -1;
- }
-
- old_capacity = 0;
- battinfo_calculation();
-
- if (timeout > 0) {
- /* Using g_timer for gathering battery info */
- timeout_id = g_timeout_add_seconds(timeout, battinfo_cb, NULL);
- }
-
- return 0;
-}
-
-static void end_battinfo_gathering(void)
-{
- _I("End battery gathering.");
-
- if (timeout_id) {
- g_source_remove(timeout_id);
- timeout_id = 0;
- }
-
- del_all_batt_node(B_UNCHARGING);
- del_all_batt_node(B_CHARGING);
-}
-
-GVariant * dbus_get_timetofull(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-{
- int val;
-
- val = time_to_full;
-
- _D("Get time=%d", val);
-
- return g_variant_new("(i)", val);
-}
-
-static GVariant * dbus_get_timetoempty(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-{
- int val;
-
- val = time_to_empty;
-
- _D("Get time=%d", val);
-
- return g_variant_new("(i)", val);
-}
-
-static const dbus_method_s dbus_methods[] = {
- { SIGNAL_TIMETOFULL, NULL, "i", dbus_get_timetofull },
- { SIGNAL_TIMETOEMPTY, NULL, "i", dbus_get_timetoempty },
- /* Add methods here */
-};
-
-static const dbus_interface_u dbus_interface = {
- .oh = NULL,
- .name = DEVICED_INTERFACE_BATTERY,
- .methods = dbus_methods,
- .nr_methods = ARRAY_SIZE(dbus_methods),
-};
-
-static int battery_probe(void *data)
-{
- struct hw_info *info;
- int ret;
-
- ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- if (ret < 0) /* There is no HAL for battery */
- return -ENODEV;
-
- return 0;
-}
-
-static void battery_init(void *data)
-{
- int ret;
-
- ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface);
- if (ret < 0)
- _E("Failed to init dbus method: %d", ret);
-
- start_battinfo_gathering(POLLING_TIME);
-}
-
-static void battery_exit(void *data)
-{
- end_battinfo_gathering();
-}
-
-static const struct device_ops battery_time_device_ops = {
- .name = "battery-time",
- .probe = battery_probe,
- .init = battery_init,
- .exit = battery_exit,
-};
-
-DEVICE_OPS_REGISTER(&battery_time_device_ops)
-
diff --git a/src/led/mrgtmp0 b/src/led/mrgtmp0
deleted file mode 100755
index c7fbf3d4..00000000
--- a/src/led/mrgtmp0
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <vconf.h>
-#include <hw/led.h>
-#include <libsyscommon/dbus-system.h>
-
-#include "core/log.h"
-#include "core/devices.h"
-#include "core/device-notifier.h"
-#include "display/core.h"
-#include "display/setting.h"
-#include "display/display-ops.h"
-#include "touch-key.h"
-
-#define KEYBACKLIGHT_TIME_90 90 /* 1.5 second */
-#define KEYBACKLIGHT_TIME_360 360 /* 6 second */
-#define KEYBACKLIGHT_TIME_ALWAYS_ON -1 /* always on */
-#define KEYBACKLIGHT_TIME_ALWAYS_OFF 0 /* always off */
-#define KEYBACKLIGHT_BASE_TIME 60 /* 1min = 60sec */
-#define KEYBACKLIGHT_PRESSED_TIME 15 /* 15 second */
-
-#ifndef VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION
-#define VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION VCONFKEY_SETAPPL_PREFIX"/display/touchkey_light_duration"
-#endif
-
-#define GET_BRIGHTNESS(val) (((val) >> 24) & 0xFF)
-#define SET_BRIGHTNESS(val) (((val) & 0xFF) << 24)
-
-struct led_device *touchled_dev;
-static guint hardkey_timeout_id;
-static int hardkey_duration;
-
-static int touchled_set_state(bool on)
-{
- struct led_state tmp = {0,};
- int r;
-
- if (!touchled_dev || !touchled_dev->set_state) {
- _E("There is no led device.");
- return -ENOENT;
- }
-
- if (on)
- tmp.color = SET_BRIGHTNESS(255);
- else
- tmp.color = SET_BRIGHTNESS(0);
-
- r = touchled_dev->set_state(&tmp);
- if (r < 0) {
- _E("Failed to set touch led state: %d", r);
- return r;
- }
-
- return 0;
-}
-
-static gboolean key_backlight_expired(void *data)
-{
- hardkey_timeout_id = 0;
-
- touchled_set_state(false);
-
- return G_SOURCE_REMOVE;
-}
-
-static void process_touchkey_press(void)
-{
- /* release existing timer */
- if (hardkey_timeout_id > 0) {
- g_source_remove(hardkey_timeout_id);
- hardkey_timeout_id = 0;
- }
- /* if hardkey option is always off */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_OFF)
- return;
- /* turn on hardkey backlight */
- touchled_set_state(true);
- /* start timer */
- hardkey_timeout_id = g_timeout_add_seconds(
- KEYBACKLIGHT_PRESSED_TIME,
- key_backlight_expired, NULL);
-}
-
-static void process_touchkey_release(void)
-{
- float fduration;
-
- /* release existing timer */
- if (hardkey_timeout_id > 0) {
- g_source_remove(hardkey_timeout_id);
- hardkey_timeout_id = 0;
- }
- /* if hardkey option is always on or off */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_ON ||
- hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_OFF)
- return;
- /* start timer */
- fduration = (float)hardkey_duration / KEYBACKLIGHT_BASE_TIME;
- hardkey_timeout_id = g_timeout_add_seconds(
- fduration,
- key_backlight_expired, NULL);
-}
-
-static void process_touchkey_enable(bool enable)
-{
- /* release existing timer */
- if (hardkey_timeout_id > 0) {
- g_source_remove(hardkey_timeout_id);
- hardkey_timeout_id = 0;
- }
-
- /* start timer in case of backlight enabled */
- if (enable) {
- /* if hardkey option is always off */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_OFF)
- return;
-
- /* turn on hardkey backlight */
- touchled_set_state(true);
-
- /* do not create turnoff timer in case of idle lock state */
- if (disp_plgn.get_lock_screen_state && disp_plgn.get_lock_screen_state() == VCONFKEY_IDLE_LOCK)
- return;
-
- /* start timer */
- hardkey_timeout_id = g_timeout_add_seconds(
- KEYBACKLIGHT_PRESSED_TIME,
- key_backlight_expired, NULL);
- } else {
- /* if hardkey option is always on */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_ON)
- return;
-
- /* turn off hardkey backlight */
- touchled_set_state(false);
- }
-}
-
-static void hardkey_duration_cb(keynode_t *key, void *data)
-{
- float duration;
-
- hardkey_duration = vconf_keynode_get_int(key);
-
- /* release existing timer */
- if (hardkey_timeout_id > 0) {
- g_source_remove(hardkey_timeout_id);
- hardkey_timeout_id = 0;
- }
-
- /* if hardkey option is always off */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_OFF) {
- /* turn off hardkey backlight */
- touchled_set_state(false);
- return;
- }
-
- /* turn on hardkey backlight */
- touchled_set_state(true);
-
- /* if hardkey option is always on */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_ON)
- return;
-
- /* start timer */
- duration = (float)hardkey_duration / KEYBACKLIGHT_BASE_TIME;
- hardkey_timeout_id = g_timeout_add_seconds(
- duration,
- key_backlight_expired, NULL);
-}
-
-static int hardkey_lcd_changed_cb(void *data)
-{
- int lcd_state;
-
- if (!data)
- return 0;
-
- lcd_state = *(int*)data;
- if (lcd_state == S_NORMAL
- && hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_ON) {
- touchled_set_state(true);
- return 0;
- }
-
- return 0;
-}
-
-static int touchled_service_load(void)
-{
- struct hw_info *info;
- int r;
-
- r = hw_get_info(LED_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (r < 0) {
- _E("Failed to load led shared library: %d", r);
- return -ENOENT;
- }
-
- if (!info->open) {
- _E("Failed to open touch led device: open(NULL)");
- return -EPERM;
- }
-
- r = info->open(info, LED_ID_TOUCH_KEY,
- (struct hw_common **)&touchled_dev);
- if (r < 0) {
- _E("Failed to get touch led device: %d", r);
- return -EPERM;
- }
-
- _D("Touch led device structure load success.");
- return 0;
-}
-
-static int touchled_service_free(void)
-{
- struct hw_info *info;
-
- if (!touchled_dev)
- return -ENOENT;
-
- info = touchled_dev->common.info;
- if (!info) {
- free(touchled_dev);
- touchled_dev = NULL;
- return -EPERM;
- }
-
- info->close((struct hw_common *)touchled_dev);
- touchled_dev = NULL;
-
- return 0;
-}
-
-static int touchled_probe(void *data)
-{
- /* load led device */
- return touchled_service_load();
-}
-
-static void touchled_init(void *data)
-{
- int ret;
-
- /* get touchkey light duration setting */
- ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, &hardkey_duration);
- if (ret < 0) {
- _E("Failed to get vconf value for touchkey light duration: %d", ret);
- hardkey_duration = KEYBACKLIGHT_TIME_90;
- }
-
- vconf_notify_key_changed(VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, hardkey_duration_cb, NULL);
-
- /* register notifier */
- register_notifier(DEVICE_NOTIFIER_LCD, hardkey_lcd_changed_cb);
-
- /* update touchkey light duration right now */
- if (hardkey_duration == KEYBACKLIGHT_TIME_ALWAYS_ON)
- touchled_set_state(true);
-}
-
-static void touchled_exit(void *data)
-{
- /* unregister notifier */
- unregister_notifier(DEVICE_NOTIFIER_LCD, hardkey_lcd_changed_cb);
-
- vconf_ignore_key_changed(VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, hardkey_duration_cb);
-
- /* free led device */
- touchled_service_free();
-}
-
-static int touchled_execute(void *data)
-{
- int opt;
-
- if (!data)
- return -EINVAL;
-
- opt = *(int *)data;
- if (opt == TOUCHLED_PRESS)
- process_touchkey_press();
- else if (opt == TOUCHLED_RELEASE)
- process_touchkey_release();
- else if (opt == TOUCHLED_DIRECT_ON)
- process_touchkey_enable(true);
- else if (opt == TOUCHLED_DIRECT_OFF)
- process_touchkey_enable(false);
- else
- return -EINVAL;
-
- return 0;
-}
-
-static const struct device_ops touchled_device_ops = {
- .name = TOUCHLED_NAME,
- .probe = touchled_probe,
- .init = touchled_init,
- .exit = touchled_exit,
- .execute = touchled_execute,
-};
-
-DEVICE_OPS_REGISTER(&touchled_device_ops)