[mythtv-users] Lirc commands in a shell script

Hika van den Hoven hikavdh at gmail.com
Tue Sep 30 15:53:02 UTC 2014


Hoi Hika,

Tuesday, September 30, 2014, 1:38:04 PM, you wrote:

> Hoi Stephen,

> Tuesday, September 30, 2014, 3:48:50 AM, you wrote:

>> On Mon, 29 Sep 2014 21:01:46 +0200, you wrote:

>>>Hoi Hika,
>>>
>>>Sunday, September 28, 2014, 11:48:46 PM, you wrote:
>>>
>>>> Hoi Alistair,
>>>
>>>> Sunday, September 28, 2014, 11:23:48 PM, you wrote:
>>>
>>>>> On Mon, Sep 29, 2014 at 2:14 AM, Hika van den Hoven <hikavdh at gmail.com> wrote:
>>>>>> Hoi Stephen,
>>>>>>
>>>>>> Sunday, September 28, 2014, 4:51:18 PM, you wrote:
>>>>>>
>>>>>>> On Sun, 28 Sep 2014 15:50:07 +0200, you wrote:
>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> Hoi Stephen,
>>>>>>>>
>>>>>>>>> Sunday, September 28, 2014, 3:28:30 PM, you wrote:
>>>>>>>>
>>>>>>>>>> On Mon, 29 Sep 2014 02:21:21 +1300, you wrote:
>>>>>>>>
>>>>>>>>>>>On Sun, 28 Sep 2014 13:37:09 +0200, you wrote:
>>>>>>>>>>>
>>>>>>>>>>>>Hoi All ,
>>>>>>>>>>>>
>>>>>>>>>>>> I have Radio integrated in Myth with some adaptations as in the wiki.
>>>>>>>>>>>> The radio command (ivtv-radio and aplay) itself runs as an
>>>>>>>>>>>> independent service and I can select stations (with iradio, which can
>>>>>>>>>>>> set the station on the screen or v4l2-ctl) either through a Mythmenu
>>>>>>>>>>>> or through a shellscript. Also Volume (with amixer) I can control
>>>>>>>>>>>> through that script.
>>>>>>>>>>>> Through my remote I can turn it on and off, by starting/stopping the
>>>>>>>>>>>> service. I would like to also be able to select stations and adjust
>>>>>>>>>>>> volume through the remote. That way I do not need to turn on the
>>>>>>>>>>>> screen. As I have seen suggested, it would be possible to receive
>>>>>>>>>>>> Lirc commands in a shellscript, as long as of cause it's on the
>>>>>>>>>>>> foreground. Does anybody know how to do that?
>>>>>>>>>>>
>>>>>>>>>>>Take a look at irexec - that runs things when triggered by a remote
>>>>>>>>>>>button.  It could be used to send signals to your radio service.  I
>>>>>>>>>>>have some test irexec setup in the MCE remote config I posted on my
>>>>>>>>>>>web server a couple of days ago:
>>>>>>>>>>>
>>>>>>>>>>>   http://www.jsw.gen.nz/mythtv/mythbuntu-devinput-lirc.bz2
>>>>>>>>>>>
>>>>>>>>>>>Look at the end of the "mythtv" file that goes in /home/<your
>>>>>>>>>>>mythfrontend user>/.lirc.  You can make an entire file of irexec setup
>>>>>>>>>>>and add it to the /home/<your mythfrontend user>/.lircrc file to be
>>>>>>>>>>>included in the lirc setup.  Whenever irexec is running, it will get
>>>>>>>>>>>those commands.
>>>>>>>>
>>>>>>>>> Do you mean that I should in .lircrc set prog = irexec for the ones I
>>>>>>>>> want to use in my script? I now run irexec for it is by default
>>>>>>>>> present in the service script, but have all mythtv keys marked with
>>>>>>>>> prog = mythtv. Then how do I catch them in the script? I guess I put a
>>>>>>>>> while true; do loop around that to trigger when it receives a valid
>>>>>>>>> command.
>>>>>>
>>>>>>> You can put script directly in the .lircrc entries for irexec, on the
>>>>>>> config line, or you can call another program or an external script.
>>>>>>> That code would need to somehow send signals to your radio service.
>>>>>>
>>>>>>> If you have entries in your .lircrc for different programs for the
>>>>>>> same key, I am not sure if they are all run or only the first one that
>>>>>>> is met is run.  You would need to check the lirc documentation.
>>>>>>
>>>>>>>>Or do they come in as regular keystrokes, so I can catch it with read.
>>>>>>>>But then I need a following <Enter>.
>>>>>>
>>>>>>> No, the incoming keycodes from lirc are not passed on directly.  The
>>>>>>> .lircrc entry matches a keycode from /usr/include/linux/input.h, and
>>>>>>> for an ordinary program then sends out one or more characters (not
>>>>>>> keycodes) to that program, as specified on the config line.  For
>>>>>>> irexec, the characters it receives from the config line it takes as
>>>>>>> some script code it must execute.  Mythfrontend interprets the
>>>>>>> characters according to its jumppoints and keybindings database tables
>>>>>>> and where it is in its screens (if it is in an alphanumeric entry
>>>>>>> mode, for example).
>>>>>>
>>>>>>>>>> I should add that when I run mplayer from mythfrontend for a video
>>>>>>>>>> file that mythfrontend can not play, only mplayer gets the remote
>>>>>>>>>> buttons, not the underlying mythfrontend.  I do not know how that
>>>>>>>>>> works, as if I run irexec in parallel with mythfronted, they both see
>>>>>>>>>> the remote buttons.
>>>>>>>>
>>>>>>>>> I guess that is because then mythfrontend is not the front window.
>>>>>>>>
>>>>>>>>>> Another alternative for changing radio stations is to add them to
>>>>>>>>>> MythTV as channels and use a channel change script to send the change
>>>>>>>>>> station commands to your radio service.  I have that working for my FM
>>>>>>>>>> radio scripts I use with my mothers PVR-150 FM tuner.
>>>>>>>>
>>>>>>>>> If looked at that some time ago, but couldn't get that working. Also
>>>>>>>>> then I probably need my screen on to see what happens.
>>>>>>
>>>>>>> In my case, the FM frequency for the PVR-150 tuner is controlled via
>>>>>>> the ivtv-radio command, so it is easy enough to get a channel change
>>>>>>> script to issue the appropriate command based on the freqid value from
>>>>>>> the channel table entry.  When I checked my code just now, I found I
>>>>>>> am in fact doing that from a start recording event script, not a
>>>>>>> channel change script.  I do not think the screen would need to be on
>>>>>>> for that to work.  You would have to set up a key on the remote to go
>>>>>>> to LiveTV mode (a jump table entry that works from everywhere), and
>>>>>>> then you would just key in the channel number once in LiveTV.  I have
>>>>>>> the radio stations as channel numbers 2001, 2002 and up to keep them
>>>>>>> out of the way of any new TV channels.
>>>>>>
>>>>>>> I have my radio scripts on my web server if you want to have a look at
>>>>>>> them:
>>>>>>
>>>>>>>   http://www.jsw.gen.nz/mythtv/event-start-recording.sh
>>>>>>>   http://www.jsw.gen.nz/mythtv/event-finished-recording.sh
>>>>>>
>>>>>>> I am not sure if what I am doing works for LiveTV though - I only use
>>>>>>> it for recording.  I know I have had problems with playing recordings
>>>>>>> while they are still recording, but I do not think I have ever tried
>>>>>>> with LiveTV.
>>>>>>> _______________________________________________
>>>>>>
>>>>>> Thanks I'll look at your scripts. One suggestion though. Ones you have
>>>>>> ivtv-radio with aplay running you better change channels through
>>>>>> v4l2-ctl ( v4l2-ctl --device=</dev/radio?> --set-freq=<frequency> )
>>>>>> since ivtv-radio needs to restart when you retune or if you daemonice
>>>>>> then you get a new instance every time you run ivtv-radio.
>>>>>> iradio is a wraparound ivtv-radio that can put tekst on screen through
>>>>>> xosd and has some lirc support. Although I didn't really investigate
>>>>>> the latter. Its documentation is scarce, mostly only that it exists.
>>>>>>
>>>>>> Also when again looking at irexec I found that the lirc package also
>>>>>> contains irxevent which does translate to the actual key. I got it to
>>>>>> place a '0' in a xterm. Now I have to test further, if I can get it to
>>>>>> send or include <enter>. Else I can not catch it with read.
>>>
>>>>> If you're familiar with python you could try receiving the lirc events
>>>>> directly using the python-lirc package
>>>>> (https://pypi.python.org/pypi/python-lirc/1.1), which would avoid the
>>>>> problems of making sure the write xterm receives the events, line
>>>>> ends, etc.
>>>
>>>>> Disclaimer: I've never used this package, so don't know how well it works.
>>>
>>>>> Cheers,
>>>>> Alistair
>>>>> _______________________________________________
>>>
>>>> Sounds like a great option, except for I never worked with python.
>>>> Maybe a nice project to get to learn python. Thanks for the hint.
>>>
>>>I found a way that will work although I have to do some fine tuning.
>>>With ircat also part of lirc. This sends the received signal with a
>>>linefeed to stdout. Only I have to work on the repeat, for now I
>>>receive every button two or more times. Also I have to think of a
>>>construct to choose two button channels.
>>>
>>>In ~/.lircrc you add the buttons you want to use like:
>>>   begin
>>>       prog = mythradio
>>>       button = KEY_0
>>>       config = 0
>>>   end
>>>
>>>The prog name is one you choose yourself. Then in a shell script you
>>>make a construct like:
>>>
>>>   #!/bin/bash
>>>   declare LircCmd
>>>
>>>   function a_function_to_call {
>>>      actions_to_take
>>>   }
>>>
>>>   while read LircCmd; do
>>>      case $LircCmd in
>>>                [0-9])
>>>                a_function_to_call
>>>                ;;
>>>                ...
>>>      esac
>>>   done | ircat mythradio
>>>
>>>This script stays running untill you press ctrl-C or 'break' the loop
>>>
>>>I found that even when myth is in the background it still is receiving
>>>its lirc events, so I decided to use a different remote. I have an old
>>>one from a cd player, that has just enough buttons.
>>>
>>>If I have this all working I think I add it to the wiki as an
>>>alternative way to play radio. This script is only for changing
>>>stations or volume. Since ivtv-radio is running independent as a
>>>service you still can through other ways schedule recordings.

>> Are you using a remote with the devinput (kernel) driver?  If so, then
>> the most likely cause for double keystrokes is that the input directly
>> from the remote via devinput is getting through to your script as well
>> as the lirc output.  Try just running a terminal without lircd running
>> and use the remote.  Do you see characters getting through to the
>> terminal?  Those are the direct keystrokes of the remote working like
>> a keyboard via devinput.  They need to be suppressed when using lirc
>> or they get through as well, and often they are the same or similar to
>> what you have programmed lirc to output and you get double keystrokes.
>> I am not entirely sure yet about how they are suppressed, but check
>> your /etc/lirc/hardware.conf file and try setting the
>> DISABLE_KERNEL_SUPPORT option to "true" if it is not already.
>> _______________________________________________

> No, I have a homebrew serial receiver. I have noticed that ircat gives
> both a signal when you press and when you release. Plus, if you press
> longer, extra repeats in between. I also have to look further into the
> pipeing for this way doesn't work. I have to create an intermediate
> that receives the signals and then can be read out. Complex matter, so
> some more studying to do.

OK, I have the basics working. I pipe the output from ircat to a fifo
file in /tmp (this is a tmpfs, so as fast as memory) and then pushing
it to the background (the '&' at the end of that line). The extra
advantage is that I can just start it at boot and push it to the
background. Then I can manipulate either through the remote or by
placing a command in the fifo file, through whatever means.
I avoid the double signal on press and release by ignoring a signal
that is equal to the previous. And then clearing the previous so I can
press again. I have repeat set to 0 in .lircrc. I now suddenly realize
that this means that if I push a command through the fifo file, I
might have to do it twice sometimes, if the same command needs to
repeat.
I now also think I could handle all kinds of remote command this way.
Like for instance suspend.


#!/bin/bash
declare LircCmd
declare PressTekst=""
declare FiFo="/tmp/fiforadio"
declare tmpStr=`ps | grep ircat`
tmpStr=`echo $tmpStr | cut -f1 -d' '`
[ "$tmpStr" != "" ] && kill $tmpStr
[ -e "$FiFo" ] && rm "$FiFo"
mkfifo "$FiFo"
ircat mythradio >"$FiFo" &

while read LircCmd; do
        if [ "$LircCmd" == "$PressTekst" ]; then
                PressTekst=""
        else
                PressTekst="$LircCmd"
                case $LircCmd in
                        [0-9])
                        echo z$LircCmd
                        
                        ;;
                        "Ch+")
                        echo z$LircCmd
                        
                        ;;
                        "Ch-")
                        echo z$LircCmd
                        
                        ;;
                        "mute")
                        echo z$LircCmd
                        
                        ;;
                        "V+")
                        echo z$LircCmd
                        
                        ;;
                        "V-")
                        echo z$LircCmd
                        
                        ;;
                        "quit")
                        echo z$LircCmd
                        break
                        ;;
                esac
        fi
done < "$FiFo"
tmpStr=`ps | grep ircat`
tmpStr=`echo $tmpStr | cut -f1 -d' '`
[ "$tmpStr" != "" ] && kill $tmpStr
[ -e "$FiFo" ] && rm "$FiFo"



Tot mails,
  Hika                            mailto:hikavdh at gmail.com

"Zonder hoop kun je niet leven
Zonder leven is er geen hoop
Het eeuwige dilemma
Zeker als je hoop moet vernietigen om te kunnen overleven!"

De lerende Mens



More information about the mythtv-users mailing list