Skip to content

Commit

Permalink
Use sensorfw for detecting orientation changes
Browse files Browse the repository at this point in the history
Use orientation sensor instead of listening to context kit property
change signals.

[mce] Use sensorfw for detecting orientation changes
  • Loading branch information
spiiroin committed Oct 30, 2013
1 parent c155438 commit b4aaf7d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 50 deletions.
3 changes: 3 additions & 0 deletions mce.c
Expand Up @@ -950,6 +950,8 @@ int main(int argc, char **argv)
0, GINT_TO_POINTER(0));
setup_datapipe(&proximity_sensor_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(COVER_OPEN));
setup_datapipe(&orientation_sensor_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
setup_datapipe(&tk_lock_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(LOCK_UNDEF));
setup_datapipe(&charger_state_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -1075,6 +1077,7 @@ int main(int argc, char **argv)
free_datapipe(&charger_state_pipe);
free_datapipe(&tk_lock_pipe);
free_datapipe(&proximity_sensor_pipe);
free_datapipe(&orientation_sensor_pipe);
free_datapipe(&lens_cover_pipe);
free_datapipe(&lid_cover_pipe);
free_datapipe(&keyboard_slide_pipe);
Expand Down
2 changes: 2 additions & 0 deletions mce.h
Expand Up @@ -296,6 +296,8 @@ datapipe_struct lid_cover_pipe;
datapipe_struct lens_cover_pipe;
/** Proximity sensor; read only */
datapipe_struct proximity_sensor_pipe;
/** Orientation sensor; read only */
datapipe_struct orientation_sensor_pipe;
/** The alarm UI state */
datapipe_struct alarm_ui_state_pipe;
/** The device state */
Expand Down
122 changes: 72 additions & 50 deletions modules/display.c
Expand Up @@ -176,13 +176,6 @@ static void stm_target_push_change(display_state_t display_state);
static void stm_rethink_schedule(void);
static void stm_rethink_force(void);

/** Contextkit D-Bus service */
#define ORIENTATION_SIGNAL_IF "org.maemo.contextkit.Property"
/** Contextkit D-Bus orientation path */
#define ORIENTATION_SIGNAL_PATH "/org/maemo/contextkit/Screen/TopEdge"
/** Contextkit D-Bus orientation changed signal */
#define ORIENTATION_VALUE_CHANGE_SIG "ValueChanged"

/** Module name */
#define MODULE_NAME "display"

Expand Down Expand Up @@ -3413,41 +3406,6 @@ static gboolean desktop_startup_dbus_cb(DBusMessage *const msg)
return status;
}

/**
* D-Bus callback for the display orientation change signal
*
* @param msg The D-Bus message
* @return TRUE on success, FALSE on failure
*/
static gboolean display_orientation_change_dbus_cb(DBusMessage *const msg)
{
display_state_t display_state = display_state_get();
gboolean status = FALSE;

(void)msg;

mce_log(LL_DEBUG,
"Received display orientation change notification");

/* Since there are two signals using the same interface,
* the dbus_message_has_path() function is called
* to check if the signal is the required one
*/
if (dbus_message_has_path(msg, ORIENTATION_SIGNAL_PATH) == TRUE) {
/* Generate activity if the display is on/dim */
if ((display_state == MCE_DISPLAY_ON) ||
(display_state == MCE_DISPLAY_DIM)) {
(void)execute_datapipe(&device_inactive_pipe,
GINT_TO_POINTER(FALSE),
USE_INDATA, CACHE_INDATA);
}
}

status = TRUE;

return status;
}

/** Have we seen shutdown_ind signal from dsme */
static gboolean shutdown_started = FALSE;

Expand Down Expand Up @@ -4251,6 +4209,57 @@ static void cancel_display_timers(void)
//cancel_adaptive_dimming_timeout();
}

/** Cached Orientation Sensor value */
static orientation_state_t orientation_state = MCE_ORIENTATION_UNDEFINED;

/** Callback for handling orientation change notifications
*
* @param state orientation sensor state
*/
static void orientation_changed_cb(int state)
{
execute_datapipe(&orientation_sensor_pipe,
GINT_TO_POINTER(state),
USE_INDATA, CACHE_INDATA);
}

/** Generate user activity from orientation sensor input
*/
static void orientation_generate_activity(void)
{
static orientation_state_t prev_orientation_state = MCE_ORIENTATION_UNDEFINED;
display_state_t display_state = datapipe_get_gint(display_state_pipe);


/* Generate activity if the display is on/dim */
if( prev_orientation_state != orientation_state ) {
prev_orientation_state = orientation_state;

switch( display_state ) {
case MCE_DISPLAY_ON:
case MCE_DISPLAY_DIM:
mce_log(LL_DEBUG, "generate activity"
"; orientation change");
execute_datapipe(&device_inactive_pipe,
GINT_TO_POINTER(FALSE),
USE_INDATA, CACHE_INDATA);
break;
default:
break;
}
}
}

/** Handle orientation sensor state change
*
* @param data The orientation state stored in a pointer
*/
static void orientation_state_trigger(gconstpointer data)
{
orientation_state = GPOINTER_TO_INT(data);
orientation_generate_activity();
}

/**
* Handle display state change
*
Expand All @@ -4266,6 +4275,20 @@ static void display_state_trigger(gconstpointer data)

cancel_lpm_proximity_blank_timeout();

/* Enable orientation sensor in ON|DIM */
switch( display_state ) {
case MCE_DISPLAY_DIM:
case MCE_DISPLAY_ON:
mce_sensorfw_orient_set_notify(orientation_changed_cb);
mce_sensorfw_orient_enable();
break;

default:
mce_sensorfw_orient_set_notify(0);
mce_sensorfw_orient_disable();
break;
}

switch (display_state) {
case MCE_DISPLAY_OFF:
case MCE_DISPLAY_LPM_OFF:
Expand Down Expand Up @@ -5487,6 +5510,8 @@ const gchar *g_module_check_init(GModule *module)
display_brightness_trigger);
append_output_trigger_to_datapipe(&display_state_pipe,
display_state_trigger);
append_output_trigger_to_datapipe(&orientation_sensor_pipe,
orientation_state_trigger);
append_output_trigger_to_datapipe(&display_state_req_pipe,
display_state_req_trigger);
append_output_trigger_to_datapipe(&submode_pipe,
Expand Down Expand Up @@ -5608,14 +5633,6 @@ const gchar *g_module_check_init(GModule *module)
shutdown_dbus_cb) == NULL)
goto EXIT;

/* Display orientation change signal */
if (mce_dbus_handler_add(ORIENTATION_SIGNAL_IF,
ORIENTATION_VALUE_CHANGE_SIG,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
display_orientation_change_dbus_cb) == NULL)
goto EXIT;

/* Turning demo mode on/off */
if (mce_dbus_handler_add(MCE_REQUEST_IF,
MCE_DBUS_DEMO_MODE_REQ,
Expand Down Expand Up @@ -5892,6 +5909,8 @@ void g_module_unload(GModule *module)
display_state_req_trigger);
remove_output_trigger_from_datapipe(&display_state_pipe,
display_state_trigger);
remove_output_trigger_from_datapipe(&orientation_sensor_pipe,
orientation_state_trigger);
remove_output_trigger_from_datapipe(&display_brightness_pipe,
display_brightness_trigger);
remove_output_trigger_from_datapipe(&charger_state_pipe,
Expand Down Expand Up @@ -5938,5 +5957,8 @@ void g_module_unload(GModule *module)
}
poweron_led_rethink_cancel();

/* Remove callbacks on module unload */
mce_sensorfw_orient_set_notify(0);

return;
}

0 comments on commit b4aaf7d

Please sign in to comment.