[Deprecated} Using the Flirc USB for remote control with mOde 5.4+ - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: FAQ and Guides (https://moodeaudio.org/forum/forumdisplay.php?fid=9) +--- Thread: [Deprecated} Using the Flirc USB for remote control with mOde 5.4+ (/showthread.php?tid=1529) |
[Deprecated} Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 07-12-2019 [Update 20200928: The addition of triggerhappy in moOde 6.4.2 has made this Python approach unnecessary. See instead Using FLIRC and other USB input devices for remote control.] [For the time being this is an on-going exploration. It will be converted to a proper HowTo when some odds-n-ends have been taken care of. This note assumes you are moderately Linux literate.] The Flirc USB is an IR-to-USB adapter which "allows you to pair any remote control with your computer or media center. Just walk through our super simple cross platform pairing application, and you're done. Use your previously paired remote with no additional software on any machine with flirc" [quoting from the flirc.tv website]. Well, I didn't exactly find it super simple---there were some interesting bumps in the road---but I'm well along my way to a solution which allows me to control a number of moOde's playback functions from an IR-remote I had on hand (an older-model Roku IR-controller, as it happens, with 12 buttons). I've implemented the usual play/pause, previous/next track, volume up/down, mute/unmute, load default playlist, load favorites playlist functions, and still have four buttons left over for functions I haven't thought about yet. My approach differs from @didier31's FLIRC-USB for remote control in that I'm running a headless moOde installation without local display and wanted to avoid adding X-stuff I knew I didn't need. I chose to take advantage of a useful Python module instead. Candidly, I took this approach because I wanted to see if I could make it work and not because I thought there was anything wrong with his prior work. Courses for horses, as they say. There's nothing special about my particular IR-remote and nothing special about the specific functions I chose to implement. The Flirc presents to the operating system as a USB-keyboard input device. This makes life pretty simple---mostly. Summary of steps:
Some Details: Nope, I'm not going to turn this into a travelogue of how I got from point A to point B by meandering through the forest. I'll put the gory details somewhere, maybe a personal blog, for those who care. But I have to point out one detail. The Flirc documentation and software implies you can mix-and-match mimicking standard keyboard keys (like a-z), which they colorfully call "valid commands", and media-control keys (like play/pause). Well, yeah, you can but this turns out to involve two different USB endpoints, one for media-control and one for keyboard. At this stage of the game I wanted to deal with only one endpoint, and there weren't enough media-control codes available from Flirc (or at least I could find no way to get to them) for my needs, so I programmed all my buttons to emit keyboard codes (KEY_A, KEY_B, KEY_C, etc.), as you'll see in the script below. No one but the script sees the actual values so it doesn't matter unless you intend to move the Flirc back and forth between moOde and some other computer or media control center which expects to receive actual media-control commands as defined in the USB spec. The script itself is an anticlimax: Code: pi@moode54b2:~ $ more Flirc-moode.py Easy peasy. As you can see, this is mostly a simple case statement, except Python doesn't have a case statement! There's alternatives to the cascading if/elif construction but they're too razzle-dazzle for me, at least at this stage. The ordering of the tests got scrambled because of my reworking from media-control keycodes. It doesn't matter programmatically but it looks odd and will get fixed before the HowTo appears. The script loops endlessly until you kill it explicitly, you unplug the Flirc, or you reboot moOde. So, to try it out, you first need to program your Flirc on another host to generate the keycodes you want with the IR-remote you have (see flirc.tv for software and docs). If you choose a different scheme from mine you'll need to do your homework on the keycodes actually emitted (hint: they're not in the Flirc docs). For moOde, you need Raspbian Buster for its up-to-date Python3 and evdev module. This means Tim's moOde 5.4b2 soon-to-be moOde 6. Install evdev Code: sudo apt-get install python3-evdev Plug in the Flirc on your moOde player. Copy the script to somewhere convenient like pi's home directory, calling it what you want; change the key values to match your Flirc configration; and make the script executable (chmod +x) for convenience. Since I don't yet have a systemd/udev solution, you'll have to start the script manually or add it to moOde's startup activity (not recommended but if you never remove the Flirc this would work). For mine, this means: Code: ./Flirc-moode.py (where the script runs in the terminal in the first instance and persists in the background in the second) Start pressing buttons and watch moOde responds. Note that you'll also start seeing the output from mpc commands since you've invoked the script from the command line. That'll go away with systemd/udev. You can play with redirecting output to the bit bucket if desired. Final thought: Almost exactly the same script works with my Satechi Bluetooth Multi-Media Remote. Unfortunately, the systemd/udev work is harder here because of the intermediary Bluetooth controller and because the Satechi goes to sleep after a period of inactivity. More to come. Regards, Kent RE: Using the Flirc USB for remote control with mOde 5.4+ - DRONE7 - 12-15-2019 Hi Kent, I thought to give your How-to a try with my Flirc (original) usb device. Pi 3 running MoOde 6.4, Kali and Piano Dac. Errors when running ./Flirc-moode.py Code: ./Flirc-moode.py Code: #!/usr/bin/python3 Code: $ lsusb Anything jump out there ? Cheers, BoB RE: Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 12-15-2019 @DRONE7 Hi, Bob. Thinking this project was "done and dusted" I moved on to try some other types of remotes. ATM I've got an OSMC RF remote on my desk I want to poke at. I'll need to revisit what I did with the FLIRC. IIRC I did a little detective work with Python to see how it was enumerated in the /dev tree and then just assumed it would always be the same. Maybe this assumption falls down with an "original" FLIRC (if that is different from mine) or with other input devices also connected. What else do you have connected to your RPi? Regards, Kent RE: Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 12-15-2019 (12-15-2019, 02:33 PM)TheOldPresbyope Wrote: @DRONE7 Done and dusted? I see some promises of more work in my orginal post. Some shiny new thing must have caught my eye back in July and I was off in another direction! Anyway, our two FLIRCs have different USB ids: For mine it's "20a0:0006" and for yours it's "20a0:0001". What do you see in /dev/input/by-id? I just spun up a fresh copy of moOde6.4.0 on an rPi3B+ and got Code: pi@moode:~ $ lsusb I'm not sure it will help but you might also post the verbose lsusb output. Here's the beginning of the output for my particular device id Code: pi@moode:~ $ sudo lsusb -v -d 20a0:0006 Regards, Kent RE: Using the Flirc USB for remote control with mOde 5.4+ - DRONE7 - 12-15-2019 Rpi3-Kali-Piano Dac... nothing else connected. Code: $ lsusb Code: ls -l /dev/input/by-id Code: $ sudo lsusb -v -d 20a0:0001 would it be as simple as changing usb-flirc.tv_flirc-event-if01 to usb-flirc.tv_flirc-event-if00 in the appropriate file..? RE: Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 12-15-2019 Interesting. Yup. In Flirc-moode.py, try changing Code: # the following endpoint tracks media keys: to Code: # the following endpoint tracks media keys: Note I was using only the "valid command" keys, hence the script is using the kbd endpoint. Regards, Kent RE: Using the Flirc USB for remote control with mOde 5.4+ - DRONE7 - 12-15-2019 Ok now I have... Code: $ ls -l /dev/input/by-id Code: $ ./Flirc-moode.py I'm now off to complete the building of a 'submarine' engine for a coffin.... so will check back tonight. Cheers, Bob. RE: Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 12-15-2019 @DRONE7 Sorry, there's no '-if00-' in the kbd endpoint. RE: Using the Flirc USB for remote control with mOde 5.4+ - DRONE7 - 12-15-2019 (12-15-2019, 06:45 PM)TheOldPresbyope Wrote: @DRONE7Just had a break waiting for glue and paint to dry....and Yes, removed '-if00-' and that got the Flirc V1 active and I'm getting output for some buttons. Progress ! Next break I will redo my mpc configs in .. Code: Flirc-moode.py Thanks !! RE: Using the Flirc USB for remote control with mOde 5.4+ - TheOldPresbyope - 12-15-2019 @DRONE7 Glad to hear you're making progress. I'm trying to understand USB better. ATM I'm trying to understand how names like "usb-flirc.tv_flirc-event-kbd" get generated from the low-level USB-descriptor information I see. I shouldn't have to cut-n-paste it into my script. Haven't a clue yet but maybe I just haven't read enough background material. This will yield somewhat redundant information, but I'd appreciate you at some point sending me the output from Code: sudo cat /sys/kernel/debug/usb/devices Regards, Kent |