Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide Using FLIRC and other USB input devices for remote control
#1
Introduction

Beginning with release 6.4.2, a software package named triggerhappy has been included in moOde to support the use of commonly available USB volume knobs. As a bonus, its inclusion also makes trivial using the FLIRC IR-to-USB adapter and other USB devices which enumerate as HID input devices. 

Quoting from the thd (triggerhappy daemon) man page

Quote:Triggerhappy is a hotkey daemon that operates on a system wide scale. It watches all configured input devices for key, switch or button events and can launch arbitrary commands specified by the administrator. 

This Guide is devoted to getting set up with the FLIRC adapter and an IR-remote media controller of your choice. The same setting-up process should apply to other USB input devices such as keyboards and the like.

Steps

Step 1. Enable the triggerhappy daemon.

By default, the daemon is disabled. If you haven’t already enabled it so you can use a USB volume knob then do the following. Go to the m>Configure>Audio config screen and scroll down to USB volume knob. Move the USB volume knob slider to ON and click SET.

You’re done.

Step 2. Plug the FLIRC into a USB port on your moOde player's RPi if you haven’t already done so.

Step 3. Determine the keycode mappings for your IR-remote media controller and FLIRC combination.

The FLIRC supports more than one pairing profile. I assume you have read your FLIRC documentation and made choices. All that matters in the following is that the FLIRC emit a keycode for each key you wish to use on your controller.

Log into the command line on your moOde player using moOde's built-in Web SSH terminal or using SSH from some other computer.

In the home directory, start the command 

Code:
thd --dump /dev/input/event* | tee keycodes.cap

While the command is running, press each of the keys you wish to use on the controller, one at a time, noting the order.  In response, you’ll see a succession of line pairs appear in the output. When done, type ^C to kill the running command and automatically save the output of this session in the file keycodes.cap. (This capture of the output to a file is solely for convenience. The "| tee keycodes.cap" portion of the command can be skipped.)

Here’s an example of the output for just the first key press and release on my controller

Code:
pi@moode:~ $ thd --dump /dev/input/event* | tee keycodes.cap
EV_KEY KEY_A 1 /dev/input/event1
# KEY_A 1 command
EV_KEY KEY_A 0 /dev/input/event1
# KEY_A 0 command
...
^C
 
We are interested in the information on the commented lines (which conveniently are formatted the way we’ll format the lines in our configuration file). 

Each line beginning with a “#” character reports the keycode emitted by the FLIRC, such as “KEY_A”, and the event code, “1” or “0”, which stand for key pressed and key released, respectively. Finally, the line ends with the string “command” as a placekeeper for the command we want to execute on the event.

Step 4. Decide on the programmatic moOde command you want to associate with each keycode. Some obvious candidates are

volume up:
  /var/www/vol.sh -up 5

volume down:
  /var/www/vol.sh -dn 5

mute/unmute:
  /var/www/vol.sh -mute

play/pause:
  /usr/bin/mpc toggle

play next:
  /usr/bin/mpc next

play previous:
  /usr/bin/mpc prev

add favorites playlist to the end of the queue:
  /usr/bin/mpc load Favorites

clear the queue and add the default playlist:
  /usr/bin/mpc clear; /usr/bin/mpc load “Default Playlist”

Note that capitalization matters; so does using quotes to avoid problems with the shell interpreting spaces in a name. Note also that I specify the full pathname for mpc out of an abundance of caution (old Unix habits die hard). A bare "mpc" will do here.

It is possible to get quite baroque but this isn’t a guide to all the ways one can abuse moOde/MPD commands Rolleyes

Step 4.  Use your favorite Linux text editor---nano, vi, or such---to create a triggerhappy configuration file for your FLIRC and controller. Make it easy on yourself and do this in the home directory. This task becomes marginally easier using the keycodes.cap file we created above.

Code:
grep ^# keycodes.cap | grep $'\x9'1 > flirc.conf

This preselects all the key-press events (code 1). All that remains is to remove the "#" character and substitute your command for the string "command".

As an example of the result of this step, here is the content of a trial flirc.conf for my FLIRC/Roku controller combo with a pairing profile of my own.

Code:
pi@moode:~ $ cat flirc.conf
KEY_A 1 /usr/bin/mpc clear; /usr/bin/mpc load Favorites
KEY_B 1 /usr/bin/mpc clear; /usr/bin/mpc load "Default Playlist"
KEY_C 1 /var/www/vol.sh -up 5
KEY_D 1 /usr/bin/mpc prev
KEY_G 1 /var/www/vol.sh -dn 5
KEY_E 1 /var/www/vol.sh -mute
KEY_F 1 /usr/bin/mpc next
KEY_L 1 /usr/bin/mpc toggle

Not shown here is that triggerhappy can detect if a key is held depressed so it is possible to create separate actions for a short press (code 1) and a long press (code 2).

Note that triggerhappy aggregates the actions for all the configuration files it finds. In some cases, triggerhappy's advanced modes and tags may be necessary to disambiguate an event. Consult the thd man page for details on modes and tags.

Step 5. Copy the flirc.conf to the proper triggerhappy directory (As suggested above, there can be many conf files present. For example, a media.conf file is already present in moOde to handle the USB volume knob.)

Code:
sudo cp flirc.conf /etc/triggerhappy/triggers.d/flirc.conf

Step 6. Restart the triggerhappy daemon so it can pick up the new configuration file. I usually do this by turning the daemon off and then on again on the Audio config page but one can also simply reboot.

Step 7. It’s time to start pushing buttons!

Debugging

Check the moOde log for signs the USB volume knob job didn't run. Check that the triggerhappy daemon process is running. Check the mpd log for telltale signs such as trying to load a nonexistent playlist (maybe because of a capitalization error or missing quotation marks).



Final remarks:

1. This Guide supercedes my previous guide.

2. By repeating steps 3-6 it should be possible to add more USB input devices to your stable.
Reply
#2
This worked well for me and I was able to set this up with my Logitech remote quite quickly. I thank you for that!

I am writing to ask if it would be possible to map a KEY command to the Moode UI Asterisk * button. I quite like the ability to load a random album and would like to add the ability to do so from my remote if possible.

I don't see that I can do this using the mpc <command> function like the other KEY mappings (first time looking at it so I could be wrong too..) so I am guessing the logic behind the Asterisk button is different or more involved.

Thoughts? Thanks again!!
Reply
#3
(10-22-2020, 08:50 PM)ahlbar75 Wrote: This worked well for me and I was able to set this up with my Logitech remote quite quickly.  I thank you for that!

I am writing to ask if it would be possible to map a KEY command to the Moode UI Asterisk * button.  I quite like the ability to load a random album and would like to add the ability to do so from my remote if possible.

I don't see that I can do this using the mpc <command> function like the other KEY mappings (first time looking at it so I could be wrong too..) so I am guessing the logic behind the Asterisk button is different or more involved.

Thoughts?  Thanks again!!

Glad to hear this has been working for you.

The random play capability is not a basic MPD function, so mpc doesn't include a command for it. 

Unfortunately, I don't use the random play capability and can't tell you off the top of my head how to invoke it in moOde from the command line. You'll have to ask @Tim Curtis.

Good luck.

Regards,
Kent
Reply
#4
A previous post at this link covers this.  http://moodeaudio.org/forum/showthread.p...bum+script

then read http://moodeaudio.org/forum/showthread.php?tid=2638
Reply
#5
It's really just a matter of demand for such a feature or a dev wanting to donate their time to implement it.
http://moodeaudio.org/forum/showthread.p...6#pid26396
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
Thanks all, I opened a separate thread:
http://moodeaudio.org/forum/showthread.php?tid=3100

sheridat suggested two threads detailing this could be done by installing and using mpdrandom. I have now mapped a button on my remote that selects a random album from my library and starts playing the first song.

Thanks again to all!
Reply
#7
One a freshly installed 6.7.1 if I say

thd –dump/dev/input/event* | tee keycodes.cap

I get

Error opening '–dump/dev/input/event*': No such file or directory

So I found out that there is a type in the first Code-Box, the command must be like in the second one:

thd --dump /dev/input/event* | tee keycodes.cap
Reply
#8
So I managed to activate Flirc on moOde and remote controlling my Pi is working. But the funny thing is: I have to press each button twice before it works. From the command line e. g. "mpc toggle" works perfectly well, but activating it from the remote needs two keystrokes. Anyone any idea?
Reply
#9
(Assume you have updated the Flirc Firmware to the latest ?)

Plug the flirc into a PC and open the Flirc app. There is a setting for adjusting the key response. Adjust and save then plug back into the Pi.
https://support.flirc.tv/hc/en-us/articl...ey-Presses

Otherwise there is an old posting from Jason on the Flirc forum indicating a problem with some remotes and a fix. Ymmv.
http://forum.flirc.tv/index.php?/topic/9...ls_19_menu
----------
bob
Reply
#10
This sounds like a interesting option to test.
Reply


Forum Jump: