Skip to content
Snippets Groups Projects
Commit 8cdb9c7c authored by Roman Lacko's avatar Roman Lacko
Browse files

Customizable timeouts and Backlight

parent 8b2a0d60
No related branches found
No related tags found
No related merge requests found
......@@ -134,7 +134,7 @@ sub init_modules($self) {
# check that only known keys begin with '-'
foreach my $key (grep { $_ =~ m/^-/ } (keys $modcfg->%*)) {
$self->log->warn("unknown '$key' in module description")
unless $key =~ m/^-(name|refresh|driver)$/;
unless $key =~ m/^-(name|refresh|driver|timeout)$/;
}
my ($moddrv, $modname) = $modcfg->@{qw(-driver -name)};
......@@ -179,6 +179,14 @@ sub init_modules($self) {
my %counterconf = (from => 0, step => 1, cycle => 0);
# if module uses custom timeout, notify log
if (defined $modcfg->{-timeout} && $modcfg->{-timeout} >= 1) {
$self->log->info("$modname has custom timeout '$modcfg->{-timeout}'");
} elsif (defined $modcfg->{-timeout}) {
$self->log->info("refusing to use timeout '$modcfg->{-timeout}' as it is invalid");
delete $modcfg->{-timeout};
}
# got here so far, save all
my $entry = {
conf => $modcfg,
......@@ -256,7 +264,8 @@ sub run($self) {
if (!defined $data) {
$data = try {
my $tmp = timeout($self->cfg->{timeout} => sub {
my $to = $entry->{conf}->{-timeout} // $self->cfg->{timeout};
my $tmp = timeout($to => sub {
return $entry->{mod}->invoke;
});
......@@ -506,7 +515,8 @@ sub event($self, $event) {
$self->cache->flush($target);
}
my $tmp = timeout($self->cfg->{timeout} => sub {
my $to = $mod->{conf}->{-timeout} // $self->cfg->{timeout};
my $tmp = timeout($to => sub {
if (!defined $button) {
$self->log->error("got unknown event '$event->{button}' for '$target'");
return $mod->{mod}->on_event;
......
package WBM::Backlight;
use utf8;
use strict;
use warnings;
use parent "WBM::Driver";
use feature qw(signatures);
no warnings qw(experimental::signatures);
use Breeze::Grad;
sub new($class, %args) {
my $self = $class->SUPER::new(%args);
$self->log->fatal("missing 'video' parameter in constructor")
unless defined $args{video};
$self->{video} = $args{video};
return $self;
}
sub invoke($self) {
my $max = qx(cat /sys/class/backlight/$self->{video}/max_brightness);
my $cur = qx(cat /sys/class/backlight/$self->{video}/brightness);
chomp($max,$cur);
my $p = int ((100 * $cur) / $max);
my $c = Breeze::Grad::get($p, qw(dc322f b58900 859900));
my $ret = {
icon => "",
text => sprintf("%3d%%", $p),
color => $c,
};
if (($self->{last} // $p) != $p) {
$ret->{invert} = 1;
}
$self->{last} = $p;
return $ret;
}
sub on_wheel_up($) {
qx(xbacklight -inc 5% -time 50 -steps 5);
return { reset_all => 1, invert => 1 };
}
sub on_wheel_down($) {
qx(xbacklight -dec 5% -time 50 -steps 5);
return { reset_all => 1, invert => 1 };
}
sub on_middle_click($) {
if ($_[0]->{last} < 10) {
qx(xbacklight -set 40% -time 400 -steps 30);
} else {
qx(xbacklight -set 0% -time 400 -steps 30);
}
return { reset_all => 1, blink => 4 };
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment