From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Dan Murphy <dmurphy@ti.com>, pavel@ucw.cz
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] documention: leds: Add multicolor class documentation
Date: Sun, 9 Jun 2019 17:15:57 +0200 [thread overview]
Message-ID: <d5bdf93b-2a6e-a773-ebb1-4850859ed147@gmail.com> (raw)
In-Reply-To: <20190530181630.30373-2-dmurphy@ti.com>
[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]
Hi Dan,
On 5/30/19 8:16 PM, Dan Murphy wrote:
[...]
> +Multicolor Class Brightness Control
> +-----------------------------------
> +The multicolor class will redirect the device drivers call back
> +function for brightness control to the multicolor class brightness
> +control function.
> +
> +The brightness level for each LED is calculated based on the color LED
> +brightness setting divided by the color LED max brightness setting multiplied by
> +the requested value.
> +
> +led_brightness = requested_value*(led_color_brightness/led_color_max_brightness)
> +
> +Example:
> +Three LEDs are present in the group as defined in "Directory Layout Example"
> +within this document.
> +
> +A user first writes the color LED brightness file with the brightness level that
> +is neccesary to achieve a blueish violet output from the RGB LED group.
> +
> +echo 138 > /sys/class/leds/rgb:grouped_leds/red/brightness
> +echo 43 > /sys/class/leds/rgb:grouped_leds/green/brightness
> +echo 226 > /sys/class/leds/rgb:grouped_leds/blue/brightness
> +
> +red -
> + brightness = 138
> + max_brightness = 255
> +green -
> + brightness = 43
> + max_brightness = 255
> +blue -
> + brightness = 226
> + max_brightness = 255
> +
> +The user can control the brightness of that RGB group by writing the parent
> +'brightness' control. Assuming a parent max_brightness of 255 the user may want
> +to dim the LED color group to half. The user would write a value of 128 to the
> +parent brightness file then the values written to each LED will be adjusted
> +base on this value
> +
> +cat /sys/class/leds/rgb:grouped_leds/max_brightness
> +255
> +echo 128 > /sys/class/leds/rgb:grouped_leds/brightness
> +
> +adjusted_red_value = 128 * (138/255) = 69
> +adjusted_green_value = 128 * (43/255) = 21
> +adjusted_blue_value = 128 * (226/255) = 113
> +
> +Reading the parent brightness file will return the current brightness value of
> +the color LED group.
I've tested this algorithm with python script and at least on my LED
monitor it works as expected. Attached is the script I've come up with.
> +cat /sys/class/leds/rgb:grouped_leds/max_brightness
> +255
> +
> +echo 128 > /sys/class/leds/rgb:grouped_leds/brightness
> +
> +cat /sys/class/leds/rgb:grouped_leds/max_brightness
> +128
> +
> +
>
--
Best regards,
Jacek Anaszewski
[-- Attachment #2: led_color.py --]
[-- Type: text/x-python, Size: 827 bytes --]
#!/usr/bin/python3.5
from PIL import Image
import sys
import time
WIDTH = 500
HEIGHT = 500
def print_usage():
print ('Usage: led_color.py RED GREEN BLUE TOP_BRIGHTNESS')
sys.exit(0)
def main():
if len(sys.argv) != 5:
print_usage()
MAX_R = int(sys.argv[4])
MAX_G = int(sys.argv[4])
MAX_B = int(sys.argv[4])
R = int(sys.argv[1])
G = int(sys.argv[2])
B = int(sys.argv[3])
TB = int(sys.argv[4])
for BR in range(1,TB+1):
OUT_R = int(BR * R / MAX_R)
OUT_G = int(BR * G / MAX_G)
OUT_B = int(BR * B / MAX_B)
print("red: {}, green: {}, blue: {}".format(OUT_R, OUT_G, OUT_B))
img = Image.new("RGB", (WIDTH,HEIGHT), (OUT_R,OUT_G,OUT_B))
img.show()
time.sleep(0.1)
if __name__ == "__main__":
main()
prev parent reply other threads:[~2019-06-09 15:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-30 18:16 [PATCH v4 1/2] leds: multicolor: Add sysfs interface definition Dan Murphy
2019-05-30 18:16 ` [PATCH v4 2/2] documention: leds: Add multicolor class documentation Dan Murphy
2019-06-09 15:15 ` Jacek Anaszewski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d5bdf93b-2a6e-a773-ebb1-4850859ed147@gmail.com \
--to=jacek.anaszewski@gmail.com \
--cc=dmurphy@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).