Skip to content

Instantly share code, notes, and snippets.

@a2ron
Forked from bahamas10/cec-keypresses.sh
Created October 21, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ron/b975565a1022ed8c43a468693c59b173 to your computer and use it in GitHub Desktop.
Save a2ron/b975565a1022ed8c43a468693c59b173 to your computer and use it in GitHub Desktop.
use `cec-client` to fire events when keys are pressed
#!/usr/bin/env bash
#
# binding remote control commands
#
# Author: Aaron Rosas
# Date: 21/10/2018
# Licens: MIT
# Tested on: Raspberry pi 3 with cec-client installed
cec-client -t a | perl -nle 'BEGIN{$|=1} /key (pressed|released): (.*) (.*) (.*)/ && print $2' | \
while read cmd; do
case "$cmd" in
"volume down") ./ir-commands.sh down;;
"volume up") ./ir-commands.sh up;;
*) echo "unrecognized button ($cmd)";;
esac
done

install libcec on raspbian

sudo apt-get update
sudo apt-get install build-essential autoconf liblockdev1-dev libudev-dev git libtool pkg-config
git clone https://github.com/Pulse-Eight/libcec
cd libcec
./bootstrap
./configure --with-rpi-include-path=/opt/vc/include --with-rpi-lib-path=/opt/vc/lib --enable-rpi
make
sudo make install
sudo ln -s /usr/local/lib/libcec.so /usr/lib/
sudo ln -s /usr/local/lib/libcec.so.2 /usr/lib/

run cec-keypresses.sh

~$ ./cec-keypresses.sh 
right button pressed
right button pressed
left button pressed
up button pressed
down button pressed
select button pressed
select button pressed
#!/bin/bash
#set -x
################################################################################
KODI_VOLUMEN_FILE=kodi-volumen.txt
KODI_VOLUMEN=$(cat $KODI_VOLUMEN_FILE)
DIFF=3
if [ "$KODI_VOLUMEN" == "" ]; then
KODI_VOLUMEN=50
elif [ $KODI_VOLUMEN -gt 100 ]; then
KODI_VOLUMEN=100
elif [ $KODI_VOLUMEN -le 0 ]; then
KODI_VOLUMEN=0
fi
if [ "$1" == "down" ]; then
KODI_VOLUMEN=$(($KODI_VOLUMEN-$DIFF))
elif [ "$1" == "up" ]; then
KODI_VOLUMEN=$(($KODI_VOLUMEN+$DIFF))
fi
echo $KODI_VOLUMEN > $KODI_VOLUMEN_FILE
xbmc-send -a "SetVolume($KODI_VOLUMEN,true)"
xbmc-send -a "Notification(Volume,$KODI_VOLUMEN)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment