54 lines
1.1 KiB
Perl
54 lines
1.1 KiB
Perl
#!/usr/bin/perl
|
|
|
|
my $arg = $ARGV[0];
|
|
my $step = 10; # measured in percents
|
|
|
|
sub fsread($); # read 1-st line from file
|
|
sub fswrite(@); # write string to file
|
|
|
|
my $brightnessfile = "/sys/class/backlight/acpi_video0/brightness";
|
|
my $maxbrightness = fsread("/sys/class/backlight/acpi_video0/max_brightness");
|
|
my $currbrightness = fsread($brightnessfile);
|
|
|
|
my $a = $maxbrightness / 100;
|
|
$step = int($step * $a);
|
|
|
|
if ( $arg eq "up" ) {
|
|
if ($currbrightness != $maxbrightness) {
|
|
my $projectedbrightness = $currbrightness + $step;
|
|
|
|
if ($projectedbrightness > $maxbrightness) {
|
|
$projectedbrightness = $maxbrightness;
|
|
}
|
|
|
|
fswrite($projectedbrightness, $brightnessfile);
|
|
}
|
|
} elsif ( $arg eq "down" ) {
|
|
if ($currbrightness != 0) {
|
|
my $projectedbrightness = $currbrightness - $step;
|
|
|
|
if ($projectedbrightness < 0) {
|
|
$projectedbrightness = 0;
|
|
}
|
|
|
|
fswrite($projectedbrightness, $brightnessfile);
|
|
}
|
|
}
|
|
|
|
|
|
sub fsread($) {
|
|
my $fname = shift;
|
|
open (F, $fname) || die;
|
|
my $str = <F>;
|
|
close F;
|
|
return $str;
|
|
}
|
|
|
|
sub fswrite (@) {
|
|
my $str = shift;
|
|
my $fname = shift;
|
|
open(OF, ">", $fname) || die;
|
|
print OF $str;
|
|
close OF;
|
|
}
|