Setting System brightness Above 255?

Post your questions and help other users.

Moderator: Martin

Pepy
Posts: 76
Joined: 31 Oct 2018 10:53
Location: Canada

Setting System brightness Above 255?

Post by Pepy » 12 Nov 2018 13:14

Hi there,
I've been working on a Flow for a while now, with the goal of adjust increasing or decreasing the system brightness when triggered.
A problem I'm facing is setting the brightness. Using the "Set Screen Brightness" action, I can only set the brightness to a max value of 255 (any higher is an invalid value), which is only about one third of my brightness slider (see attached image), and while using "Init System Variable" to get the begithness value at max brightness returns 1023.
I'm currently on Android 8.1. Does anyone know of a workaround for this?
Hope my post was helpful :D
Device: OnePlus 5T running crDroid, rooted with Magisk 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Setting System brightness Above 255?

Post by Desmanto » 12 Nov 2018 23:39

You need to use "Set System Setting", find the value which store the brightness. Usually it is at the system category, screen_brightness. But since you are using non standard ROM, the value can be stored differently.

Create a flow with trigger System Setting Changed, global. Add another 2 with the same, but choose system and secure. (You have 3 triggers in the same flow). Add action notification on screen, put
{setting_name} {setting}
enable the flow and change your brightness. You should see the name of the value. Use this in Set System Setting.

This doesn't guarantee it will work, since not all ROM reflect every setting change. And you need to grant Automagic write secure permission first from adb.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Pepy
Posts: 76
Joined: 31 Oct 2018 10:53
Location: Canada

Re: Setting System brightness Above 255?

Post by Pepy » 13 Nov 2018 15:46

Hi, and thank you for your reply.

If I understood you correctly, I am actually in fact using the stock ROM (OxygenOS) which came pre-installed with my device, not a custom ROM of any sort.

Anyway, following your instructions, I found out that both "screen_brightness" and "screen_auto_brightness_adj" (under the System category) works (the difference being that the latter is not affected by changes made by auto-brightness). None of the settings any of the three categories were triggered when the brightness was changed. I'll just stick with "screen_brightness" for now, since it's the same that I used for retrieving the brightness.

Also, I have one more question. You said that the system setting variable for the brightness varies depending on the device you're using, does this also apply to the max value of the brightness? I'd really appreciate it if you could check yours for me to see, so I can compare it to mine (which is 1023, as stated in my opening post).
Last edited by Pepy on 01 Jun 2019 22:49, edited 1 time in total.
Hope my post was helpful :D
Device: OnePlus 5T running crDroid, rooted with Magisk 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Setting System brightness Above 255?

Post by Desmanto » 15 Nov 2018 18:31

Sorry for the confusion. When I mean non standard ROM, it includes the ROM heavily modified by the vendor, not AOSP-ish anymore as in android one or Pixel line.
So MIUI stock ROM or Oxygen Stock ROM also considered non standard ROM.

I am currently using RR 6.2 Oreo 8.1, AOSP ROM with customization, based on LOS. I have "screen_brightness" ranging from 0 to 255, and this only works when the auto brightness is off. When auto brightness is on, "screen_auto_brightness_adj" will be in charge. The value range from -1.0 to 1.0, with floating value in between (so I can have values like -0.755123 or 0.65341). I tried to change this value when auto brightness is on, and the system reflect the changes immediately (for example, current is -0.5, changed to 1.0 - full auto brightness). So the action works at my current ROM. You need to try at yours. Try to change the brightness slider and recheck the value at those settings. Try to modify to see if the system reflect the changes.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Pepy
Posts: 76
Joined: 31 Oct 2018 10:53
Location: Canada

Re: Setting System brightness Above 255?

Post by Pepy » 19 Jan 2019 04:00

I see, so basically every ROM that has been modified in any way is a non-standard ROM.

Thank you for sharing your the ROM you're using and the brightness range it uses. If I recall, two settings seem to work, but I decided to end up using "screen_brightness" instead, so it does work fine for me as well. I had to include global_variables for the minimum and maximum values for the brightness, however, and if I do end up sharing the flow, the user may have to input their own values since there doesn't seem to be a good way to determine these values automatically.

Now, since you told me that you can have two different brightness values depending on whether auto brightness is on or not, I'm wondering if it's necessary to include different sets of all in a map or list. In my opinion, it probably might be better to just use the Set System Setting action for both the brightness whether or not they range from 0 to 255 though.

I have also gotten some help from Martin as well on some of the other issues I had like the Execution Counter action mistakenly thinking that the value of the integer variable is null when it's not.

But anyway, thank you for your help. I've gotten just about everything working now with this and another sub-flow that toggles Night Screen.
Last edited by Pepy on 01 Jun 2019 22:49, edited 1 time in total.
Hope my post was helpful :D
Device: OnePlus 5T running crDroid, rooted with Magisk 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Setting System brightness Above 255?

Post by Desmanto » 19 Jan 2019 18:37

For different devices, you can't help with them. You have to show them how to find the value, and edit the maximum number. I prefer the final user understand the concept of the flow and can modify by their own. But of course some adaptation should be done to make it easier to share our idea of the flow. In this case, probably don't use glovar, since it is only single number. Simply show them where to edit the maximum number.

Yes, you can set a value to convert the range you have set. Example using 0-100 as the scale. When this value is used for the screen_brightness with maximum 255, then each 1 point will be multiply with 2.55, and round to the nearest integer. While for the screen_auto_brightness_adj, will be minus 50 and divided by 50. Example, 30 at the scale, will be 30-50 = -20. Divided by 50, we get -0.4 to be used at the set system setting.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Pepy
Posts: 76
Joined: 31 Oct 2018 10:53
Location: Canada

Re: Setting System brightness Above 255?

Post by Pepy » 04 Feb 2019 00:04

Right, I see what you mean by that. It would make more sense for the user to understand how the flow works, rather than just give them a shortcut for modifying the necessary values.

As for the global variables, is it ever a good idea to use it to hold the values that could be just declared locally? I've started using Maps not too long ago for some of my flows, but in your opinion, this may not be good idea no matter how many values you have, right? I'd like to hear your opinion on this.

Where exactly did the "minus 50 and divided by 50" come from? And since the value you gave is an example, in actuality, it wouldn't make sense to have a negative value, right?
But basically, what you're essentially saying is to write an algorithm that can convert between the two values depending on the maximum value given?
Last edited by Pepy on 01 Jun 2019 22:50, edited 1 time in total.
Hope my post was helpful :D
Device: OnePlus 5T running crDroid, rooted with Magisk 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Setting System brightness Above 255?

Post by Desmanto » 04 Feb 2019 07:03

If the variable only used in that flow, better declare locally. So it doesn't pollute the glovar.

Using too many glovar will slow down every elements in all your flow. Because glovar is always used as the context before executing any element. I am still thinking the concept to request additional variable, which can be called flow_variable. The variable persist after execution, but only available to that flow. I haven't tested it yet properly, hence haven't posted it.

At the size of 10-20 KB of glovar (variables.bin at your automagic folder), there is no visible slowdown. But I ever hit 100 KB, every element execution delayed by more than 500 ms. The effect cascaded if you have more elements in between. This cause a significant slowdown that is visible in all flows. I painfully endured it for probably more than a month. But after a massive clean up, deleting a lot of my variable logger glovar content; the speed of execution return back to normal.

So don't put too may unnecessary glovar. If you need logging, you need to dump the glovar to text file, by using toJSON() and action Write to files.

=============
For the brightness, the range at my phone is -1.0 to +1.0. So the range is only 2, but with decimal. The original 0-100 scale has the range of 100. To get the same range, so we should divide 100 by 50 = 2. Hence divide by 50. But the 0 value start from -1.0. So to get the same value, after divided by 50, I should deduct 0 by -1.0, hence -1. But before division, -1 will be scaled up to -50 (I choose to minus first before division, but the result is the same, only different scale).

Hence comes minus by 50 (I choose minus first) then divide by 50. Example 20, minus 50, we get -30. Divided by 50 = -0.6
0 >>> -1.0
20 >>> -0.6
40 >>> -0.2
50 >>> 0.0
60 >>> 0.2
80 >>> 0.6
100 >>> 1.0
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Pepy
Posts: 76
Joined: 31 Oct 2018 10:53
Location: Canada

Re: Setting System brightness Above 255?

Post by Pepy » 26 Apr 2019 08:17

It's certainly been a while. I've been spending a lot more time with Automagic now, and I've learned a lot since then.

Apart from what you mentioned, I've started making some rules to limit the use of global variables, such as:
  • Must be used in multiple flows
  • Must not be static values
  • Must have a clear descriptive name if it's used for a particular purpose, and not something like storing audio volume or device brightness, in which case, may be useful, since other flows will surely make use of it too
About your idea though, won't that require adding a completely new type of variable? I feel that time could be better spent on adding other more important changes, especially since you never know when other flows will make use of that same variable.

Thank you for sharing your experience by the way. I'll be sure to keep it in mind. Right now, I'm currently only at just barely over 1 kb. It's hard to imagine just how many you've had during then, but I guess it shouldn't be too surprising, having taken a look at all the impressive flows you've shared.

I haven't played around much with the JSON or the text file action though. Logging certainly is helpful however, and I have used it to get the correct SMS number since the Send SMS action seems quite picky with the country codes.

For the brightness values you've told me about though, that's quite surprising. I've never seen decimal values in brightness, which is why I have a Script action in the flow for rounding the values. Perhaps I could use a Execution connection for this to see if rounding is necessary.
I haven't thought about looking into dealing with multiple brightness values yet though, but I doubt it's worth it since every device is different, and making an algorithm to change between the different values will be a waste of time. Still, I appreciate your effort in writing all that out for me, but I think it'll be much better to just ask the user to enter the values manually themselves, which I can store using a map (ex. min/max, min2/max2).

I don't understand some of what you said though. Why exactly would you need to scale the number by 50? And how does changing the order between subtraction and multiplication not make a difference (it should give a completely different result).
Last edited by Pepy on 01 Jun 2019 22:52, edited 2 times in total.
Hope my post was helpful :D
Device: OnePlus 5T running crDroid, rooted with Magisk 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Setting System brightness Above 255?

Post by Desmanto » 26 Apr 2019 16:38

After scripting for a while, most of us will develop a common practice that we follow. :) I also have set of rules I follow for my own style of scripting.

"Flow variable" which I propose, is just the same thing as global variable, except it only works in that flow. This is useful for declaring static value prior the flow execution. Example, if you see my Automagic backup flow : viewtopic.php?f=3&t=7858
I declare a list of variable in the beginning of the flow. If these variables can be stored in another "Flow variable", I don't need to init it again, and it will be available to all elements for that flow execution. While I know it cost only one script element to declare it, sometimes it is important to certain speedy and frequently triggered flow (example sensor based flow). It also can be use to log data to the flow variable, without hogging the global variable space. So massive logging will only slow down that flow, but not other flow.

Exporting the flow variable to global variable should be as easy as assigning the glovar value to the flowvar in the script. My glovar expand to that big, mostly because of reckless logging. A single day of user activity or periodic timer with one minute interval can probably takes up 20 KB (depends on what we log). 5 days is enough to slow down Automagic to a turtle. I trimmed it all way down to 10+ KB, and it run fast again. But now, it grows again to 30+ KB. I am creating another flow just to trim down and save the glovar to json file for later usage. Because I still occassionally do some logging before creating the flow for it. So I can have example data to play with.


If we want to design a flow which work on multiple devices, we should make a defined variable to fill. The min and max brightness value to fill. Then we can calculate the range from there. Adjust it to 0-100 range that we use in our flow.
I am sorry for confusing the order of the operation. The number used are different if we change the order.

minflow = 0
maxflow = 100
rangeflow = 100
will be converted to
min = -1.0
max = +1.0
range = 2.0

Example x = 20
We can choose to minus first before division
var = (x - 50) / 50
(20 - 50) / 50 >> -30 / 50 >> -0.6

Or we can choose to divide first before minus
var = x / 50 - 1.0
20 / 50 - 1.0 >> 0.4 - 1.0 >> -0.6

Both result the same, but have different number and operation order
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply