Last active
July 13, 2018 10:08
-
-
Save danieljimenez/296aed86e7fc8ebd86ffa2c69e65120f to your computer and use it in GitHub Desktop.
CEC HDMI Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cec | |
import logging | |
import uinput | |
import time | |
logging.basicConfig(level=logging.DEBUG) | |
u = uinput | |
KEYMAP = { | |
0: u.KEY_ENTER, | |
1: u.KEY_UP, | |
2: u.KEY_DOWN, | |
3: u.KEY_LEFT, | |
4: u.KEY_RIGHT, | |
5: u.KEY_TAB, | |
6: u.KEY_F5, | |
7: u.KEY_F11, | |
200: u.KEY_LEFTCTRL, | |
201: u.KEY_LEFTSHIFT, | |
} | |
cec.init('RPI') | |
device = uinput.Device(KEYMAP.values()) | |
def on_key(event, key, state): | |
if event is 2: | |
if state > 0: | |
logging.debug("Got key '{}', State '{}'".format(key, state)) | |
if key == 1: # Up | |
device.emit_click(u.KEY_F5) | |
elif key == 2: # Down | |
device.emit_click(u.KEY_F11) | |
elif key == 3: # Left | |
device.emit_combo((u.KEY_LEFTCTRL, u.KEY_LEFTSHIFT, u.KEY_TAB)) | |
elif key == 4: # Right | |
device.emit_combo((u.KEY_LEFTCTRL, u.KEY_TAB)) | |
else: | |
logging.error("Unknown key {} found, sending through...".format(key)) | |
device.emit_click(key) | |
cec.add_callback(on_key, cec.EVENT_ALL) | |
logging.info("CEC Ready") | |
while True: | |
time.sleep(9e9) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=HDMI CEC Hack Utility | |
After=display-manager.service | |
[Service] | |
SyslogIdentifier=cec-hack | |
ExecStart=/usr/bin/python /usr/local/src/cec/main.py | |
Restart=on-failure | |
StandardOutput=inherit | |
StandardError=inherit | |
Restart=always | |
User=root | |
Nice=-5 | |
[Install] | |
WantedBy=default.target | |
Alias=cec.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment