scripts/thinkpad/kbd_backlight.pl

38 lines
780 B
Perl
Raw Normal View History

#!/usr/bin/perl
use strict;
use warnings;
my $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
my ($max, $now, $new);
if (open(my $m, '<', $maxfile)) {
2020-11-23 09:35:26 +00:00
$max = readline($m);
chomp $max;
close($m);
} else {
2020-11-23 09:35:26 +00:00
print "Failed to read $maxfile\n";
exit;
}
if (open(my $c, '<', $current)) {
2020-11-23 09:35:26 +00:00
$now = readline($c);
chomp $now;
close($c);
} else {
2020-11-23 09:35:26 +00:00
print "Failed to read $current\n";
exit;
}
if (open(my $fh, '>', $current)) {
2020-11-23 09:35:26 +00:00
$new = (($now+1) % ($max+1));
chomp $new;
print $fh $new;
close($fh);
} else {
2020-11-23 09:35:26 +00:00
print "Failed to write $current\n";
exit;
}
#print STDERR "$new\n";