FORUMS

Numerical explanation of the CM7 automatic backlight settings

695 posts
Thanks Meter: 729
 
By byrong, Senior Member on 22nd March 2011, 03:39 PM
Post Reply Email Thread
While the CM7 auto-backlight settings should function the same across supported devices, I do not know how the light sensor itself may differ. As such, some of what I write below may be specific to the Inc while the general concepts should be applicable to other devices.

Thanks to userjf for helping me better understand the effect of kernel choice on light sensor readings.


The CM7 automatic backlight settings can seem a bit intimidating at first: there are a lot of options for the user to tweak. Don't worry though: there is some very basic math being used and once you understand it, optimizing your settings becomes much easier.

The most important thing to realize right away is that the light sensor can only detect a fixed number of raw values. If you are using the stock kernel in nightly #26 (or later), then you should be able to read 10 values:
Code:
10, 160, 225, 320, 640, 1280, 2600, 5800, 8000, 10240
If you are using an older nightly, or a custom kernel that does not yet incorporate these extra levels, you will only be able to read 7 values:
Code:
160, 225, 320, 640, 1280, 2600, 10240
If you aren't sure what you have, go to the "edit other levels" portion of the CM7 backlight settings and then cover your light sensor. When the raw reading updates, you should see either 10 or 160, telling you which of the above two lists applies to you.

Since there are only 10 possible raw readings, setting up more than 10 custom levels is pointless, unless you also enable filtering. Filtering uses an average of raw readings to create new filtered readings, increasing the number of possible values.

The number of new values will be dependent on your window length and sample interval. If you select a window length of 30 seconds with a sample interval of 5 seconds, each filtered reading will now be based on the average of 6 raw readings (30/5). A quick example of this 30/5 filter involves walking from a room that has a raw reading of 640 to one that has a raw reading of 320:



Notice that the shift in filtered values is much more gradual than the shift in raw values. Given enough time, however, the filtered value will always return to a raw value.

If the filtered value always anchors back to a raw value, why enable filtering?

There are two primary benefits offered by filtering:
1. It can allow you to set up smoother brightness transitions (assuming you also increase the number of custom levels)
2. It can decrease the likelihood of screen flicker in mixed lighting

Point #1 should be relatively self-explanatory: since we now have interpolated light values, we can create intermediate screen brightness levels. Each of those values between 640 and 320 can trigger subtle changes in screen brightness, allowing for a smoother transition between them.

As for #2, you may find yourself in mixed lighting conditions that straddle two raw brightness levels. Without filtering, these raw levels may cause your screen to repeatedly shift back and forth between two brightness settings. I've found this can easily happen with artificial lighting as it is more directional than natural lighting. Sitting in your office, for example, you may find that simply shifting the angle at which you hold the phone changes the brightness reading.

With a filter in place, however, the effects of fluctuating raw values can be mitigated. This is true even if you don't create additional brightness levels. For example, using the stock values, let's look at what would happen if your sensor was getting raw readings back and forth between 640 and 320:



Notice that without filtering, the screen brightness jumps back and forth between 70 and 55, which can be very distracting. The filter, on the other hand, maintains a single value for the screen brightness, even under these fluctuating lighting conditions.

Of course, there may be times in which you want the screen to respond quickly to changes rather than slowly ramping. Moving from a dark building out in to broad daylight, for example, you don't want to watch your screen slowly brighten over the course of 30 seconds: those are 30 seconds in which your phone may be unreadable. This is where the reset threshold comes in handy. If a raw reading differs from your current average by this amount, the filtered value is immediately reset to the raw value. Finding the right value for your reset threshold allows you the best of both worlds: a screen that gradually changes based on subtle light changes, but responds rapidly to extreme changes.

"Allow light decrease" is a very simple option. If this is checked, your screen brightness will increase and decrease according to your custom levels. If it is unchecked, your screen will brighten as the light sensor reads higher values, but will never darken, even if the sensor detects that you have moved to a very dark area. I'm not quire sure why anyone would want to uncheck this, but maybe I'm missing something.

Finally, the hysteresis option is a bit of a mystery to me. That is, I understand the concept of hysteresis ("a retardation of the effect when the forces acting upon a body are changed"), but I don't see any difference in practice. In my testing, it doesn't matter whether I set hysteresis to 0% or 90% - my brightness values and resulting screen values behave exactly the same. If you are able to observe a quantifiable difference, please let me know your findings.

Putting this all together should hopefully give you a better idea of how to tweak your settings. If you want a screen that responds very rapidly to changes in ambient lighting, possibly at the risk of flickering, decrease your filter window (or disable the filter completely) and increase your sample interval. If you want a screen that never flickers, possibly at the risk of slow responsiveness, increase your window.

Note that any settings you choose can easily be modeled with some very basic math. Here are some example configurations and how they would play out:

Filter A: 10 second window, 2 second interval
Filter B: 20 second window, 2 second interval
Filter C: 30 second window, 2 second interval
Filter D: Same as Filter C, but includes a reset threshold of 2000

This is a pretty ugly graph, but hopefully it conveys the concept. Filter D is represented as a dotted line because it overlaps Filter C so much.



Note how the inclusion of a reset threshold on Filter D allows for immediate responsiveness under extreme light changes while still preserving the gradual shifts at smaller changes.

It's also worth noting a known issue at the time of this writing. That is, if you are using the screen on/off animations in CM7, any screen brightness changes will look more "jumpy." That is, if you change your screen from 100 to 150, either manually or automatically, the change will look like a switch was flipped. If you disable the animations, however, that same change from 100 to 150 will be smoother, with the system automatically scaling through the intermediate brightness levels. Even so, the change will be fairly quick, so it does not replace filtering: it's just a nice extra if you really prefer smooth brightness changes.
The Following 14 Users Say Thank You to byrong For This Useful Post: [ View ] Gift byrong Ad-Free
25th March 2011, 07:58 AM |#2  
jimmiet's Avatar
Senior Member
Flag Trevor
Thanks Meter: 49
 
Donate to Me
More
Once again a very informative write up. Thanks.
25th March 2011, 12:34 PM |#3  
Fergusonfox7's Avatar
Senior Member
Flag Champlin
Thanks Meter: 32
 
More
Thanks man. Very informative!

Sent from my ADR6300 using XDA Premium App
31st March 2011, 04:14 AM |#4  
Senior Member
Thanks Meter: 160
 
Donate to Me
More
Here is some more information I have found out about the light sensor, and I really hope that some of you will find it interesting:


#1

If the filter is enabled, the raw value is polled about every 0.5 seconds.

If the filter is disabled, the raw value is only polled about every 2.0 seconds.

This is by-design within CM7, for whatever reason.

#2

The values are in "Lux", but they are multiplied by 10. So, 1000 is really 100.0

The sensor itself detects 0 - 1024, but CM7 shows them as 0 - 10240. (Multiplied by 10).

So, the sensor will max out in a bright room, and therefore can't detect any more brightness outside in a much brighter sunshine than it can in a bright room.

#3

The lux values in CM7, even when you divide them by 10, don't actually match the value reported by the light sensor. The light sensor driver has its own "10 values" that it pairs up with the CM7 "10 values".

The 10 values in the driver are not equal to the 10 values in CM7... but this only really affects you if you are trying to get an accurate measurement of light.

For example, the sensor may detect 50 lux, the driver rounds it up to the closest of the 10 driver values, for example "150", which might be the third number in the driver's 10 values. Therefore, CM7 would report it as 225, as 225 is the third number in the CM7 "10 values".


I'm not calling any of this information bugs or flaws... just interesting infomation for people that enjoy the technical part of things.
The Following 2 Users Say Thank You to userjf For This Useful Post: [ View ] Gift userjf Ad-Free
31st March 2011, 12:51 PM |#5  
byrong's Avatar
OP Senior Member
Flag East Coast
Thanks Meter: 729
 
More
Very interesting info. Thank you, userjf!

One question:
Quote:
Originally Posted by userjf

If the filter is enabled, the raw value is polled about every 0.5 seconds.

In the filter settings, the sample interval can be set anywhere from 0.5s to 10s. When you note the 0.5, are you listing the fastest value, or are you saying that interval setting is misleading?

If I set mine to 5s, for example, I don't see the raw (or filtered values) update for 5s. So it seems to work...
31st March 2011, 02:17 PM |#6  
Senior Member
Thanks Meter: 160
 
Donate to Me
More
Quote:
Originally Posted by byrong

Very interesting info. Thank you, userjf!

One question:

In the filter settings, the sample interval can be set anywhere from 0.5s to 10s. When you note the 0.5, are you listing the fastest value, or are you saying that interval setting is misleading?

If I set mine to 5s, for example, I don't see the raw (or filtered values) update for 5s. So it seems to work...

The poll to update the raw value with the filter enabled should still be 0.5 seconds, regardless of what you set that interval setting to.

The interval setting, I believe, is how often the filter will look at the raw value for calculation purposes. The raw value will continue to be pollled at 0.5 seconds when you are just watching the value yourself.

That is how I believed it to work, and trying it on my phone just now, it seems to work that way. Even when I set the interval to 10s, I can wave my phone around and see the raw value changing rapidly... but the filter will only check that raw value every 10 seconds for its internal calculations.

Please try again, setting the interval to a high number, going into a bright room, and watching the raw value as you cover and uncover your phone with the shadow of your hand.
31st March 2011, 02:26 PM |#7  
byrong's Avatar
OP Senior Member
Flag East Coast
Thanks Meter: 729
 
More
Quote:
Originally Posted by userjf

Please try again, setting the interval to a high number, going into a bright room, and watching the raw value as you cover and uncover your phone with the shadow of your hand.

You are correct, sir! Very interesting. I could have sworn that when I was doing testing on an earlier version of CM7 that the interval affected the speed of raw readings. Either that changed, or I'm simply misremembering.

Thanks again for the extra info!
31st March 2011, 04:31 PM |#8  
RussianMenace's Avatar
Senior Member
Thanks Meter: 83
 
More
Thank you so much! I've been looking for a breakdown similar to this for weeks. I've been itching to play around with the auto-brightness but the process made no sense to me.
11th April 2011, 04:00 AM |#9  
Senior Member
Thanks Meter: 345
 
More
Is there a way to backup/restore brightness settings between nightlies?
11th April 2011, 02:05 PM |#10  
Senior Member
Flag Happy Valley
Thanks Meter: 42
 
More
as long as you flash over nightlies and don't wipe they stay, but to answer your question directly no there are no backup options for these settings.
11th April 2011, 02:20 PM |#11  
byrong's Avatar
OP Senior Member
Flag East Coast
Thanks Meter: 729
 
More
If you use Titanium Backup, there is an entry for [CM SETTINGS] CyanogenMod settings 2.3.3

That said, I'm not actually sure if it backs up the auto-brightness settings as I haven't needed to use it. I just flash over nightlies, and as noted by ctinsley, my settings remain intact between versions.
Post Reply Subscribe to Thread

Tags
automatic backlight, cm7, cm7 automatic backlight

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes