You are not logged in.
Project page: http://xyne.archlinux.ca/projects/relight/
My backlight setting is reset to the brightest setting whenever I reboot. There are probably numerous ways to restore previous settings already but rather than look for those I quickly wrote my own script and service (reinventing the wheel ftw). Enable it and your backlight settings should persist across reboots.
The package also includes a simple dialog-base menu to set the backlight for one screen. When I have more time I may try to create a curses-based dialogue that adjust the backlight in realtime as the user changes the setting.
Now let the dust collection in this thread begin!
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Have a look at something similar but already embedded into something more general: https://bbs.archlinux.org/viewtopic.php?id=153959
Last edited by eruditorum (2013-01-23 22:07:13)
Offline
Have a look at something similar but already embedded into something more general: https://bbs.archlinux.org/viewtopic.php?id=153959
I did indeed miss that, but I don't see how it's more general. It bundles multiple functions into a single service and requires the user to directly edit the script to customize it. The latter is admittedly not a real issue but it prevents effective packaging. You could of course create a configuration file and source that, but I still prefer a more modularized approach. Besides, I only needed a backlight service. Sharing it is just an afterthought.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Resetting backlight levels drives me nuts, especially when I don't realise it is set to max until my eyes start hurting. Thanks!
Offline
Xyne, unfortunately it doesn't work due to the error below (from journalctl) - probably race condition occurred and acpi_video0 does not exist yet:
relight[290]: found setting for acpi_video0 but /sys/class/backlight/acpi_video0/brightness does not exist
any ideas how I could fix it? Maybe adding some dependency?
Offline
Maybe it's not video0 in your case?
Offline
What do you think about implementing the distinction between two brightness settings for battery use and AC state?
Then it would be the ideal brightness service to keep track of the correct setting on boot and for different AC states.
Regards
Offline
I have acpi_video0. Anyway, I went through the relight bash script and it is flexible enough to manage lack of device - in particular, it's looking for every device acpi_video* and stores backlight values separately for each one of them.
I should have also stated it explicitly that relight save is working okay, it stores in /var/tmp/relight/screen_* proper value. So the only reason I see is that acpi_video0 does not exist yet when relight script is called.
Offline
Version 2013.3 changelog:
added support for adapter-dependent savestates
added support for user-configurable intervals to wait for /sys/ interfaces
new options gen_conf and del_conf to configure intervals
The default settings are 10 retries with 1 second intervals. Run "relight gen_conf" and edit /etc/relight.conf to suit your needs.
I use prefixes to support the different adapter states so old savestate files should now be ignored. You can remove them with "relight clear".
To configure AC power states, plug in the adapter, configure your backlight, and run "relight save". Unplug the adapter and do the same to configure that battery states. Note that the purpose of relight is to remember backlight states across boots. It will not detect ACPI events and change the backlight dynamically as the adapter is connected or disconnected. If you need that, you can configure one of the dedicated ACPI daemons to invoke relight (or directly manage the backlight). You can of course just run "relight restore" yourself too.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Now it works almost perfectly - it restores value of the screen backlight. I haven't tested configuration file though since I'm okay with default settings. I'm running it as a systemd service.
One minor glitch I found is the error that is logged through journal:
mar 06 23:06:56 clu systemd[1]: relight.service: main process exited, code=exited, status=1/FAILURE
mar 06 23:06:56 clu systemd[1]: Failed to start Restore Backlight Settings.
mar 06 23:06:56 clu systemd[1]: Unit relight.service entered failed state
It is caused by non-zero exit in relight script in line 89. After changing it to 0, it does not display error anymore.
Thanks Xyne for such quick response!
Offline
fixed, thanks!
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Would it be viable to allow the save/restore functions to use custom extensions? It could easily be implemented like so:
if [[ "$2" ]]
then
ext_=".$2"
else
if [[ -e /sys/class/power_supply/ADP0/online ]]
then
if [[ $(cat /sys/class/power_supply/ADP0/online) == 1 ]]
then
ext_=".adp"
else
ext_=".bat"
fi
else
ext_=""
fi
fi
I use linux and I dont understand nothing in this post.
Offline
@Supplantr
I like the idea, but rather than support "extensions", I have implemented it as "profiles". Internally they are still stored using an extension, but the user specifies them with e.g. "bat" instead of ".bat". I have also added a command to list existing profiles (relight list). Let me know if it works as expected.
Thanks for the suggestion.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Let me know if it works as expected.
Thanks, everything works, and profiles integrate well with my power saving script.
I use linux and I dont understand nothing in this post.
Offline
Xyne,
I went ahead and wrote a curses script. It is my first curses c program, so it will probably make the seasoned c devs vomit, but anyone who needs it can use it. https://github.com/mrhhug/Scripts/blob/ … ightness.c
/* Written by Michael Hug: mrhhug is my username on gmail
* tested on :
* Manufacturer: ASUSTeK Computer Inc.
* Product Name: K60IJ */
/* when compiling link curses, something like 'gcc -Wall ./LCDbrightness.c -lncurses -o LCDbrightness.out' */
#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
//change this to match your system
char mbrightfile[] = "/sys/class/backlight/intel_backlight/max_brightness";
char curbrightfile[] = "/sys/class/backlight/intel_backlight/brightness";
int maxbright; //this gets used over and over and does not change, set in main
int read_max_bright()
{
FILE* maxBright = fopen (mbrightfile, "r"); //fopen filename
if (maxBright == NULL) // check for weird errors
{
endwin(); // end cureses mode, return the terminal to regular
printf("Error opening %s\n",mbrightfile);
exit(1);
}
int max_bright; // not sure if c will let you return inline
fscanf (maxBright, "%d", &max_bright); // doing the actual scan
fclose(maxBright); // close the file
return max_bright;
}
int read_cur_bright()
{
FILE* curBright = fopen (curbrightfile, "r"); //fopen filename
if (curBright == NULL) // check for weird errors
{
endwin(); // end cureses mode, return the terminal to regular
printf("Error opening %s\n",curbrightfile);
exit(1);
}
int cur_bright; // not sure if c will let you return inline
fscanf (curBright, "%d", &cur_bright); // doing the actual scan
fclose(curBright); // close the file
return cur_bright;
}
void write_brightness(int brightness)
{
FILE *f = fopen(curbrightfile, "w");
if (f == NULL) // check for weird errors
{
endwin(); // end cureses mode, return the terminal to regular
printf("Error opening %s\n",curbrightfile);
exit(1);
}
fprintf(f, "%d", brightness); // the actual write
fclose(f); // close the file
}
void draw()
{
double curbright = read_cur_bright(); //cast to double for division
double mbright = maxbright; //cast to double for divivsion
erase(); // clear window, needed to remove when used decreases brightness
mvaddstr(0,0,"Use [up arrow,A] or [down arrow,B] to adjust brightness, q to quit"); // instructions
int i; // ....gnu89
int j; // ....gnu89
for(i =1; i<4 ;i+=2)
{
move(i,0);
for(j=0;j<102;j++)
{
printw("-");
}
}
mvaddstr(2,0,"|"); // left edge
mvaddstr(2,101,"|"); // right edge
move(2,1);
for(i=0;i<curbright/mbright*100;i++) // loop to write progress style #s
{
printw("#");
}
move(4,0); // actual numbers, for general reference
printw("%.0f of %d : %f %%",curbright,maxbright,curbright/mbright*100);
}
int main(void)
{
if(geteuid() == 0) // only root can change backlight
{
maxbright = read_max_bright();
initscr(); // Start curses mode
noecho(); // do not print input to screen
int cha; // what we will use to catch input
int newbrightness; // what we will use to set brightness
while (cha != 'q') //exit on q
{
draw();
cha = getch(); //waits for keyboard input
if (cha == 65) // up arrow actually sends a set of 3, only looking for last
{
newbrightness = read_cur_bright()*1.01; // integer multiplication of 101%
if(newbrightness>maxbright) // do no go above max
{
newbrightness=maxbright; // had the multiplacation gone above max, set new brightness to max
}
write_brightness(newbrightness); // write to file
}
if (cha == 66) // down arrow actually sends a set of 3, only looking for last
{
newbrightness = read_cur_bright()*0.99; // integer multiplication of 99%
if(newbrightness>1) // do not go below 1
{
write_brightness(newbrightness); // write to file
}
}
}
endwin(); // end cureses mode, return the terminal to regular
}
else
{
printf("run me as root\n"); // sudo !!
}
return 0;
}
Last edited by mrhhug (2013-12-19 06:22:24)
Offline