Brightness value convert

Post your questions and help other users.

Moderator: Martin

Post Reply
Bender64
Posts: 20
Joined: 25 Feb 2016 15:47

Brightness value convert

Post by Bender64 » 25 Feb 2016 16:00

Hello, I create widget where i set text to show me screen brightness (auto mode or value). When i set brightness to 50 % widget show me 130, max is 255. As source i use screen_brightness from system settings.
It is possible to widget show me brightness value in % from 0-100?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Brightness value convert

Post by Martin » 25 Feb 2016 20:36

Hi,

You could divide the value by 2.5 to get into the range from 0 to 100.
Assuming the value is stored in variable setting, you could use an action Notification on Screen with following expression:
{setting/2.5,numberformat,0}

numberformat,0 formats the number without decimal places, e.g. 50 instead of 50.3.

Regards,
Martin

Bender64
Posts: 20
Joined: 25 Feb 2016 15:47

Re: Brightness value convert

Post by Bender64 » 26 Feb 2016 08:46

"It's Alive" :mrgreen:
Thx Martin, you are the best.

Image

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Re: Brightness value convert

Post by Bushmills » 05 Jun 2016 11:29

There's a very slight chance that the operation - a so called "scaling operation" - may consume a tad less power by sticking to integers: arithmetically it makes no appreciable difference if, instead of dividing by brightness/2.55 - forcing a floating point operation - the operation consisted of brightness*100/255 (sticking to integers). Languages exists which even provide a 3 argument operation for this kind of integer scaling, using a longer intermediate result for the product to avoid integer overflow.
Automagic scripts language distinguishes between integers and floating point numbers, and does integer or floating point calculation depending on the type of number fed to the calculation, but I haven't done any measuring how performance or power consumption are affected. It should also depend on the microprocessor the code runs on.

Post Reply