Numerical explanation of the CM7 automatic backlight settings

Search This thread

byrong

Senior Member
Jul 9, 2010
695
722
East Coast
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:

filter1.png


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:

filter2.png


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.

filter3.png


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.
 

userjf

Senior Member
Dec 22, 2010
1,453
160
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.
 
  • Like
Reactions: tmuka and byrong

byrong

Senior Member
Jul 9, 2010
695
722
East Coast
Very interesting info. Thank you, userjf!

One question:
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...
 

userjf

Senior Member
Dec 22, 2010
1,453
160
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.
 

byrong

Senior Member
Jul 9, 2010
695
722
East Coast
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!
 

RussianMenace

Senior Member
Oct 13, 2010
507
83
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.
 

ctinsley

Senior Member
Nov 4, 2008
203
42
Happy Valley
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.
 

byrong

Senior Member
Jul 9, 2010
695
722
East Coast
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.
 

marcmarshall

Senior Member
Apr 20, 2010
996
63
Providence
Great post byrong. I'm wondering about the screen dim level also. CM defaults to 20 but I took a look at Ultimate and it defaults at 10.

I started playing around with the levels, I added a couple and changed some levels but I really don't know how they effect real world performance. It seemed to me that the little book light in my completely darkened room would max out the raw data and if I added another level I was not able to increase the lux read level. I've deleted it all but I think I was up to around 8 or 10,000 with small book light. I set the brightness for that below 255. I figured daylight at the beach would be a lot more and wanted to set a level to max brightness for that. I could not enter anything higher than 10,000, If I remember correctly.


So does anyone have some good settings they can share?
 

byrong

Senior Member
Jul 9, 2010
695
722
East Coast
I'm wondering about the screen dim level also. CM defaults to 20 but I took a look at Ultimate and it defaults at 10.
That's simply the lower limit to which your brightness can be set. I.E. if you leave it at 20 (which is the factory default), the phone will never dim past that level, even if you try manually. If you set it lower, then it will allow your screen to be set to that lower level when you want. It doesn't change performance of the auto-brightness: it only redefines the "minimum" brightness that the system will allow.

It seemed to me that the little book light in my completely darkened room would max out the raw data and if I added another level I was not able to increase the lux read level.
That's one of the limitations of lux meters, especially in an application like this. The meter is measuring luminous flux spread over a given area, and as such, the distance to the light source makes a world of difference.

A dim lamp could register full brightness on the meter if placed close enough to the phone, whereas a fairly bright room might register a lower lux value if the light is very diffuse.
 

marcmarshall

Senior Member
Apr 20, 2010
996
63
Providence
That's simply the lower limit to which your brightness can be set. I.E. if you leave it at 20 (which is the factory default), the phone will never dim past that level, even if you try manually. If you set it lower, then it will allow your screen to be set to that lower level when you want. It doesn't change performance of the auto-brightness: it only redefines the "minimum" brightness that the system will allow.

That's good to know. I'll just set it in a pitch black room.


That's one of the limitations of lux meters, especially in an application like this. The meter is measuring luminous flux spread over a given area, and as such, the distance to the light source makes a world of difference.

A dim lamp could register full brightness on the meter if placed close enough to the phone, whereas a fairly bright room might register a lower lux value if the light is very diffuse.

Yes, we have the inverse square law here. My concern was that the meter max's out at a level too low to tweak it well in bright outdoor conditions. These screens are so hard to see in sunlight that it might be non issue anyway.

Thanks again byrong
 

marcmarshall

Senior Member
Apr 20, 2010
996
63
Providence
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:
......#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.........

I had missed that and I found that to be true. So set it up so you have smooth transitions and your indoor (low and intermediate) ambient light levels do not trigger screen brightness levels that are too low or unnecessarily bright.

Re hysteresis- this has me confused. In a system that has hysteresis you should not be able to derive the state of output without knowing the history of the inputs (or examining the state of the system). For example if a thermostat is set to turn a furnace on at 60 degrees and off at 75 degrees, you cannot know if the furnace is on or off when the temperature is 70 degrees unless you know the temperature history (or you look at the furnace). So by inference I assume that if we enable hysteresis the screen output level will somehow depend on the sensor input history and not simply on the real time value.

Edit- just took another look and I see that the hysteresis setting is not to enable/disable but to change a percentage. That doesn't make it any clearer for me, just sayin'.
 
Last edited:

marcmarshall

Senior Member
Apr 20, 2010
996
63
Providence
Here its a screen shot of my current level settings. My screen dim level us set st 10, window length 10 sec, sample interval 2 sec. Any suggestions welcome!

4a61b183-1d16-2b9b.jpg


Sent from my ADR6300 using XDA App
 
  • Like
Reactions: cbaird7

lokety

Member
Dec 31, 2010
49
8
Auckland
www.lokety.com
Here its a screen shot of my current level settings. My screen dim level us set st 10, window length 10 sec, sample interval 2 sec. Any suggestions welcome!

Sent from my ADR6300 using XDA App

I tried similar settings as above from another site. When I tapped "save & apply", the screen turned off and remained off! Now, my CM7 Legend boots up, shows the animation for a while, vibrates a bit, screen dims a bit, and then the screen turns off forever! I know it is still booted up and running, but the screen is just off!

What can I do to reset the backlight settings?

Please help. Thanks.
 

marcmarshall

Senior Member
Apr 20, 2010
996
63
Providence
I tried similar settings as above from another site. When I tapped "save & apply", the screen turned off and remained off! Now, my CM7 Legend boots up, shows the animation for a while, vibrates a bit, screen dims a bit, and then the screen turns off forever! I know it is still booted up and running, but the screen is just off!

What can I do to reset the backlight settings?

Please help. Thanks.

Do you have the brightness control in the drop down notification/power control area? If so try hitting the control blind from memory. If you can turn off auto brightness you should be good.
 

lokety

Member
Dec 31, 2010
49
8
Auckland
www.lokety.com
Do you have the brightness control in the drop down notification/power control area? If so try hitting the control blind from memory. If you can turn off auto brightness you should be good.

I'm not sure if I'm getting to the home screen, but I don't have the brightness control in the notification area anyway. I have a lock screen with an unlock pattern defined.

I doubt I'm getting there because I tried maxing the ringer and it doesn't beep as expected.

I'm hoping someone could point out what system file to replace as I can reach recovery and perhaps flash a new file there.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 13
    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:

    filter1.png


    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:

    filter2.png


    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.

    filter3.png


    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.
    2
    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.
    1
    Here its a screen shot of my current level settings. My screen dim level us set st 10, window length 10 sec, sample interval 2 sec. Any suggestions welcome!

    4a61b183-1d16-2b9b.jpg


    Sent from my ADR6300 using XDA App