migrate to libcec with cec socket

This commit is contained in:
fred 2026-02-17 15:02:53 -08:00
parent 4a525bb5a6
commit 246535facd
2 changed files with 35 additions and 4 deletions

6
cec.sh
View file

@ -1,15 +1,13 @@
#!/bin/bash #!/bin/bash
tv_on() { tv_on() {
cec-ctl --to 0 --image-view-on echo "on 0" > /run/cec.fifo
#xrandr --output HDMI-A-0 --mode 1920x1080
xrandr --output HDMI-A-0 --auto; sleep 3; xrandr --output HDMI-A-0 --mode 1920x1080
echo "on">~/scripts/PJ/tv_state echo "on">~/scripts/PJ/tv_state
curl -X POST -d '' $REPORT_TV_ON curl -X POST -d '' $REPORT_TV_ON
} }
tv_off() { tv_off() {
cec-ctl --to 0 --standby echo "standby 0" > /run/cec.fifo
echo "off">~/scripts/PJ/tv_state echo "off">~/scripts/PJ/tv_state
curl -X POST -d '' $REPORT_TV_OFF curl -X POST -d '' $REPORT_TV_OFF
} }

33
nix/cec.nix Normal file
View file

@ -0,0 +1,33 @@
{ pkgs, ... }:
{
boot.kernelModules = [ "cec" ];
environment.systemPackages = with pkgs; [
libcec
];
services.udev.extraRules = ''
# Pulse-Eight CEC adapter
SUBSYSTEM=="tty" ACTION=="add" ATTRS{manufacturer}=="Pulse-Eight" ATTRS{product}=="CEC Adapter" GROUP="video" MODE="0660"
'';
systemd.sockets."cec-client" = {
wantedBy = [ "sockets.target" ];
socketConfig = {
ListenFIFO = "/run/cec.fifo";
SocketGroup = "video";
SocketMode = "0660";
};
};
systemd.services."cec-client" = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1 -o /dev/ttyACM0'';
ExecStop = ''/bin/sh -c "echo q > /run/cec.fifo"'';
StandardInput = "socket";
StandardOutput = "journal";
Restart = "on-failure";
};
};
}