The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.34 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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


Messages In This Thread
Using FLIRC and other USB input devices for remote control - by TheOldPresbyope - 09-28-2020, 04:14 PM

Forum Jump: