Code Monkey home page Code Monkey logo

es-cec-input's Introduction

es-cec-input

TV CEC remote control support for Emulation Station (included in RetroPie)

Features

  • It will automatically map your retroarch keyboard config to the remote control buttons. Ensure you pick a key for all available options ( See Supported Keyboard Keys Below )

  • It will not act on remote button presses when kodi or retroarch is running and will act as soon as ES returns or starts.

Buttons

ES <-> TV Remote

A <-> SELECT or RED

B <-> EXIT or GREEN

UP <-> UP

DOWN <-> DOWN

LEFT <-> LEFT

RIGHT <-> RIGHT

START <-> FAST FORWARD or BLUE

SELECT <-> REWIND OR YELLOW

Dependencies

It depends on the cec-utils package and also the python-uinput package which contains the library and the udev rules at /etc/udev/rules.d/40-uinput.rules.

Both cec-utils and python-uinput are in the repositories.

The 40-uinput.rules file should look like the following

ACTION=="add|change", KERNEL=="event[0-9]*", ENV{ID_VENDOR_ID}=="012a", ENV{ID_MODEL_ID}=="034b",
ENV{ID_INPUT_KEYBOARD}="1", ENV{ID_INPUT_TABLET}="1"SUBSYSTEM=="input", ATTRS{name}=="python-uinput",
ENV{ID_INPUT_KEYBOARD}="1"KERNEL=="uinput", MODE:="0666" 

Run the code as a non root user

You must first create the uinput group

sudo addgroup uinput

Then add the pi user to the uinput group

sudo adduser pi uinput

Testing before autostart

Note: It was developed and tested on a pi3 with Retropie 4.1 with kodi installed in the ports section of retropie

To make sure it will work you should run the script as a non root user.

First make the script executable (assuming your in the same directory as the file)

chmod u+x es-cec-input.py

then run it with

./es-cec-input.py

If you see no output then you can try your TV remote with the buttons in the Button section above. If it works then proceed to the next section

If you see output it will exit and tell you the key which is unsupported and a list of the supported keys.

Ensure all your keys are supported and try again until you get no output.

Autostart on boot

To start on boot, add to user's crontab.

crontab -e

Add the line,

@reboot nohup /home/pi/PATH/TO/THE/SCRIPT/es-cec-input.py

Supported Keyboard Keys

Note: You must set up your keyboard in Emulation Station first (pick a key for all options!) or the script will not work

As keys need to be mapped from retroarch.cfg supported keys to corresponding uinput supported keys not all the keys are available. However most are supported, as seen below

Letters ("a" to "z"), left, right, up, down, enter, kp_enter, tab, insert, del, end, home, rshift, shift, ctrl, alt, space, escape, kp_plus, kp_minus, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, num0, num1, num2, num3, num4, num5, num6, num7, num8, num9, pageup, pagedown, keypad0, keypad1, keypad2, keypad3, keypad4, keypad5, keypad6, keypad7, keypad8, keypad9, period, capslock, numlock, backspace, scroll_lock, backquote, pause, comma, minus, slash, semicolon, equals, backslash, kp_period, kp_equals, rctrl, ralt

(where "kp_"# is for keypad keys)

FAQ

  • The script is not working after exiting from kodi. This is due to a setting in kodi. Solution
  • Using remote is not controlling menu but signal is being received (goes out of screensaver). Happens when keyboard was not configured as a controller. Solution

es-cec-input's People

Contributors

c2v4 avatar dillbyrne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

es-cec-input's Issues

CEC doesn't work when TV isn't powered on

When i start the tv and pi in that order es-cec-input works. but when i start the tv when the pi is already running cec doesn't work. when i start the script manually i have double inputs - that means in emulationstation menu it jumps not one point to left or right, it jumps two point in that direction. when the script isn't running nothings works.

i had this problem with not working cec when tv is powered on later than the pi also with libreelec. here it was enough to use the first hdmi port on the tv (it seems on some devices only the hdmi 1 fast a full cec support or something like that). but the pi is already connected to hdmi 1.

Buttons

Hey there lovely script you made for using libcec with retropie! Bit hacky but hey works right?! I was able to connect my remote via your script but one thing that i noticed was that in my retroarch.conf your script detected a illegal 1. However this was not the case except for extra lines in the bottom;
input_player1_analog_dpad_mode = "1"

I just uncommented the if section for checks for "1" but figured i'd post this here. Perhaps you could change the if section of your script. My python knowledge == "0" :)

Also, i changed buttons via evtest. Perhaps it would be handy for new users to point them in that direction should they need to change button layout with their remote controller. (I just reversed A and B).

General usage

Hi @dillbyrne

Thanks for your work! I am trying to integrate my OSMC with RetroPie. Idea controlling the both OSMC/Kodi and EmulationStation/RetroPie with a single remote via HDMI/CEC is definitely appealing. However I have some general usage issues with your script.

I believe I have managed to install all the dependencies. Added missing /etc/udev/rules.d/40-uinput.rules and confirmed the script works in background with evtest tool.

However I still cannot control the EmulationStation. ES is stuck waiting for a controller.

Any ideas?

Errors on line 209 (press_keys(lines.next(), device, keylist))

Issue in the title

Setup is a little different to most;
RasPi3B+ running OSMC with menu options to launch RetroPi
Retropi was installed using the "retrosmc" script (which works fine)

Followed the instructions to enable CEC in es (replacing "pi" with "osmc" in sudo adduser pi uinput - I gave the script a once over to make sure that the user "pi" wasn't specifically referenced) but when I run es-cec-input.py

osmc@osmc_main:~$ ./es-cec-input.py
Traceback (most recent call last):
  File "./es-cec-input.py", line 224, in <module>
    main()
  File "./es-cec-input.py", line 209, in main
    press_keys(lines.next(), device, keylist)
StopIteration

Additionally once this occurs, vi fails with
vi: can't read user input
but I'm assuming that's because of the errors above - a reboot sorts it

Not really troubleshooted as I haven't a clue where to start. I did have issues installing python-uinput as I needed to install wheel first.

Any thoughts?

'nte' key unsupported

Hi,

I tried your script, in order to be able to use my remote with the emulationstation interface. When I run it, I get this message:

The 'nte' key in your retroarch.cfg is unsupported by this script
And then a list of the supported keys.

The thing is: what key is that? In which retroarch.cfg (if I search in my filesystem, there are several of them. I assume is the one located at /opt/retropie/configs/all/retroarch.cfg). In that file there was no reference to an "nte" key whatsoever.

I can't figure it out what it means.

...help?

Don't work on RetroPie 4.6

Should the script work with retropie 4.6? There is an error when i start the script

Traceback (most recent call last):
  File "./es-cec-input.py", line 224, in <module>
    main()
  File "./es-cec-input.py", line 183, in main
    device = register_device(keylist)
  File "./es-cec-input.py", line 129, in register_device
    return uinput.Device(keylist)
  File "/usr/lib/python2.7/dist-packages/uinput/__init__.py", line 178, in __init__
    self.__uinput_fd = fd or fdopen()
  File "/usr/lib/python2.7/dist-packages/uinput/__init__.py", line 84, in fdopen
    return _libsuinput.suinput_open()
  File "/usr/lib/python2.7/dist-packages/uinput/__init__.py", line 70, in _open_error_handler
    raise OSError(code, msg)
OSError: [Errno 13] Failed to open the uinput device: Permission denied

It works when i start it with sudo but cec doesn't work.

Problem when exiting Kodi and returning to Emulationstation

Thanks for making CEC work in Emulationstation. I have one small issue though.
Everything works fine until I exit Kodi and return to Emulationstation. Then I get no response from CEC remote. If I start the script again it works, but is there some way to make sure it is always running?

Start script after closing Kodi again

Hey there,

first of all thanks fpr the nice script!

Got it working on boot - but after I start Kodi through the Retropie Ports section and close it again, Retropie doesn't recognize CEC Inputs anymore until I start Kodi again (with an USB Keyboard) or reboot the Pi.

Is there a way to let the script run upon closing Kodi?

I'm a Linux noob myself - Sorry if this is a stupid question.

List index out of range

When running the script I get the following error:

Traceback (most recent call last): File "./es-cec-input.py", line 223, in <module> main() File "./es-cec-input.py", line 181, in main keylist = generate_keylist() File "./es-cec-input.py", line 92, in generate_keylist key_bindings = get_key_bindings('/opt/retropie/configs/all/retroarch.cfg') File "./es-cec-input.py", line 122, in get_key_bindings keys.append(line.split('=')[1][2:-2]) IndexError: list index out of range

A keyboard is configured. My config file can be found at https://pastebin.com/SF4CNTDD

I am using the most current version of Retropie.

It appears that this problem occurs because I have the setting input_player1_analog_dpad_mode" "1" in my configuration. If I uncomment the line, the script works without any problems.

keypresses not detected

Hi, it's me again,
I managed to run the script without errors, but it is still unable to detect any keypresses from my tv remote, either in emulationstation or using the utility evtest. Maybe it's conflicting with the cec driver in Kodi, I don't know. Oh, I disabled that option to turn off the cec signal after closing Kodi that some other user suggested, but that didn't make a difference.

Anyway, that's what I do: after closing Kodi, I run the es-cec-input.py script (as the pi user), and then I run the evtest where I select the python-uinput option (the other is my bluetooth gamepad). And basically, it doesn't recognise any of the keypresses I do.

I haven't formally configured a keyboard in retropie. If I plug a keyboard, it just works fine to browse the menus and select games, but I don't know if that's enough to "configure it".

Also, I noticed that when the script is running at the same time as Kodi, the CPU usage increases by ~10% in a raspberry pi 2. I've disabled it from crontab until I figure out why.

I hope you can help me. It's not a big deal, but I think it's a good tool and I'd like to use it.

Retroarch.cfg

Raspberry Pi 4b 2gb
Retropie 4.8 (original image used)

Hi all,

I am trying to get this working since I would love to just use my remote to start kodi instead of needing my controller or mini keyboard. Ive installed the dependencies and I get to the part to try the script, when executing the script I end up with an output that states:

The 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul' (not sure how many but a lot of them lol) keys in your retroarch.cfg are unsupported by this script.

Supported keys are:
bla bla blaaa etc

Now my question is, is it the config file in opt/configs/all/retroarch.cfg? All the players input are set to nul.

As far as I understand, retroarch pulls the data from the joypad config files.
My keyboard has been configured, Ive done some reboots inbetween too. I dont see a keyboard config file where all the joypad configs are stored.

Could someone hopefully shed some light on what I am doing wrong.

Thank you!

Button to Open Kodi

I thought it would be cool to have a button on the remote that would automatically open Kodi. Im probably going about this the wrong way but I added the following to the script (after removing the green button from the existing commands). It works when testing in command line but not when emulationstation is open. Any help would be appriciated.

elif "green" in line:
            Kodi = subprocess.Popen("/home/pi/RetroPie/roms/ports/Kodi.sh")

input_player1_analog_dpad_mode is parsed

The configuration input_player1_analog_dpad_mode = "1" is parsed and returns the key "1". The script then stops because the key is invalid.

The script should check if the line is commented out or contains "input_player1_analog_dpad_mode".

This can be done by changing line 121 from

if 'input_player1_' in line and '#' not in line:
to
if 'input_player1_' in line and '#' not in line and 'input_player1_analog_dpad_mode' not in line:

doubled input

I'm using es-cec-input on retropie 4.4 and kodi 18.0rc1. In emulationstation, the only buttons work is up, down, left and right. In kodi, every input is recognized as a doublehit since the cursor always jumps two steps.
retroarch.cfg is:

...
input_player1_a = "a"
input_player1_b = "b"
input_player1_y = "y"
input_player1_x = "x"
input_player1_start = "d"
input_player1_select = "s"
input_player1_l = "shift"
input_player1_r = "rshift"
input_player1_left = "left"
input_player1_right = "right"
input_player1_up = "up"
input_player1_down = "down"
input_player1_l2 = "ctrl"
input_player1_r2 = "rctrl"
input_player1_l3 = "num1"
input_player1_r3 = "num2"
...

Missing 40-uinput.rules file

Hello there,
I’m a newb admittingly and I’ve been trying to get this to work for a while.

I’ve installed the cec-utils package and also the python-uinput package but there is no 40-uinput.rules file at:
/etc/udev/rules.d/

Is this supposed to be there upon install of the above packages? Do I simply need to create it?

Setup problem, very new on unix

Hello,
first of all, sorry for my english ^^.

I've tried to run es-cec-input .
At first i've installed cec-utils with

sudo apt-get install cec-utils

No problems.

After this i've tried to install python-uinput with:

sudo apt-get install python-uinput

I got this error:

E: Unable to locate package python-uinput

After this i cloned the git-rep:

git clone -v https://github.com/tuomasjjrasanen/python-uinput.git

Then i run python setup.py build and python setup.py install

No problems, i've copied the 40-uinput.rules to /etc/udev/rules.d/
and edited it to:

ACTION=="add|change", KERNEL=="event[0-9]*", ENV{ID_VENDOR_ID}=="012a", ENV{ID_MODEL_ID}=="034b", ENV{ID_INPUT_KEYBOARD}="1", ENV{ID_INPUT_TABLET}="1"SUBSYSTEM=="input", ATTRS{name}=="python-uinput", ENV{ID_INPUT_KEYBOARD}="1"KERNEL=="uinput", MODE:="0666"

Then i've downloaded your file with

wget https://github.com/dillbyrne/es-cec-input/blob/master/es-cec-input.py

changed chmod to u+x and tried to launch and i get this error:

pi@retropie:~/pythonUinput $ ./es-cec-input.py
./es-cec-input.py: line 1: syntax error near unexpected token newline' ./es-cec-input.py: line 1: '

I really don't know what i can do to fix it.
I hope you can help me.

c4sti3l

CECTester name on device

This script is amazing and still works great on the most recent version of Retropie.

I know this is barely an issue, but I was wondering if you knew of some way of changing the displayed OSD name from CECTester to something else.

I've found the command in cec-utils to change the name, I've set it to change the name to "Retropie" but it's only temporary (ie per command).

echo "tx 10 47 52 65 74 72 6f 70 69 65" | cec-client -s -d 1

Could we have this run in the script somehow?

Online some people say the easiest way is rebuilding cec-utils, but that doesn't seem feasible for everyone.

Can't get CEC to work

Hi,

i've tried your script on retropie 4.2, but it doesn't work. maybe i misunderstood something here https://github.com/dillbyrne/es-cec-input. i can control retropie with my logitech controller and the keyboard. i've only mapped the cursors, enter and space to select and start and the buttons (key a to button a and so on).

the Dependencies are installed, the udev rule exists. the script is downloaded to the userdir and its executable. i connect to the pi with ssh and start the script. nothing happens, the cursor jumps to the next line, there is no new prompt. looks like it waiting for something :-) when i press a button on the tv remote nothing happens. there is no reaction on retropie or on the terminal window with the ssh connection. no error.

is there something wrong the way i set up the keyboard?

Problems testing the script

Hello, guys!

When testing the script, I've stumbled upon the following output:

Traceback (most recent call last):
File "./es-cec-input.py", line 224, in
main()
File "./es-cec-input.py", line 183, in main
device = register_device(keylist)
File "./es-cec-input.py", line 129, in register_device
return uinput.Device(keylist)
File "/usr/lib/python2.7/dist-packages/uinput/init.py", line 175, in init
self.__uinput_fd = _libsuinput.suinput_open()
File "/usr/lib/python2.7/dist-packages/uinput/init.py", line 68, in _open_error_handler
raise OSError(code, "%s. Perhaps load the uinput kernel module first?" % msg)
OSError: [Errno 2] Failed to open the uinput device: No such file or directory. Perhaps load the uinput kernel module first?

I've no idea what to do. Do you have any pointers?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.