Skip to content

Instantly share code, notes, and snippets.

@glitterkitty
Last active January 5, 2018 10:35
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 glitterkitty/9554d88aff011e73b02ccd67b944f7c9 to your computer and use it in GitHub Desktop.
Save glitterkitty/9554d88aff011e73b02ccd67b944f7c9 to your computer and use it in GitHub Desktop.
wip: my way to a working x10 rf-remote in kodi on odroid-c2
objective:
-----------
a. linux shall get button-presses from my x10 rf-remote
b. button-presses shall be used to navigate kodi, trigger actions
like 'Show Favourites' and the like
c. additionally, a deamon listens to the remote to execute commands
like switching lights on/off wt pilight switching relais wt GPIO a.t.l.
d. all is setup/run at start: poweron the odroid and lay back, doing
ev'rything wt the remote
I got:
-------
odroid c2
X10 RF Remote (Pollin Remote) set to channel 2 (see below)
Ubuntu Mate 16.04.3
kodi 17.6
the long journey of a rf-buttonpress in a nutshell - my findings (correct me if I'm wrong, please!):
------------------------------------------------------------------------------------------------------
on the remote, a button is pressed !
--> usb-receiver get's it by rf
--> ati_remote get's it,compares it wt the channel-mask module-parameter and let's it pass or not
--> ati remote passes it as an event (scancode) to the resp. /dev/input/event* devicenode
--> /dev/input looks up the scancode of the press and translates it by means of the rc_keytable
--> inputlirc get's it as a key_event, as inputlirc is listening on that eventdevice node
--> inputlirc publishes it via /var/run/lirc/lircd socket to all lirc-clients on the system
--> lirc-client irexec get it and performs an action defined in ~/.lircrc
--> lirc-client irw (when running) get's it and dumps it to the console
--> lirc-client kodi gets it and maps it to a kodi-key via Lircmap.xml
--> the kodi-key is looked-up in ~/.kodi/userdata/keymaps/*.xml (any) and an kodi-action is triggered
--> kodi performs the triggered action, like 'select' or 'activatewindow(favourites)'
--> evry'body and his dog is happy!
note:
i know I'm wrong at one point, since my up/down/left/rite presses
seem to get caught by the system elsewhere, resulting in double action in kodi :(
oh my...
tons of thanx to:
-----------------
http://nucblog.net/2014/01/mapping-the-buttons-on-the-remote-control/
for providing the missing link for setting up <remote device="/dev/input/event4"> in Lircmap.xml
let's go !
lirc
-----
install lirc for getting irexec and irw
use apt install on the shell and in post-install, leave lirc unconfigured.
sudo dpkg-reconfigure lirc runs the post-install again
disable lirc service:
$ sudo systemctl disable lirc
kernel module ati_remote:
---------------------------
create new file:
$ nano /etc/modprobe.d/ati_remote.conf
options ati_remote channel_mask=131067
options ati_remote debug=1
how to determine your channel_mask for ati_remote.conf:
$ echo "65536 + 65535 - 2 ^ <channelnum>" | bc
-> options ati_remote channel_mask=131067 for channel 2
note: some sources say 'echo "65535 - 2 ^ <channelnum>" | bc', which worked for me, too
-> options ati_remote channel_mask=65531
on the remote:
# press world-btn *5sec
# number of led blinking is current channel_mask
# - to cancel: press world
# - to set channel: enter number 1-16
# - press world
# number of led blinking is now the new channel-no.
$ rmmod ati_remote
$ modprobe ati_remote
$ tail -f /var/log/kern.log
Jan 2 12:47:10 odroid64 kernel: [ 6472.396963] ati_remote 1-1.4:1.0: channel 0x01; key data 22, scancode 22
Jan 2 12:47:10 odroid64 kernel: [ 6472.428972] ati_remote 1-1.4:1.0: channel 0x01; key data 22, scancode 22
Jan 2 12:47:10 odroid64 kernel: [ 6472.468988] ati_remote 1-1.4:1.0: channel 0x01; key data 22, scancode 22
...
if the channel_mask is wrong, u get sth like:
Jan 2 12:47:55 odroid64 kernel: [ 6517.248924] ati_remote 1-1.4:1.0: Masked input from channel 0x00: data f7,22, mask= 0xfffb
Jan 2 12:47:55 odroid64 kernel: [ 6517.296932] ati_remote 1-1.4:1.0: Masked input from channel 0x00: data f7,22, mask= 0xfffb
Jan 2 12:47:55 odroid64 kernel: [ 6517.496988] ati_remote 1-1.4:1.0: Masked input from channel 0x00: data 77,a2, mask= 0xfffb
inputlircd
-----------
$ cat /proc/bus/input/devices
$ man inputlircd
$ sudo nano /etc/default/inputlirc
# for selecting device, i wanted to use the -n feature, but
# i could NOT set this up in /etc/default/inputlirc, coz of qouting-stuff
# so I took EVENT="/dev/input/event4" and hope this does'nt change that often :(
EVENTS="/dev/input/event4"
# this is for for getting all keys,
OPTIONS="-m 0"
ir-keytable
------------
this is for remapping the keys send by the remote to /dev/input/event*. I did this,
because some buttons on the remote caused ubuntu to react, especialyy KEY_POWER!
my keymap is attached
the error message about 'could not change protocols ... /proc/sys/rc/...' can be IGNORED
$ ir-keytable -c -w /etc/rc_keymaps/x10_keymap
$ ir-keytable -r
# table medion_x10_or2x, type: rc-6, other
0x02 KEY_EXIT #war POWER, jetzt Shutdown Menü
0x16 KEY_L #war TEXt,jetzt: next Subtitle
0x09 KEY_VOLUMEUP
0x08 KEY_VOLUMEDOWN
0x00 KEY_MUTE
0x0b KEY_CHANNELUP
0x0c KEY_CHANNELDOWN
...
$ ir-keytable -t :
Testing events. Please, press CTRL-C to abort.
1514893362.632238: event type EV_MSC(0x04): scancode = 0x22
1514893362.632238: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
1514893362.632238: event type EV_SYN(0x00).
1514893362.632271: event type EV_KEY(0x01) key_up: KEY_DOWN(0x006c)
1514893362.632271: event type EV_SYN(0x00).
1514893362.936306: event type EV_MSC(0x04): scancode = 0x22
1514893362.936306: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
1514893362.936306: event type EV_SYN(0x00).
...
irw
-----
running irw should now yield:
$ irw
171 0 KEY_TITLE /dev/input/event4
172 0 KEY_SUBTITLE /dev/input/event4
173 0 KEY_ANGLE /dev/input/event4
170 0 KEY_LANGUAGE /dev/input/event4
...
kodi:
------
let's get to the nitty-gritty :)
first, set logging in kodi to enabled:
SystemSettings->Expert (from Basic)
SystemSettings->Logging: Enable debug logging
$ tail -f ~/.kodi/temp/kodi.log
...
15:19:06.144 T:548218773504 DEBUG: LIRC: Update - NEW at 153125:179 0 KEY_TV /dev/input/event4 (KEY_TV)
so, kodi is getting the KEY_* events from inputlirc, and you can now map them to
kodi-ir-buttons in ~/.kodi/userdata/Lircmap.xml. I attached my WIP Lircmap.xml.
Only VALID names will be processed by kodi. A look into TranslateString.cpp
(https://github.com/xbmc/xbmc/blob/master/xbmc/input/IRTranslator.cpp) reveals,
which kodi-ir-button names are valid in Lircmap.xml. I've NEVER seen a doc or
list or summary on this NOWHERE!, so I will attach a summary here.
quit kodi
$ nano ~/.kodi/userdata/Lircmap.xml
<?xml version="1.0" encoding="UTF-8"?>
<lircmap>
<remote device="/dev/input/event4">
<zero>BTN_MISC</zero>
<one>BTN_1</one>
<two>BTN_2</two>
...
<up>BTN_TRIGGER_HAPPY1</up>
<down>BTN_TRIGGER_HAPPY2</down>
<left>BTN_TRIGGER_HAPPY3</left>
<right>BTN_TRIGGER_HAPPY4</right>
<select>BTN_TRIGGER_HAPPY5</select>
...
</remote>
</lircmap>
explanation:
<remote device="/dev/input/event4"> must match your device, i.e. the output of
$ irw
171 0 KEY_TITLE /dev/input/event4 <- this one
Kodi ir-button name in this line is 'zero', a valid name taken from IRTranslator.cpp
BTN_MISC is what irw spits out when you press the button on the remote, this is
defined in /etc/rc_keymaps/x10_keymap
most ir-buttons will then trigger predefined actions in kodi, which are defined in system-
and/or user-defined keymaps. system-defined keymaps are stored in /usr/share/kodi/system/keymaps/,
user-defined keymaps are stored in ~/.kodi/userdata/keymaps/
YMMV
you may wonder, why I defined such strange keys in x10_keymap. well, it happened, that kodi
triggerd actions even I had not defined a mapping from the key to a kodi-ir-button in Lircmap.xml.
so to circumvent this, I took the most unfamilliar keys from input-event-codes.h (https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h).
by using the addon Keymap Editor, you can select, what action a ir-button in kodi should trigger.
Keymap Editor generates 'gen.xml' in ~/.kodi/userdata/keymaps, which looks like this:
<?xml version="1.0"?>
<keymap>
<global>
<keyboard>
<key id="22">select</key>
<key id="250">activatewindow(favourites)</key>
...
</keyboard>
</global>
</keymap>
this way, you should now be able to have kodi recognize button-presses, translate
them into 'kodi ir-buttons' and setup 'kodi-actions' to be triggered then.
irexec:
--------
optionally (I do) irexec can now be used
$ nano ~/.lircrc
begin
prog = irexec
button = KEY_LANGUAGE
config = echo "Parlez-vous francais? Sprecken si teutsch?"
end
begin
prog = irexec
button = KEY_PVR
config = echo kodi && aplay /home/aspasia/Documents/sounds/kodi_start.wav && kodi &
mode = kodi
end
test this wt:
$ irexec # and press KEY_LANGUAGE
Parlez-vous francais? Sprecken si teutsch?
...
wip - autostart all needed parts on boot:
------------------------------------------
well, i've given up on creating a service for that with systemd. too much hassle
also, this way, I can close the xterm, make modifications to .lircrc or x10_keymap and
restart it by dbl-clicking the starter and have debug output on the console
I let the system autologon my user at start and run 'start_remotecontrol.sh'.
create a 'launcher' on desktop:
name: RemoteControl
command: xterm -geometry 64x32+840+300 -bg black -fg grey -e start_remotecontrol.sh
autostart it on logon:
system->preferences->personal-Startup applications -> add
name: RemoteControl
command: <browse for the launcher>
click 'add'
create start_remotecontrol.sh:
$ cd ~ ; mkdir bin ; cd bin
$ nano start_remotecontrol.sh
#!/bin/bash
echo "Installing Keymap..."
ir-keytable -c -w /etc/rc_keymaps/x10_new
echo "Starting irexec..."
killall irexec
irexec --loglevel=4 &
sleep 1s
tail -f /home/aspasia/.cache/irexec.log
note on irexec --loglevel=4 &:
-------------------------------
your irexec (v0.9.0) might not have that parameter available.
get the sources for lirc v0.9.4.d and compile it, it's not that hard.
do !not! run 'make install', run
$ which irexec
to find the location of your irexec, make a backup, and copy tools/irexec to there, e.g.
$ sudo cp $(which irexec) $(which irexec).bak
$ sudo cp tools/irexec $(which irexec)
or
remove
--loglevel=4 &
sleep 1s
tail -f /home/aspasia/.cache/irexec.log
---------------------------------------------------
that's it so far - that was 2days+ - #$%#?!
i find, setting up lirc and such is and has always been a hard thing to do.
it's by far not the first time I did this, but it is Alway differen, and a
solution that formerly worked fine for me on a system (I lirced on win-/linux-x86
and on pi before) doesn't work on another (now the 'droid).
have phun!
btw:
If you wanna know if the 'droid can do
kodi well - no he doesn't. He does it
superbly: fast and snappy! I guess, I
won't miss the PI...
<?xml version="1.0" encoding="UTF-8"?>
<lircmap>
<remote device="/dev/input/event4">
<guide>KEY_FN_F1</guide>
<language>KEY_FN_F7</language>
<playlist>KEY_FN_F8</playlist>
<contentsmenu>KEY_FN_F9</contentsmenu>
<menu>KEY_FN_F9</menu>
<back>KEY_FN_F10</back>
<up>BTN_TRIGGER_HAPPY</up>
<down>BTN_TRIGGER_HAPPY2</down>
<left>BTN_TRIGGER_HAPPY3</left>
<right>BTN_TRIGGER_HAPPY4</right>
<select>BTN_TRIGGER_HAPPY5</select>
<rootmenu>KEY_FN_B</rootmenu>
<info>KEY_FN_F</info>
<zero>BTN_MISC</zero>
<one>BTN_1</one>
<two>BTN_2</two>
<three>BTN_3</three>
<four>BTN_4</four>
<five>BTN_5</five>
<six>BTN_6</six>
<seven>BTN_7</seven>
<eight>BTN_8</eight>
<nine>BTN_9</nine>
<star>KEY_FN_1</star>
<hash>KEY_FN_2</hash>
<display>KEY_DISPLAYTOGGLE</display>
<reverse>KEY_BRL_DOT1</reverse>
<pause>KEY_BRL_DOT2</pause>
<forward>KEY_BRL_DOT3</forward>
<play>KEY_BRL_DOT4</play>
<skipplus>KEY_BRL_DOT5</skipplus>
<skipminus>KEY_BRL_DOT6</skipminus>
<stop>KEY_BRL_DOT7</stop>
<record>KEY_BRL_DOT8</record>
<volumeplus>KEY_VOLUMEUP</volumeplus>
<volumeminus>KEY_VOLUMEDOWN</volumeminus>
<mute>KEY_MUTE</mute>
<channelplus>KEY_CHANNELUP</channelplus>
<channelminus>KEY_CHANNELDOWN</channelminus>
<pageplus>KEY_CHANNELUP</pageplus>
<pageminus>KEY_CHANNELDOWN</pageminus>
</remote>
</lircmap>
# table medion_x10, type: other
# power guide text
0x02 KEY_FN_ESC
0x31 KEY_FN_D
0x16 KEY_FN_E
# vol + channel
0x08 KEY_VOLUMEDOWN
0x09 KEY_VOLUMEUP
0x00 KEY_MUTE
0x0b KEY_CHANNELUP
0x0c KEY_CHANNELDOWN
# back info
0x20 KEY_FN_B
0x2f KEY_FN_F
# livetv rectv photo music dvd video
# audio angle title subtitle
0x1c KEY_FN_F1
0x18 KEY_FN_F2
0x05 KEY_FN_F3
0x06 KEY_FN_F4
0x04 KEY_FN_F5
0x2d KEY_FN_F6
0x32 KEY_FN_F7
0x34 KEY_FN_F8
0x35 KEY_FN_F9
0x33 KEY_FN_F10
# u/d/l/r/ok
0x1a BTN_TRIGGER_HAPPY1
0x22 BTN_TRIGGER_HAPPY2
0x1d BTN_TRIGGER_HAPPY3
0x1f BTN_TRIGGER_HAPPY4
0x1e BTN_TRIGGER_HAPPY5
# numpad star hash
0x0d BTN_1
0x0e BTN_2
0x0f BTN_3
0x10 BTN_4
0x11 BTN_5
0x12 BTN_6
0x13 BTN_7
0x14 BTN_8
0x15 BTN_9
0x17 BTN_0
0x37 KEY_FN_1
0x38 KEY_FN_2
# world
0x1b KEY_DISPLAYTOGGLE
# rew play ffwd ...
0x24 KEY_BRL_DOT1
0x25 KEY_BRL_DOT2
0x26 KEY_BRL_DOT3
0x29 KEY_BRL_DOT4
0x21 KEY_BRL_DOT5
0x23 KEY_BRL_DOT6
0x28 KEY_BRL_DOT7
0x27 KEY_BRL_DOT8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment