KlipperScreen icon indicating copy to clipboard operation
KlipperScreen copied to clipboard

[Enhancement] Add Setting to adjust Screen brightness

Open nicedevil007 opened this issue 4 years ago • 8 comments

heya @jordanruthe

again, I found a small thingi that would be nice to be added to your KlipperScreen.

Adjusting the brightness (tested with RaspberyPi 7" Touchscreen) is working with this command:

sudo sh -c 'echo "128" > /sys/class/backlight/rpi_backlight/brightness'

the number 128 can be anything between 0 and 255.

nicedevil007 avatar Feb 13 '21 15:02 nicedevil007

it would be awesome to see this feature in the feature! Right now I'm using the console. The black looked a bit too much grey :)

Zayl1up avatar Feb 13 '21 15:02 Zayl1up

Thanks for this writeup. This shouldn't be too hard to address and I'll be looking at it in the near future

jordanruthe avatar Feb 14 '21 16:02 jordanruthe

Here are my thoughts on configuring this function:

  1. Configure a specific command (script, binary etc.) with a placeholder (parameter) for the value as to be set.
  2. Configure the minimum and maximum values ​​that can be passed to the command.
  3. Interpolate/calculate the ui value "0-100%" based on the minimum and maximum values.

For many waveshare displays it is possible to control the backlight via PWM -> "gpio -g pwm 18 $value" (control brightness, $value is between 0~1024)

emtrax-ltd avatar Dec 10 '22 12:12 emtrax-ltd

this heavily depends on the screen used and most don't have any software control, and for that reason i don't believe this functionality will reach master.

this is how i would add it if my screen would support brightness control via software:

  1. install G-Code Shell Command Extension
  2. create a couple of macros that set the brightness at different levels, for example min_bright, half_bright, max_bright
  3. add the macros to a menu in klipperscreen
[menu __main brightness]
name: Brightness
icon: light

[menu __main brightness min]
name: Min
icon: speed-
method: printer.gcode.script
params: {"script":"min_bright"}


[menu __main brightness mid]
name: Mid
icon: light
method: printer.gcode.script
params: {"script":"half_bright"}


[menu __main brightness max]
name: Max
icon: speed+
method: printer.gcode.script
params: {"script":"max_bright"}

you can add more levels and icons if you like

alfrix avatar Dec 10 '22 17:12 alfrix

I found out recently, that waveshare displays are able to dim/shutoff the backlight with PWM:

down in the FAQ: https://www.waveshare.com/wiki/5inch_HDMI_LCD#Image https://www.waveshare.com/wiki/Template:Raspberry_Pi_Documentation-GPIO https://www.waveshare.com/w/upload/5/56/PWM_control_backlight_manual.pdf

I added this to my "/etc/rc.local" to enable PWM-dimming at startup and set the brightness by default to 700:

gpio -g mode 12 pwm #set the pin as PWM gpio pwmc 1000 gpio -g pwm 12 700 #change the brightness, ranges 0-1024

By issueing gpio -g pwm 12 0 I switch off the backlight. With gpio -g pwm 12 1024 set it to full brightness.

But this is tedious making by hand and I would like:

It would be nice, to shutoff the backlight when KlipperScreen blanks the display and switches on the backlight again, when touched.

This needs a customization option due to different displays attached to the various raspis. Further, the option to dim the backlight with defined gcode macros is nice too.

Peuqui avatar Nov 23 '23 18:11 Peuqui

There is also another alternative, that i described a while ago on discord

you can create a moonraker power device that uses gpio or a klipper_device that uses a macro or pin, and then configure the options screen_on_devices and screen_off_devices of klipperscreen to trigger said power device, the only drawback is that moonraker needs to be connected.

the idea of this method is to power off and power on the screen when it doesn't support DPMS

alfrix avatar Nov 24 '23 17:11 alfrix

Brilliant! I'll try it out.

Edit: Works like a charm! Added following lines to "moonraker.cfg":

[power Backlight] type: gpio pin: gpiochip0/gpio12 initial_state: on

and following lines to KlipperScreen.cfg:

[main] screen_on_devices: Backlight screen_off_devices: Backlight

Peuqui avatar Nov 24 '23 18:11 Peuqui