2020-11-16 04:55:20 +00:00
|
|
|
#!/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);
|
2020-11-16 04:55:20 +00:00
|
|
|
} else {
|
2020-11-23 09:35:26 +00:00
|
|
|
print "Failed to read $maxfile\n";
|
|
|
|
exit;
|
2020-11-16 04:55:20 +00:00
|
|
|
}
|
|
|
|
print STDERR "max = $max\n";
|
|
|
|
|
|
|
|
if (open(my $c, '<', $current)) {
|
2020-11-23 09:35:26 +00:00
|
|
|
$now = readline($c);
|
|
|
|
chomp $now;
|
|
|
|
close($c);
|
2020-11-16 04:55:20 +00:00
|
|
|
} else {
|
2020-11-23 09:35:26 +00:00
|
|
|
print "Failed to read $current\n";
|
|
|
|
exit;
|
2020-11-16 04:55:20 +00:00
|
|
|
}
|
|
|
|
print STDERR "now = $now\n";
|
|
|
|
|
|
|
|
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);
|
2020-11-16 04:55:20 +00:00
|
|
|
} else {
|
2020-11-23 09:35:26 +00:00
|
|
|
print "Failed to write $current\n";
|
|
|
|
exit;
|
2020-11-16 04:55:20 +00:00
|
|
|
}
|
|
|
|
print STDERR "new = $new\n";
|