Skip to content

Commit

Permalink
[tklock] Add setting for lid is closed als limit. Fixes JB#33468
Browse files Browse the repository at this point in the history
The light level limit used for filtering lid opened/closed events is hard
coded - which makes it impossible to specify platform specific values.

Add setting for the light level limit. By default it is assumed that
ALS will report zero lux in complete darkness.

Configuration files can be used to provide platform specific default.

Users can - if necessary - users tweak the limit mcetool option:
  --set-filter-lid-als-limit=<lux>

The value of the setting persists over mce / device restarts.
  • Loading branch information
spiiroin committed Nov 11, 2015
1 parent 54bb08b commit 7cd2519
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1281,6 +1281,11 @@ static const setting_t gconf_defaults[] =
.type = "b",
.def = G_STRINGIFY(DEFAULT_FILTER_LID_WITH_ALS),
},
{
.key = MCE_GCONF_FILTER_LID_ALS_LIMIT,
.type = "i",
.def = G_STRINGIFY(DEFAULT_FILTER_LID_ALS_LIMIT),
},
{
.key = MCE_GCONF_TK_LID_OPEN_ACTIONS,
.type = "i",
Expand Down
23 changes: 19 additions & 4 deletions tklock.c
Expand Up @@ -89,9 +89,6 @@ typedef enum
/** Signal to send when lpm ui state changes */
#define MCE_LPM_UI_MODE_SIG "lpm_ui_mode_ind"

/** Minimum light level for TKLOCK_LIDLIGHT_HI state [lux] */
#define TKLOCK_LIDLIGHT_HI_LIMIT 2

/** How long to wait for lid close after low lux [ms] */
#define TKLOCK_LIDFILTER_SET_WAIT_FOR_CLOSE_DELAY 1500

Expand Down Expand Up @@ -526,6 +523,11 @@ static gboolean filter_lid_with_als = DEFAULT_FILTER_LID_WITH_ALS;
/** Config notification for filter_lid_with_als */
static guint filter_lid_with_als_gconf_id = 0;

/** Maximum amount of light ALS should report when LID is closed */
static gint filter_lid_als_limit = DEFAULT_FILTER_LID_ALS_LIMIT;
/** Config notification for filter_lid_als_limit */
static guint filter_lid_als_limit_gconf_id = 0;

/** How long to keep display on after incoming call ends [ms] */
static gint exception_length_call_in = DEFAULT_EXCEPTION_LENGTH_CALL_IN;
/** GConf callback ID for exception_length_call_in */
Expand Down Expand Up @@ -2424,7 +2426,7 @@ static tklock_lidlight_t tklock_lidlight_from_lux(int lux)
return TKLOCK_LIDLIGHT_NA;

/* Sensor does not see light? */
if( lux < TKLOCK_LIDLIGHT_HI_LIMIT )
if( lux <= filter_lid_als_limit )
return TKLOCK_LIDLIGHT_LO;

/* It is not completely dark */
Expand Down Expand Up @@ -4758,6 +4760,10 @@ static void tklock_gconf_cb(GConfClient *const gcc, const guint id,
filter_lid_with_als = gconf_value_get_bool(gcv);
tklock_lidfilter_rethink_lid_state();
}
else if( id == filter_lid_als_limit_gconf_id ) {
filter_lid_als_limit = gconf_value_get_int(gcv);
tklock_lidfilter_rethink_lid_state();
}
else if( id == lockscreen_anim_enabled_cb_id ) {
lockscreen_anim_enabled= gconf_value_get_bool(gcv);
}
Expand Down Expand Up @@ -5074,6 +5080,12 @@ static void tklock_gconf_init(void)
tklock_gconf_cb,
&filter_lid_with_als_gconf_id);

mce_gconf_track_int(MCE_GCONF_FILTER_LID_ALS_LIMIT,
&filter_lid_als_limit,
DEFAULT_FILTER_LID_ALS_LIMIT,
tklock_gconf_cb,
&filter_lid_als_limit_gconf_id);

/* Display on exception lengths */
mce_gconf_track_int(MCE_GCONF_EXCEPTION_LENGTH_CALL_IN,
&exception_length_call_in,
Expand Down Expand Up @@ -5215,6 +5227,9 @@ static void tklock_gconf_quit(void)
mce_gconf_notifier_remove(filter_lid_with_als_gconf_id),
filter_lid_with_als_gconf_id = 0;

mce_gconf_notifier_remove(filter_lid_als_limit_gconf_id),
filter_lid_als_limit_gconf_id = 0;

mce_gconf_notifier_remove(exception_length_call_in_cb_id),
exception_length_call_in_cb_id = 0;

Expand Down
4 changes: 4 additions & 0 deletions tklock.h
Expand Up @@ -126,6 +126,10 @@ typedef enum
#define MCE_GCONF_FILTER_LID_WITH_ALS MCE_GCONF_LOCK_PATH"/filter_lid_with_als"
#define DEFAULT_FILTER_LID_WITH_ALS true

/** Maximum amount of light ALS should report when LID is closed */
#define MCE_GCONF_FILTER_LID_ALS_LIMIT MCE_GCONF_LOCK_PATH"/filter_lid_als_limit"
#define DEFAULT_FILTER_LID_ALS_LIMIT 0

/** Lid sensor open actions */
typedef enum
{
Expand Down
41 changes: 41 additions & 0 deletions tools/mcetool.c
Expand Up @@ -3036,6 +3036,34 @@ static void xmce_get_filter_lid_with_als(void)
printf("%-"PAD1"s %s\n", "Filter lid with als:", txt);
}

/* Set limit for light als should report when lid is closed
*
* @param args string suitable for interpreting as lux value
*/
static bool xmce_set_filter_lid_als_limit(const char *args)
{
int val = xmce_parse_integer(args);
if( val < 0 ) {
errorf("%d: invalid lux value\n", val);
return false;
}
mcetool_gconf_set_int(MCE_GCONF_FILTER_LID_ALS_LIMIT, val);
return true;
}

/* Get current filter lid als limit from mce and print it out
*/
static void xmce_get_filter_lid_als_limit(void)
{
gint val = 0;
char txt[32];

strcpy(txt, "unknown");
if( mcetool_gconf_get_int(MCE_GCONF_FILTER_LID_ALS_LIMIT, &val) )
snprintf(txt, sizeof txt, "%d", (int)val);
printf("%-"PAD1"s %s (lux)\n", "Lid closed als limit:", txt);
}

/* Set lid_sensor use mode
*
* @param args string suitable for interpreting as enabled/disabled
Expand Down Expand Up @@ -5410,6 +5438,7 @@ static bool xmce_get_status(const char *args)
xmce_get_ps_acts_as_lid();
xmce_get_lid_sensor_mode();
xmce_get_filter_lid_with_als();
xmce_get_filter_lid_als_limit();
xmce_get_lid_open_actions();
xmce_get_lid_close_actions();
xmce_get_kbd_slide_open_trigger();
Expand Down Expand Up @@ -6293,6 +6322,18 @@ static const mce_opt_t options[] =
"When enabled, lid closed events are acted on only if they\n"
"happen in close proximity to light level drop.\n"
},
{
.name = "set-filter-lid-als-limit",
.with_arg = xmce_set_filter_lid_als_limit,
.values = "lux",
"set limit for how much light als can report when lid is closed\n"
"\n"
"Lid closed event is ignored unless it is associated with als\n"
"reporting lux>limit -> lux<=limit drop.\n"
"\n"
"Lid opened event is ignored unless it is associated with als\n"
"reporting lux<=limit -> lux>limit raise.\n"
},
{
.name = "set-orientation-sensor-mode",
.with_arg = xmce_set_orientation_sensor_mode,
Expand Down

0 comments on commit 7cd2519

Please sign in to comment.