From f673ed7ed761635e5efe3bc393c9299a35e0a1a7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 22 Dec 2021 15:02:39 +0000 Subject: intergrated IR control * PWA files * lirc wrapper * lircd config files --- lib/App/MediaControl.rakumod | 27 ++++++++++++++++------ lib/Lirc/Commands.rakumod | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 lib/Lirc/Commands.rakumod (limited to 'lib') diff --git a/lib/App/MediaControl.rakumod b/lib/App/MediaControl.rakumod index 238ae53..e4b5024 100644 --- a/lib/App/MediaControl.rakumod +++ b/lib/App/MediaControl.rakumod @@ -2,20 +2,16 @@ use v6.d; use Cro::HTTP::Server; use Cro::HTTP::Router; use Vlc::Client; -use Lirc::Client; +use Lirc::Commands; class App::MediaControl { has Vlc::Client $.vlc is required; - has Lirc::Client $.lirc is required; + has Lirc::Commands $.lirc is required; has Int $.port = 8080; has Cro::Service $!service handles ; method start() { - my $application = route { - resources-from %?RESOURCES; - - get -> { resource 'index.html' } - + my $vlc = route { post -> 'play' { await self.vlc.command('pl_play') } post -> 'pause' { await self.vlc.command('pl_pause') } post -> 'stop' { await self.vlc.command('pl_stop') } @@ -24,11 +20,28 @@ class App::MediaControl { my $status = await self.vlc.status(); content 'application/json', $status; } + } + + my $ir = route { + post -> $thing, $arg { + await self.lirc.send($thing, $arg); + } + } + + my $application = route { + resources-from %?RESOURCES; + + get -> { resource 'index.html' } + get -> 'ir.png' { resource 'ir.png' } + get -> 'ir.webmanifest' { resource 'ir.webmanifest' } + + include :$vlc, :$ir; around -> &handler { handler(); CATCH { default { + note "BOOM $_"; response.status = 500; content 'application/json', %( error => "$_" ); } diff --git a/lib/Lirc/Commands.rakumod b/lib/Lirc/Commands.rakumod new file mode 100644 index 0000000..a274bdc --- /dev/null +++ b/lib/Lirc/Commands.rakumod @@ -0,0 +1,54 @@ +use v6.d; +use Lirc::Client; + +class Lirc::Commands { + has Lirc::Client $.client is required; + + sub hdmi-seq($input) { + return [ + , + , + ('amplifier', "hdmi{$input}"), + ] + } + sub stop-seq() { + return [ + , + , + , + ]; + } + my %sequences = ( + 'start bluray' => [ + , + , + , + , + ], + 'stop bluray' => [ + |stop-seq(), + , + ], + 'start hdmi1' => hdmi-seq(1), + 'start hdmi2' => hdmi-seq(2), + 'start hdmi3' => hdmi-seq(3), + 'stop hdmi' => stop-seq(), + ); + + method send($thing, $arg) { + if %sequences{"$thing $arg"} -> @seq { + for @seq -> @command { + await self.send(|@command); + sleep 1; + } + return Promise.kept(); + } + else { + note "irsend $thing $arg"; + return self.client.send( + remote => $thing, + keysym => "KEY_{$arg.uc}", + ); + } + } +} -- cgit v1.2.3