Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 164fcfb8 authored by Jonas Larsson's avatar Jonas Larsson Committed by Madison Koenig
Browse files

Pimp automatic backlight.

Moving average filter for light sensor, support for custom levels, battery stats fix and dim fix.

Optimization: Don't compute the sum of all samples in filter window every run. Instead, keep track of the sum, subtract phased out sample, add new sample and divide new sum by number of valid samples. Massive CPU cycle savings.
Thanks to Jonathan (zenpoy on gmail dot com) for pointing me in the right direction!

Fix: The code for stopping the filter if the sensor has been stable the entire filter window time was only enabled if debug logging was enabled. Oops. CPU cycle savings in steady ambient light.

Tweak light sensor filter

1. Only allow decrease if user permitted it
2. Only perform filter reset on sensor increase and current average is below 1500 ("indoors")
3. Filter reset in 2. means pushing the filter half way towards new sample
4. Filter reset is disabled by default

This change requires commits from CMParts:

5f4026702b67b5d23c9a992f408e3861c90566db
f9238a01e4a4a64cb414dbdada36c97ae2a37db9
0a4b490035c333b3d77e6e59fcc0f7d16d78ebda
5036cc8217daf59aa9f2800bc3fa40e4dd4b3117
b43caaab217848668241681613ce8d54ceda69e9
cc0682a4cc43d0058db8b5195d4d329336f2d3fd

Change-Id: I9c88704484f4a23b3d643597f35b55d74cf36b56
parent 6abe6e0a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -45,4 +45,11 @@ interface IPowerManager
    // sets the brightness of the backlights (screen, keyboard, button) 0-255
    void setBacklightBrightness(int brightness);
    void setAttentionLight(boolean on, int color);

    // custom backlight things
    int getLightSensorValue();
    int getRawLightSensorValue();
    int getLightSensorScreenBrightness();
    int getLightSensorButtonBrightness();
    int getLightSensorKeyboardBrightness();
}
+130 −0
Original line number Diff line number Diff line
@@ -1390,6 +1390,136 @@ public final class Settings {
         */
        public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1;

        /**
         * Indicates that custom light sensor settings has changed.
         * The value is random and changes reloads light settings.
         *
         * @hide
         */
        public static final String LIGHTS_CHANGED = "lights_changed";

        /**
         * Whether custom light sensor levels & values are enabled. The value is
         * boolean (1 or 0).
         *
         * @hide
         */
        public static final String LIGHT_SENSOR_CUSTOM = "light_sensor_custom";

        /**
         * Screen dim value to use if LIGHT_SENSOR_CUSTOM is set. The value is int.
         * Default is android.os.BRIGHTNESS_DIM.
         *
         * @hide
         */
        public static final String LIGHT_SCREEN_DIM = "light_screen_dim";

        /**
         * Custom light sensor levels. The value is a comma separated int array
         * with length N.
         * Example: "100,300,3000".
         *
         * @hide
         */
        public static final String LIGHT_SENSOR_LEVELS = "light_sensor_levels";

        /**
         * Custom light sensor lcd values. The value is a comma separated int array
         * with length N+1.
         * Example: "10,50,100,255".
         *
         * @hide
         */
        public static final String LIGHT_SENSOR_LCD_VALUES = "light_sensor_lcd_values";

        /**
         * Custom light sensor lcd values. The value is a comma separated int array
         * with length N+1.
         * Example: "10,50,100,255".
         *
         * @hide
         */
        public static final String LIGHT_SENSOR_BUTTON_VALUES = "light_sensor_button_values";

        /**
         * Custom light sensor lcd values. The value is a comma separated int array
         * with length N+1.
         * Example: "10,50,100,255".
         *
         * @hide
         */
        public static final String LIGHT_SENSOR_KEYBOARD_VALUES = "light_sensor_keyboard_values";

        /**
         * Whether light sensor is allowed to decrease when calculating automatic
         * backlight. The value is boolean (1 or 0).
         *
         * @hide
         */
        public static final String LIGHT_DECREASE = "light_decrease";

        /**
         * Light sensor hysteresis for decreasing backlight. The value is
         * int (0-99) representing % (0-0.99 as float). Example:
         *
         * Levels     Output
         * 0 - 100    50
         * 100 - 200  100
         * 200 - Inf  255
         *
         * Current sensor value is 150 which gives light value 100. Hysteresis is 50.
         * Current level lower bound is 100 and previous lower bound is 0.
         * Sensor value must drop below 100-(100-0)*(50/100)=50 for output to become 50
         * (corresponding to the 0 - 100 level).
         * @hide
         */
        public static final String LIGHT_HYSTERESIS = "light_hysteresis";

        /**
         * Whether light sensor used when calculating automatic backlight should
         * be filtered through an moving average filter.
         * The value is boolean (1 or 0).
         *
         * @hide
         */
        public static final String LIGHT_FILTER = "light_filter";

        /**
         * Window length of filter used when calculating automatic backlight.
         * One minute means that the average sensor value last minute is used.
         * The value is integer (milliseconds)
         *
         * @hide
         */
        public static final String LIGHT_FILTER_WINDOW = "light_filter_window";

        /**
         * Reset threshold of filter used when calculating automatic backlight.
         * Sudden large jumps in sensor value resets the filter. This is used
         * to make the filter respond quickly to large enough changes in input
         * while still filtering small changes. Example:
         *
         * Current filter value (average) is 100 and sensor value is changing to
         * 10, 150, 100, 30, 50. The filter is continously taking the average of
         * the samples. Now the user goes outside and the value jumps over 1000.
         * The difference between current average and new sample is larger than
         * the reset threshold and filter is reset. It begins calculating a new
         * average on samples around 1000 (say, 800, 1200, 1000, 1100 etc.)
         *
         * The value is integer (lux)
         *
         * @hide
         */
        public static final String LIGHT_FILTER_RESET = "light_filter_reset";

        /**
         * Sample interval of filter used when calculating automatic backlight.
         * The value is integer (milliseconds)
         *
         * @hide
         */
        public static final String LIGHT_FILTER_INTERVAL = "light_filter_interval";

        /**
         * Control whether the process CPU usage meter should be shown.
         */
+393 −32

File changed.

Preview size limit exceeded, changes collapsed.