Skip to content

Commit

Permalink
Add setting for ignoring lid/cover sensor
Browse files Browse the repository at this point in the history
If mce find that a device has lid/cover sensor, it is used as a very
high priority input for display blanking policy. It might be desirable
to stop this from happening if for example:
- user does not like the feature
- mce input device probing produces a false match
- the sensor is unreliable and makes using the device difficult
- we want to keep the display on during sensor testing activities

Add disable/enable setting for using lid/cover sensor.

By default the setting is enabled, but can be changed for example by
installing hw specific mce configuration files or from command line

  mcetool --set-lid-sensor-mode=<enabled|disabled>

The setting persists over mce/device restarts.

[mce] Add setting for ignoring lid/cover sensor. Fixes JB#28108
  • Loading branch information
spiiroin committed Apr 24, 2015
1 parent 0a5497d commit 1909bba
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 52 deletions.
5 changes: 5 additions & 0 deletions builtin-gconf.c
Expand Up @@ -1214,6 +1214,11 @@ static const setting_t gconf_defaults[] =
.type = "b",
.def = G_STRINGIFY(DEFAULT_DEVICELOCK_IN_LOCKSCREEN),
},
{
.key = MCE_GCONF_LID_SENSOR_ENABLED,
.type = "b",
.def = G_STRINGIFY(DEFAULT_LID_SENSOR_ENABLED),
},
{
.key = MCE_GCONF_AUTOLOCK_DELAY,
.type = "i",
Expand Down
14 changes: 10 additions & 4 deletions datapipe.c
Expand Up @@ -88,8 +88,11 @@ datapipe_struct keyboard_slide_pipe;
/** Keyboard available; read only */
datapipe_struct keyboard_available_pipe;

/** Lid cover open/closed; read only */
datapipe_struct lid_cover_pipe;
/** Lid cover sensor open/closed; read only */
datapipe_struct lid_cover_sensor_pipe;

/** Lid cover policy state; read only */
datapipe_struct lid_cover_policy_pipe;

/** Lens cover open/closed; read only */
datapipe_struct lens_cover_pipe;
Expand Down Expand Up @@ -837,7 +840,9 @@ void mce_datapipe_init(void)
0, GINT_TO_POINTER(COVER_CLOSED));
setup_datapipe(&keyboard_available_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(COVER_CLOSED));
setup_datapipe(&lid_cover_pipe, READ_ONLY, DONT_FREE_CACHE,
setup_datapipe(&lid_cover_sensor_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(COVER_OPEN));
setup_datapipe(&lid_cover_policy_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(COVER_OPEN));
setup_datapipe(&lens_cover_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
Expand Down Expand Up @@ -921,7 +926,8 @@ void mce_datapipe_quit(void)
free_datapipe(&ambient_light_sensor_pipe);
free_datapipe(&orientation_sensor_pipe);
free_datapipe(&lens_cover_pipe);
free_datapipe(&lid_cover_pipe);
free_datapipe(&lid_cover_sensor_pipe);
free_datapipe(&lid_cover_policy_pipe);
free_datapipe(&keyboard_slide_pipe);
free_datapipe(&keyboard_available_pipe);
free_datapipe(&lockkey_pipe);
Expand Down
3 changes: 2 additions & 1 deletion datapipe.h
Expand Up @@ -108,7 +108,8 @@ extern datapipe_struct touchscreen_pipe;
extern datapipe_struct lockkey_pipe;
extern datapipe_struct keyboard_slide_pipe;
extern datapipe_struct keyboard_available_pipe;
extern datapipe_struct lid_cover_pipe;
extern datapipe_struct lid_cover_sensor_pipe;
extern datapipe_struct lid_cover_policy_pipe;
extern datapipe_struct lens_cover_pipe;
extern datapipe_struct proximity_sensor_pipe;
extern datapipe_struct ambient_light_sensor_pipe;
Expand Down
4 changes: 2 additions & 2 deletions event-input.c
Expand Up @@ -2077,12 +2077,12 @@ evin_iomon_keypress_cb(gpointer data, gsize bytes_read)
/* hammerhead magnetic lid sensor; Feed in to the
* same datapipe as N770 sliding cover uses */
if( ev->value ) {
execute_datapipe(&lid_cover_pipe,
execute_datapipe(&lid_cover_sensor_pipe,
GINT_TO_POINTER(COVER_CLOSED),
USE_INDATA, CACHE_INDATA);
}
else {
execute_datapipe(&lid_cover_pipe,
execute_datapipe(&lid_cover_sensor_pipe,
GINT_TO_POINTER(COVER_OPEN),
USE_INDATA, CACHE_INDATA);
}
Expand Down
4 changes: 2 additions & 2 deletions event-switches.c
Expand Up @@ -211,7 +211,7 @@ static gboolean lid_cover_iomon_cb(gpointer data, gsize bytes_read)
lid_cover_state = COVER_CLOSED;
}

(void)execute_datapipe(&lid_cover_pipe,
(void)execute_datapipe(&lid_cover_sensor_pipe,
GINT_TO_POINTER(lid_cover_state),
USE_INDATA, CACHE_INDATA);

Expand Down Expand Up @@ -475,7 +475,7 @@ gboolean mce_switches_init(void)
submode_trigger);

/* Set default values, in case these are not available */
(void)execute_datapipe(&lid_cover_pipe,
(void)execute_datapipe(&lid_cover_sensor_pipe,
GINT_TO_POINTER(COVER_OPEN),
USE_INDATA, CACHE_INDATA);

Expand Down
33 changes: 30 additions & 3 deletions modules/display.c
Expand Up @@ -1112,6 +1112,30 @@ static void mdy_datapipe_submode_cb(gconstpointer data)
return;
}

/** Cache Lid cover policy state; assume open
*/
static cover_state_t lid_cover_policy_state = COVER_OPEN;

/** Change notifications from lid_cover_policy_pipe
*/
static void tklock_datapipe_mdy_datapipe_lid_cover_policy_cb(gconstpointer data)
{
cover_state_t prev = lid_cover_policy_state;
lid_cover_policy_state = GPOINTER_TO_INT(data);

if( lid_cover_policy_state == COVER_UNDEF )
lid_cover_policy_state = COVER_OPEN;

if( lid_cover_policy_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "lid_cover_policy_state = %s -> %s",
cover_state_repr(prev),
cover_state_repr(lid_cover_policy_state));
EXIT:
return;
}

/* Cached current display state */
static display_state_t display_state = MCE_DISPLAY_UNDEF;

Expand All @@ -1129,16 +1153,14 @@ static gpointer mdy_datapipe_display_state_filter_cb(gpointer data)
display_state_t want_state = GPOINTER_TO_INT(data);
display_state_t next_state = want_state;

cover_state_t lid_cover_state = datapipe_get_gint(lid_cover_pipe);

/* Handle never-blank override */
if( mdy_disp_never_blank ) {
next_state = MCE_DISPLAY_ON;
goto UPDATE;
}

/* Display stays off while lid_cover is on */
if( lid_cover_state == COVER_CLOSED ) {
if( lid_cover_policy_state == COVER_CLOSED ) {
next_state = MCE_DISPLAY_OFF;
goto UPDATE;
}
Expand Down Expand Up @@ -1637,6 +1659,7 @@ static void mdy_datapipe_orientation_state_cb(gconstpointer data)
EXIT:
return;
}

/** Array of datapipe handlers */
static datapipe_handler_t mdy_datapipe_handlers[] =
{
Expand Down Expand Up @@ -1718,6 +1741,10 @@ static datapipe_handler_t mdy_datapipe_handlers[] =
.datapipe = &lipstick_available_pipe,
.output_cb = mdy_datapipe_lipstick_available_cb,
},
{
.datapipe = &lid_cover_policy_pipe,
.output_cb = tklock_datapipe_mdy_datapipe_lid_cover_policy_cb,
},

// sentinel
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ut/ut_display.c
Expand Up @@ -1301,7 +1301,7 @@ static void stub_setup_checked(void)
0, GINT_TO_POINTER(0));
setup_datapipe(&keyboard_slide_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
setup_datapipe(&lid_cover_pipe, READ_ONLY, DONT_FREE_CACHE,
setup_datapipe(&lid_cover_input_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
setup_datapipe(&lens_cover_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
Expand Down Expand Up @@ -1364,7 +1364,7 @@ static void stub_teardown_checked(void)
free_datapipe(&tk_lock_pipe);
free_datapipe(&proximity_sensor_pipe);
free_datapipe(&lens_cover_pipe);
free_datapipe(&lid_cover_pipe);
free_datapipe(&lid_cover_input_pipe);
free_datapipe(&keyboard_slide_pipe);
free_datapipe(&lockkey_pipe);
free_datapipe(&device_inactive_pipe);
Expand Down

0 comments on commit 1909bba

Please sign in to comment.