Esempio n. 1
0
/** Check if ALS sensor should be enabled or disabled
 */
static void rethink_als_status(void)
{
	static gboolean enable_old = FALSE;

	gboolean enable_new = FALSE;
	gboolean want_data  = FALSE;

	if( !have_als )
		goto EXIT;

	if( use_als_flag ) {
		switch( display_state_next ) {
		case MCE_DISPLAY_ON:
		case MCE_DISPLAY_DIM:
		case MCE_DISPLAY_POWER_UP:
		case MCE_DISPLAY_LPM_OFF:
		case MCE_DISPLAY_LPM_ON:
			want_data = TRUE;
			break;

		default:
		case MCE_DISPLAY_POWER_DOWN:
		case MCE_DISPLAY_OFF:
		case MCE_DISPLAY_UNDEF:
			want_data = FALSE;
			break;
		}
	}

	if( want_data )
		enable_new = TRUE;

	mce_log(LL_DEBUG, "use=%d, want=%d -> enable=%d",
		use_als_flag, want_data, enable_new);

	if( want_data ) {
		/* The sensor has been off for some time, so the
		 * history needs to be forgotten when we get fresh
		 * data */
		inputflt_flush_on_change();

		/* Enable change notifications */
		mce_sensorfw_als_set_notify(als_lux_changed);
	}
	else {
		/* Disable change notifications */
		mce_sensorfw_als_set_notify(0);

		/* Force cached value re-evaluation */
		als_lux_changed(-1);

		/* Stop sampling timer */
		inputflt_sampling_stop();
	}

	if( enable_old == enable_new )
		goto EXIT;

	enable_old = enable_new;

	if( enable_new ) {
		mce_sensorfw_als_enable();
	}
	else {
		mce_sensorfw_als_disable();

		/* Clear thresholds so that the next reading from
		 * als will not be affected by previous state */
		als_filter_clear_threshold(&lut_display);
		als_filter_clear_threshold(&lut_led);
		als_filter_clear_threshold(&lut_key);
		als_filter_clear_threshold(&lut_lpm);
	}

	run_datapipes();
EXIT:
	return;
}
Esempio n. 2
0
/** Check if ALS sensor should be enabled or disabled
 */
static void rethink_als_status(void)
{
	static gboolean enable_old = FALSE;

	gboolean enable_new = FALSE;
	gboolean want_data  = FALSE;

	if( !have_als )
		goto EXIT;

	if( use_als_flag ) {
		switch( display_state ) {
		case MCE_DISPLAY_ON:
		case MCE_DISPLAY_DIM:
			want_data = TRUE;
			break;

		default:
		case MCE_DISPLAY_OFF:
		case MCE_DISPLAY_LPM_OFF:
		case MCE_DISPLAY_LPM_ON:
		case MCE_DISPLAY_UNDEF:
			want_data = FALSE;
			break;
		}
	}

	if( want_data || ext_als_enablers  )
		enable_new = TRUE;

	mce_log(LL_DEBUG, "use=%d, want=%d ext=%d -> enable=%d",
		use_als_flag, want_data, ext_als_enablers ? 1 : 0,
		enable_new);

	if( want_data )
		mce_sensorfw_als_set_notify(als_lux_changed);
	else
		mce_sensorfw_als_set_notify(0);

	if( enable_old == enable_new )
		goto EXIT;

	enable_old = enable_new;

	if( enable_new ) {
		mce_sensorfw_als_enable();
	}
	else {
		mce_sensorfw_als_disable();

		/* Clear thresholds so that the next reading from
		 * als will not be affected by previous state */
		als_filter_clear_threshold(&lut_display);
		als_filter_clear_threshold(&lut_led);
		als_filter_clear_threshold(&lut_key);
	}

	run_datapipes();
EXIT:
	return;
}