Lirc for Creative LiveDrive
Foreword
I'm using my computer as main media center in my home. Most of music I listen and video I watch is played directly by my Linux media applications. Thanks to lirc package I can control my computer using remote control. It's a great thing especially for such a lazy person like me, I can do whatever I need with my computer not moving away from my couch. Lirc is offering support for wide range of infrared remote controls. I have Creative LiveDrive with RM-1500 remote control. Both devices were part of my Creative SoundBlaster Audigy 4 Pro sound card. KDE desktop environment has direct support for Lirc devices and thanks to this I'm able to remotely control any application that is using Linux system messaging bus DBus. What I especially love about remote control in Linux is that I'm not bound to some kind of default configuration I have to learn. I can setup my controls and choose applications I want to control by my self. Only my imagination and sky is the limit. Thats the main difference between Linux and other operating systems. You make Linux work as you like, not learn by heart how you should use your system.
I will try to share here my Lirc and remote control configuration that is coming from my main computer. Lirc is not the only remote control application available for Linux at the end you can find also short information about another applications I use to remote control my computer. Most of the provided here information should be applicable to any Linux distribution but some of the instruction are typical for distribution I use Gentoo Linux. If you have different remote control hardware you can still find some of the information provided here useful. I will start with kernel and system service configuration.
Kernel and system service configuration
My remote control is integrated with my sound card therefor I have to control it using sound card kernel module. To configure my kernel I had to enter kernel catalog and start menuconfig by running following commands in terminal:
cd /usr/src/linux make menuconfig
Below you will find the list of needed kernel modules for my lirc device.
Linux Kernel Configuration: Kernel modules configuration |
Loadable module support ---> [*] Module unloading Device Drivers ---> Input device support ---> [*] Event interface <M> Sound card support ---> <M> Advanced Linux Sound Architecture ---> [*] PCI sound devices ---> <M> Emu10k1 (SB Live!, Audigy, E-mu APS) |
As you can see the sound card support will be build as module. The module will be loaded by udev hardware allocation service and initialized during alsa sound system service start. After marking all necessary kernel modules I'm ready to recompile, install and use new kernel. I usually do it by running this commands in terminal:
cd /usr/src/linux make && make modules_install install
This is not over yet. To initialize remote control for Emu10k1 kernel module I had to pass additional parameter to kernel module. I did this by providing sound module configuration in /etc/modprobe.d/alsa.conf. Below you can find part of my alsa.conf file that is affecting Audigy 4 sound card configuration.
alias snd-card-0 snd-emu10k1 options snd-emu10k1 index=0 id=audigy4pro extin=0x3fcf extout=0x1fcf enable_ir=1 alias sound-slot-0 snd-emu10k1
The most important part is options line. Kernel module option enable_ir = 1 is enabling infrared red remote control for my sound card.
Now it's good time to reboot the machine with new kernel. After this the new kernel modules should be loaded and infrared remote control should be available. Unfortunately I found out this is not enough to make my Sound Blaster Audigy 4 Pro LiveDrive properly receive infrared signals coming from it's remote control. LiveDrive control LED wasn't lighting when I was pressing remote control buttons. After searching the Internet I found out that LiveDrive device need to be initialized with special command. The best way to do it is to write additional simple system service which will depend on alsa sound system service. I called this service audigy. Below you can see the service script which is making my remote control fully operational.
#!/sbin/runscript depend() { need alsasound } start() { ebegin "Initialising external I/O Hub" echo -e '\0360\0000\0040\0041\0141\0000\0000\0000\0177\0000\0367' > /dev/snd/midiC0D1 eend $? } stop() { ebegin "Nothing to Stop" eend $?
As you can see in this script my LiveDrive device is bound to device node /dev/snd/midiC0D1. The script itself is very basics it simply passes the initialization string using ASCI characters string in octal code. Now I can add this script to default run level to make it start on next system boot. To do it I need to run following command in terminal:
rc-update add audigy default
To make it start without the need of restarting my system I have to run following command in my terminal:
/etc/init.d/audigy start
After starting this service the LED on LiveDrive device started to light every time I pressed button on my remote control. Now we can move on to Lirc configuration.
Lirc Configuration
Before installing Lirc on Gentoo system you should provide a name of lirc devices in /etc/make.conf. This will make lirc install only components you need. In my system lirc configuration in /etc/make.conf looks like this:
LIRC_DEVICES="livedrive_midi"
To install lirc in Gentoo system you need to run this commands in terminal:
emerge -av sys-apps/lirc
Lirc installation, will provide system service which will let us start lirc daemon. Before starting this service we should configure it properly. First thing we need to do is to tell lirc service what type of device we want to use. We do it by appending LIRCD_OPTS options into /etc/conf.d/lircd file. Configuration for Audigy 4 Pro LiveDrive should look like this:
LIRCD_OPTS="-H livedrive_midi -d /dev/snd/midiC0D1"
Second thing we need to do is to provide a configuration file that will map core IR signals to our remote control buttons. On Lirc project page you will find a detailed instruction how to do it manually, but there is no need to. You should be able to easily find the configuration file for your remote control on Lirc page or somewhere in Internet. The configuration file should be saved as /etc/lirc/lircd.conf. Below you can see configuration for my devices.
############################################################## #RM-1500 For Audigy 4 Pro ############################################################## begin remote name Creative_RM-1500 bits 16 flags SPACE_ENC|CONST_LENGTH eps 30 aeps 100 header 9078 4671 one 663 1607 zero 663 497 ptrail 662 repeat 9078 2216 pre_data_bits 16 pre_data 0x8322 gap 106974 min_repeat 4 toggle_bit 0 begin codes Power 0x000000000000619E 1 0x0000000000008B74 2 0x0000000000008F70 3 0x000000000000906F 4 0x0000000000008A75 5 0x000000000000847B 6 0x0000000000007887 7 0x0000000000008976 8 0x000000000000837C 9 0x0000000000007788 0 0x000000000000807F CMSS 0x000000000000718E EAX 0x0000000000008C73 Mute 0x0000000000006E91 Vol_Down 0x000000000000639C Vol_Up 0x000000000000629D Up 0x0000000000007B84 Left 0x0000000000008778 Ok 0x000000000000817E Right 0x000000000000758A Down 0x0000000000008D72 Return 0x0000000000008E71 Start 0x0000000000008877 Cancel 0x0000000000007C83 Rec 0x000000000000738C Options 0x000000000000827D Display 0x0000000000007689 Previous 0x0000000000007F80 Play 0x0000000000007986 Next 0x0000000000007A85 Slow 0x0000000000007D82 Stop 0x000000000000857A Step 0x0000000000007E81 end codes end remote # # contributed by Stefan Br�ns # # brand: Creative Audigy 2 ZS Platinum LiveDrive # model no. of remote control: # devices being controlled by this remote: # begin remote name LiveDrive flags SPACE_ENC|CONST_LENGTH bits 16 eps 30 aeps 100 header 9000 4500 one 563 1687 zero 563 562 pre_data_bits 16 pre_data 0x8000 gap 108000 toggle_bit 0 repeat 9000 2250 frequency 38000 duty_cycle 33 begin codes mute 0x0000000000000040 vol+ 0x0000000000008080 vol- 0x0000000000008082 cmss 0x0000000000000080 end codes end remote begin remote name LiveDrive_Headphone bits 16 flags SPACE_ENC|CONST_LENGTH eps 30 aeps 100 header 9000 4500 one 563 1687 zero 563 562 repeat 9000 2250 pre_data_bits 16 pre_data 0x8000 gap 108000 toggle_bit 0 frequency 38000 duty_cycle 33 begin codes Headphone_out 0x4000 Headphone_in 0x4080 end codes end remote
As you can see my file has configuration for 3 devices. First one is my 33 button remote control. Second one is LiveDrive receiver which has 2 buttons and volume knob. The last one device is Hedphone monitor which will allow me to react on headphones plug in and out events. This ends my remote control configuration. Now I'm ready to use my lirc devices. I can start them by running following command in terminal:
/etc/init.d/lircd start
To make my lircd start as system service I have to run following command in terminal:
rc-update add lircd default
Now I can configure applications to use my lirc devices.
Applications configuration
There are two ways of controlling programs using lirc. First one is direct lirc support build into the application. To make my applications use lirc support I had to add lirc use flag to /etc/make.conf, then I can rebuild applications with the new use flag by running following command in terminal.
emerge --deep --update --newuse world
To check which of installed programs have direct lirc support you can use gentoolkit equery utility like this:
equery hasuse lirc [ Searching for USE flag lirc in all categories among: ] * installed packages [I--] [ ~] kde-base/kdeutils-meta-4.4.4 (4.4) [I--] [ ] dev-python/kaa-base-0.6.0 (0) [I--] [ ~] media-video/mplayer-1.0_rc4_p20100612 (0) [I--] [ ] media-video/vlc-1.0.6 (0) [I--] [ ~] media-plugins/audacious-plugins-2.3 (0) [I--] [ ~] media-plugins/banshee-community-extensions-1.6.1 (0) [I--] [ ~] media-tv/mythtv-0.23_p25073 (0)
As you can see on my system example there is wide range of programs that has direct lirc support. To make them use lirc you have to create a special ~/.lircrc configuration file in your home which will map program functions to remote control buttons. You can check what kind of program functions are available to user by running program help command or reading program documentation. Below you can find my .lircrc mapping file for MythTV media center, Audacious and Banshee sound players.
##################################################### #MythTv LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = mythtv config = [ repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = mythtv config = ] repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = mythtv config = | end #Show teletex/caption begin remote = LiveDrive button = cmms prog = mythtv config = T end ##################################################### #Audacious LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = audacious config = VOL_DOWN repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = audacious config = VOL_UP repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = audacious config = MUTE end # Playlist clear begin prog = audacious remote = LiveDrive button = cmss repeat = 0 delay = 0 config = PLAYLIST_CLEAR end ##################################################### #MythTV Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Up prog = mythtv config = Up repeat = 1 end begin remote = Creative_RM-1500 button = Down prog = mythtv config = Down repeat = 1 end begin remote = Creative_RM-1500 button = Left prog = mythtv config = Left end begin remote = Creative_RM-1500 button = Right prog = mythtv config = Right end #stop in mythmusic OR show osd begin remote = Creative_RM-1500 button = Stop prog = mythtv config = O end begin remote = Creative_RM-1500 button = Play prog = mythtv config = P end begin remote = Creative_RM-1500 button = Previous prog = mythtv config = Home end begin remote = Creative_RM-1500 button = Next prog = mythtv config = End end begin remote = Creative_RM-1500 button = Vol_Down prog = mythtv config = [ repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = mythtv config = ] repeat = 1 end begin remote = Creative_RM-1500 button = Ok prog = mythtv config = Enter end begin remote = Creative_RM-1500 button = Mute prog = mythtv config = | end #Numer Codes begin remote = Creative_RM-1500 button = 1 prog = mythtv config = 1 end begin remote = Creative_RM-1500 button = 2 prog = mythtv config = 2 end begin remote = Creative_RM-1500 button = 3 prog = mythtv config = 3 end begin remote = Creative_RM-1500 button = 4 prog = mythtv config = 4 end begin remote = Creative_RM-1500 button = 5 prog = mythtv config = 5 end begin remote = Creative_RM-1500 button = 6 prog = mythtv config = 6 end begin remote = Creative_RM-1500 button = 7 prog = mythtv config = 7 end begin remote = Creative_RM-1500 button = 8 prog = mythtv config = 8 end begin remote = Creative_RM-1500 button = 9 prog = mythtv config = 9 end begin remote = Creative_RM-1500 button = 0 prog = mythtv config = 0 end #Show menu begin remote = Creative_RM-1500 button = Options prog = mythtv config = M end #Jump to bookmarked position begin remote = Creative_RM-1500 button = Return prog = mythtv config = K end #Cycle through aspect ratios begin remote = Creative_RM-1500 button = Display prog = mythtv config = W end #close/cancel/escape begin remote = Creative_RM-1500 button = Cancel prog = mythtv config = Esc repeat = 3 end #show teletext / captions begin remote = Creative_RM-1500 button = CMSS prog = mythtv config = T end #Show information (OK button is Enter) begin remote = Creative_RM-1500 button = Start prog = mythtv config = I end #adjust time stretch begin remote = Creative_RM-1500 button = Slow prog = mythtv config = A end #increase play speed begin remote = Creative_RM-1500 button = Step prog = mythtv config = U end #cycle through audio streams begin remote = Creative_RM-1500 button = EAX prog = mythtv config = + end begin remote = Creative_RM-1500 button = Power prog = mythtv config = Esc end begin remote = Creative_RM-1500 button = Rec prog = mythtv config = R end ##################################################### #Audacious Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Play prog = audacious config = PLAYPAUSE end begin remote = Creative_RM-1500 button = Stop prog = audacious config = STOP end begin remote = Creative_RM-1500 button = Options prog = audacious config = SHUFFLE end begin remote = Creative_RM-1500 button = Options prog = audacious config = SHUFFLE end begin remote = Creative_RM-1500 button = Return prog = audacious config = REPEAT end begin remote = Creative_RM-1500 button = Right prog = audacious config = FWD end begin remote = Creative_RM-1500 button = Left prog = audacious config = BWD end begin remote = Creative_RM-1500 button = Power prog = audacious config = QUIT end begin remote = Creative_RM-1500 button = Start prog = audacious config = LIST end begin remote = Creative_RM-1500 button = EAX prog = audacious config = PLAYLIST_ADD end begin remote = Creative_RM-1500 button = CMSS prog = audacious config = PLAYLIST_CLEAR end begin remote = Creative_RM-1500 button = Previous prog = audacious config = PREV end begin remote = Creative_RM-1500 button = Next prog = audacious config = NEXT endbegin remote = Creative_RM-1500 button = Vol_Down prog = audacious config = VOL_DOWN repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = audacious config = VOL_UP repeat = 1 end begin remote = Creative_RM-1500 button = Mute prog = audacious config = MUTE end ##################################################### #Banshee LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = banshee config = volume-down repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = banshee config = volume-up repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = banshee config = toggle-mute end # Play begin prog = banshee remote = LiveDrive button = cmss repeat = 0 delay = 0 config = play end ##################################################### #Banshee Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Stop prog = banshee config = stop end begin remote = Creative_RM-1500 button = Play prog = banshee config = play end begin remote = Creative_RM-1500 button = Previous prog = banshee config = previous end begin remote = Creative_RM-1500 button = Next prog = banshee config = next end begin remote = Creative_RM-1500 button = Vol_Down prog = banshee config = volume-down repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = banshee config = volume-up repeat = 1 end begin remote = Creative_RM-1500 button = Mute prog = banshee config = toggle-mute end
As you can see this file isn't complicated. For every remotely controlled function you have to create one entry closed between begin and end words. For every entry you must provide your remote controller name, it's button name, program name and program function that should be assigned to previously given button. Optionally you may defined repeat parameter if the function should be repeated when you hold down the button. This last parameter is useful mostly for volume controls. Number of available functions are dependent on lirc support implantation. As you can see on above example MythTV and Audacious has wide range of lirc functions while Banshee support is very basic.
Some of the applications are offering their own lirc support. XBMC best looking media center available for Linux is example of such application. To make it work with lirc you have to provide Lirc mapping configuration file in xml format and save it in your home as ~/.xbmc/userdata/Lircmap.xml. Below you can see my Lircmap.xml file.
<lircmap> <remote device="LiveDrive"> <volumeplus>vol+</volumeplus> <volumeminus>vol-</volumeminus> <mute>mute</mute> <power>cmss</power> </remote> <remote device="Creative_RM-1500"> <power>Power</power> <one>1</one> <two>2</two> <three>3</three> <four>4</four> <five>5</five> <six>6</six> <seven>7</seven> <eight>8</eight> <nine>9</nine> <zero>0</zero> <info>CMSS</info> <menu>EAX</menu> <mute>Mute</mute> <volumeminus>Vol_Down</volumeminus> <volumeplus>Vol_Up</volumeplus> <up>Up</up> <left>Left</left> <select>Ok</select> <right>Right</right> <down>Down</down> <back>Return</back> <start>Start</start> <clear>Cancel</clear> <record>Rec</record> <title>Options</title> <display>Display</display> <skipminus>Previous</skipminus> <play>Play</play> <pageplus>Step</pageplus> <pause>Slow</pause> <stop>Stop</stop> <skipplus>Next</skipplus> </remote> </lircmap>
This file provides a mapping of the keys on my remote controllers to XBMC button strings defined as xml tags. Full list of button string available in XBMC you can find here. Those button strings are mapped by default XBMC configuration to actions available in media center. I could create my own action mappings but I found this unnecessary as default configuration is working quite well for me.
The second method to setup lirc support in applications is using build into KDE desktop environment GUI LIRC settings utility. The is probably the easiest way. This KDE tool has direct support and easy wizards to set up most popular KDE applications including: Kaffeine media player, Konqueror web browser, KDE sound mixer, VLC media player, Amarok media player, KsCD audio CD player, Okular document browser and Dragon media player. If this is not enough you can use advanced setup for any programs that are using Linux system messaging bus DBus. This way I was able to remotely control additional applications like for example Kmplayer media player. Using this tool you can also assign remote controller functions for shutdown, reboot, hibernate and suspend system actions. Last but not least you can setup lunch program actions. This tool is so easy to use that I want be wasting my time to explain how to work with it. You can see this tool on some of the screenshots provided below.
The configuration of Lirc is not so hard it just require some time to write all those files. Most of them you can find in Internet. Lirc package is not the only way to remotely control your Linux application. I use other tools as well below you find more information.
Additional Information
Besides the infrared remote controller I also have a bluetooth Cordless Logitech Rumplepad 2 game pad. I use this pad to control my media center applications MythTV and XBMC. I also use it as remote pointing device. To control both media centers I had to build them with joystick support. For MythTV I additionally had to create a joystick configuration file in my home and save it as ~/.mythtv/joystickmenurc. Below you can see my joystick configuration file for mythtv.
devicename /dev/input/js0 button 0 Enter button 1 T button 2 P button 3 0 button 4 M button 5 K button 6 I button 7 A button 8 U button 9 Esc button 10 | button 11 Escape axis 1 -32767 0 Home axis 1 32767 0 End axis 2 32767 0 [ axis 2 -32767 0 ] axis 4 -32767 0 Right axis 4 0 32767 Left axis 5 -32767 0 Down axis 5 0 32767 Up
In this file I provide a joystick device node and mapping of my joystick buttons and axis to MythTV functions.
Controlling XBMC with my game pad does not require any additional configuration as XBMC comes with full support for Logitech Cordless RumplePad 2 game controller. My game pad was working in XBMC right away after media center installation.
To use my game pad as remote pointing device I had to additionally install QJoyPad application. This is program which lets user translate input events generated by joysticks into mouse actions and keystrokes in Linux X environment. This program comes with simple to use settings wizard which is helping user create many layout configurations. User can switch between defined configurations in runtime.
Prove that it's working
Sources
- Lirc Project Page
- Gentoo Wiki Lirc HowTo
- MythTV Wiki
- XBMC Lirc HowTo
- emu10k1 kernel module documentation
- man lircd
Wstęp
Używam mojego komputera jako głównego centrum multimedialnego w moim mieszkaniu. Większość muzyki, której słucham czy filmów, które oglądam jest odtwarzana przez moje Linuxowe aplikacje multimedialne. Dzięki pakietowi lirc mogę kontrolować mój komputer używając pilota. To naprawdę wspaniała rzecz szczególnie dla tak leniwej osoby jak ja, że mogę zrobić wszystko co trzeba na moim komputerze nie ruszając się z kanapy. Lirc zapewnia wsparcie dla szerokiej gamy pilotów na podczerwień. Ja posiadam Creative LiveDrive wraz pilotem RM-1500. Oba urządzenia były częścią zestawu mojej karty dźwiękowej Creative SoundBlaster Audigy 4 Pro. Środowisko graficzne KDE posiada bezpośrednie wsparcie dla urządzeń Lirc i dzięki temu mogę zdalnie kontrolować dowolną aplikację korzystającą z Linuxowego systemu wymiany informacji Dbus. To co podoba mi się najbardziej w zdalnym zarządzaniu w Linuxie to fakt, że nie jestem związany czy ograniczony domyślną konfiguracją, której musiałbym się nauczyć. Mogę skonfigurować moje urządzenia i wybrać aplikację, którymi chcę zarządzać samodzielnie. Tylko moja wyobraźnia mnie ogranicza. Jest to podstawowa różnica między Linuxem a innymi systemami operacyjnymi. To ty sprawiasz, że Linux działa jak sobie życzysz a nie uczysz się na pamięć, jak powinien działać twój system.
Postaram się tutaj podzielić moją konfiguracją usług Lirc pochodzącą z mojego głównego komputera. Lirc nie jest jedynym Linuxowym projektem pozwalającym na zdalne kontrolowanie komputera. Na końcu znajdziesz, krótką informację na temat innych programów, które wykorzystuję do zdalnego zarządzania moim komputerem. Większość dostępnych tutaj informacji powinno dać się wykorzystać w dowolnej dystrybucji Linuxa, jednakże niektóre z nich są typowe dla dystrybucji Gentoo Linux. Jeśli posiadasz innego pilota niż ja, możesz mimo to skorzystać z niektórych podanych tutaj informacji. Rozpocznę od konfiguracji kernela i usług systemowych.
Konfiguracja kernela i usług systemowych
Mój pilot jest zintegrowany z moją kartą dźwiękową dlatego muszę go kontrolować używając modułu kernela dla mojej karty dźwiękowej. Aby skonfigurować kernel musiałem wejść do jego katalogu i uruchomić menuconfig wydając następujące komendy w terminalu:
cd /usr/src/linux make menuconfig
Poniżej znajdziesz listę wymaganych modułów kernela dla mojego urządzenia lirc.
Konfiguracja Kernela Linuxa: Konfiguracja modułów kernela |
Loadable module support ---> [*] Module unloading Device Drivers ---> Input device support ---> [*] Event interface <M> Sound card support ---> <M> Advanced Linux Sound Architecture ---> [*] PCI sound devices ---> <M> Emu10k1 (SB Live!, Audigy, E-mu APS) |
Jak widzisz wsparcie dla karty dźwiękowej zostanie zbudowane jako moduł. Moduł będzie załadowany przez mechanizm dynamicznej alokacji sprzętu udev i zainicjowany podczas startu systemu dźwiękowego alsa. Po zaznaczeniu wymaganych modułów kernela, można skompilować, zainstalować i wykorzystać nowy kernel. Zwykle dokonuję tego wydając następujące komendy w terminalu:
cd /usr/src/linux make && make modules_install install
To jednakże nie koniec. Aby zainicjować obsługę pilota dla modułu kernela Emu10k1 musiałem przekazać dodatkowy parametr do modułu kernela. Dokonałem tego definiując konfigurację modułu dźwiękowego w pliku /etc/modprobe.d/alsa.conf. Poniżej możesz zobaczyć część mojego pliku alsa.conf dotyczącą konfiguracji karty dźwiękowej Audigy 4.
alias snd-card-0 snd-emu10k1 options snd-emu10k1 index=0 id=audigy4pro extin=0x3fcf extout=0x1fcf enable_ir=1 alias sound-slot-0 snd-emu10k1
Najważniejszą rzeczą jest linia options. Opcja modułu kernela enable_ir = 1 włącza obsługę pilota na podczerwień w mojej karcie dźwiękowej.
Teraz można zrestartować komputer, używając nowego kernela. Po uruchomieniu nowy moduł kernela powinien zostać załadowany a pilot na podczerwień powinien działać. Niestety przekonałem się, że powyższa konfiguracja nie jest wystarczająca aby sprawić, że mój LiveDrive z SoundBlastera Audigy 4 Pro będzie odbierał poprawnie sygnały pochodzące z jego pilota. Dioda kontrolna LiveDrive'a nie zapalała się kiedy przyciskałem przyciski na pilocie. Po przeszukaniu Internetu znalazłem informację, że urządzenie LiveDrive musi zostać zainicjowane specjalną komendą. Najlepszym sposobem aby to zrobić jest napisanie prostej usługi systemowej, która będzie zależna od usługi systemu dźwiękowego alsa. Nazwałem tę usługę audigy. Poniżej znajdziesz skrypt usługi systemowej, która sprawia, że mój pilot zaczyna funkcjonować prawidłowo.
#!/sbin/runscript depend() { need alsasound } start() { ebegin "Initialising external I/O Hub" echo -e '\0360\0000\0040\0041\0141\0000\0000\0000\0177\0000\0367' > /dev/snd/midiC0D1 eend $? } stop() { ebegin "Nothing to Stop" eend $?
Jak możesz zauważyć w tym skrypcie moje urządzenie LiveDrive jest reprezentowane przez węzeł urządzenia /dev/snd/midiC0D1. Sam skrypt jest nieskompilowany, po prostu przekazuje ciąg inicjacyjny używając znaków ASCI zapisanych w kodzie ósemkowym. Teraz mogę dodać ten skrypt do domyślnego poziomu uruchomienia tak aby wykonywał się on podczas startu systemu. Aby tego dokonać muszę wykonać następującą komendę w terminalu:
rc-update add audigy default
Aby uruchomić ten skrypt bez potrzeby restartowania sytemu muszę wykonać następującą komendę w terminalu:
/etc/init.d/audigy start
Po uruchomieniu tej usługi dioda kontrolna urządzenia LiveDrive zaczęła się zapalać ilekroć wciksałem klawisze mojego pilota. Teraz możemy przejść do konfiguracji Lirca.
Konfiguracja Lirca
Przed zainstalowaniem pakietu Lirc w systemie Gentoo należy podać nazwę urządzenia lirc w pliku konfiguracyjnym /etc/make.conf. To sprawi, że lirc zainstaluje tylko te komponenty, których potrzebujesz. Konfiguracja lirca w moim pliku /etc/make.conf wygląda w ten sposób:
LIRC_DEVICES="livedrive_midi"
Aby zainstalować Lirc w systemie Gentoo musisz wydać następującą komendę w terminalu:
emerge -av sys-apps/lirc
Instalacja Lirca spwoduje powjawienie się usługi systemowej, która pozwoli nam uruchomić demon lirc. Zanim uruchomimy tę usługę powinniśmy we właściwy sposób ją skonfigurować. Pierwszą rzecz jaką musimy zrobić to powiedzieć usłudze lirc z jakiego typu urządzenia chcemy korzystać. Robiny to dodając opcję LIRCD_OPTS do pliku /etc/conf.d/lircd. Konfiguracja dla LiveDrive z Audigy 4 Pro powinna wyglądać w ten sposób:
LIRCD_OPTS="-H livedrive_midi -d /dev/snd/midiC0D1"
Drugą rzeczą jaką musimy zrobić to stworzyć plik konfiguracyjny, który powiąże sygnały podczerwone z przyciskami naszego pilota. Na stronie projektu Lirc możesz znaleźć szczegółowe informacje jak dokonać tego ręcznie, ale tak na prawdę nie ma potrzeby. Powinieneś bez większego problemu znaleźć konfigurację dla twojego pilota na stronie Lirca lub gdzieś w Internecie. Plik konfiguracyjny powinien zostać zapisany jako /etc/lirc/lircd.conf. Poniżej możesz zobaczyć plik konfiguracyjny dla moich urządzeń.
############################################################## #RM-1500 For Audigy 4 Pro ############################################################## begin remote name Creative_RM-1500 bits 16 flags SPACE_ENC|CONST_LENGTH eps 30 aeps 100 header 9078 4671 one 663 1607 zero 663 497 ptrail 662 repeat 9078 2216 pre_data_bits 16 pre_data 0x8322 gap 106974 min_repeat 4 toggle_bit 0 begin codes Power 0x000000000000619E 1 0x0000000000008B74 2 0x0000000000008F70 3 0x000000000000906F 4 0x0000000000008A75 5 0x000000000000847B 6 0x0000000000007887 7 0x0000000000008976 8 0x000000000000837C 9 0x0000000000007788 0 0x000000000000807F CMSS 0x000000000000718E EAX 0x0000000000008C73 Mute 0x0000000000006E91 Vol_Down 0x000000000000639C Vol_Up 0x000000000000629D Up 0x0000000000007B84 Left 0x0000000000008778 Ok 0x000000000000817E Right 0x000000000000758A Down 0x0000000000008D72 Return 0x0000000000008E71 Start 0x0000000000008877 Cancel 0x0000000000007C83 Rec 0x000000000000738C Options 0x000000000000827D Display 0x0000000000007689 Previous 0x0000000000007F80 Play 0x0000000000007986 Next 0x0000000000007A85 Slow 0x0000000000007D82 Stop 0x000000000000857A Step 0x0000000000007E81 end codes end remote # # contributed by Stefan Br�ns # # brand: Creative Audigy 2 ZS Platinum LiveDrive # model no. of remote control: # devices being controlled by this remote: # begin remote name LiveDrive flags SPACE_ENC|CONST_LENGTH bits 16 eps 30 aeps 100 header 9000 4500 one 563 1687 zero 563 562 pre_data_bits 16 pre_data 0x8000 gap 108000 toggle_bit 0 repeat 9000 2250 frequency 38000 duty_cycle 33 begin codes mute 0x0000000000000040 vol+ 0x0000000000008080 vol- 0x0000000000008082 cmss 0x0000000000000080 end codes end remote begin remote name LiveDrive_Headphone bits 16 flags SPACE_ENC|CONST_LENGTH eps 30 aeps 100 header 9000 4500 one 563 1687 zero 563 562 repeat 9000 2250 pre_data_bits 16 pre_data 0x8000 gap 108000 toggle_bit 0 frequency 38000 duty_cycle 33 begin codes Headphone_out 0x4000 Headphone_in 0x4080 end codes end remote
Jak widzisz mój plik przechowuję konfigurację trzech urządzeń. Pierwszym jest mój 33 przyciskowy pilot. Drugim jest odbiornik LiveDrive, który posiada 2 klawisze i pokrętło dźwięku. Ostanie urządzenie to monitor słuchawek, który pozwala mi reagować na zdarzenia podłączania i odłączania słuchawek. To kończy konfigurację urządzeń pilotów. Teraz mogę wykorzystać moje piloty. Mogę uruchomić usługę wydając następujące polecenie w terminalu.
/etc/init.d/lircd start
Aby sprawić, że usługa lircd uruchomi się jako usługa systemowa muszę wydać następujące polecenie w terminalu.
rc-update add lircd default
Teraz mogę skonfigurować programy, aby wykorzystywały moje urządzenia lirc.
Konfiguracja programów
Są dwa sposoby na kontrolowanie programów przy użyciu pakietu lirc. Pierwszym z nich jest bezpośrednio wbudowana w program obsługa lirc. Aby sprawić, że moje programy będą posiadały wsparcie dla lirc muszę dodać flagę use lirc do pliku konfiguracyjnego /etc/make.conf, następnie mogę przebudować programy z obsługą nowych flag use wydając następującą komendę w terminalu:
emerge --deep --update --newuse world
Aby sprawdzić, które z zainstalowanych programów mają bezpośrednie wsparcie dla lirca możesz wykorzystać narzędzie equery z pakietu gentoolkit w następujący sposób:
equery hasuse lirc [ Searching for USE flag lirc in all categories among: ] * installed packages [I--] [ ~] kde-base/kdeutils-meta-4.4.4 (4.4) [I--] [ ] dev-python/kaa-base-0.6.0 (0) [I--] [ ~] media-video/mplayer-1.0_rc4_p20100612 (0) [I--] [ ] media-video/vlc-1.0.6 (0) [I--] [ ~] media-plugins/audacious-plugins-2.3 (0) [I--] [ ~] media-plugins/banshee-community-extensions-1.6.1 (0) [I--] [ ~] media-tv/mythtv-0.23_p25073 (0)
Jak widzisz na przykładzie mojego sytemu istnieje spora liczba programów posiadających bezpośrednie wsparcie dla lirca. Aby mogły one korzystać z pakietu lirc musisz stworzyć specjalny plik konfiguracyjny ~/.lircrc w swoim katalogu domowym. Plik ten powiąże funkcje programów z przyciskami twojego pilota. Możesz sprawdzić, które z funkcji programów są dostępne do wykorzystania, używając pomocy programu lub czytając jego dokumentację. Poniżej możesz zobaczyć mój plik .lircrc storzony dla centrum multimedialnego MythTV oraz odtwarzaczy dźwięku Audacious i Banshee.
##################################################### #MythTv LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = mythtv config = [ repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = mythtv config = ] repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = mythtv config = | end #Show teletex/caption begin remote = LiveDrive button = cmms prog = mythtv config = T end ##################################################### #Audacious LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = audacious config = VOL_DOWN repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = audacious config = VOL_UP repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = audacious config = MUTE end # Playlist clear begin prog = audacious remote = LiveDrive button = cmss repeat = 0 delay = 0 config = PLAYLIST_CLEAR end ##################################################### #MythTV Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Up prog = mythtv config = Up repeat = 1 end begin remote = Creative_RM-1500 button = Down prog = mythtv config = Down repeat = 1 end begin remote = Creative_RM-1500 button = Left prog = mythtv config = Left end begin remote = Creative_RM-1500 button = Right prog = mythtv config = Right end #stop in mythmusic OR show osd begin remote = Creative_RM-1500 button = Stop prog = mythtv config = O end begin remote = Creative_RM-1500 button = Play prog = mythtv config = P end begin remote = Creative_RM-1500 button = Previous prog = mythtv config = Home end begin remote = Creative_RM-1500 button = Next prog = mythtv config = End end begin remote = Creative_RM-1500 button = Vol_Down prog = mythtv config = [ repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = mythtv config = ] repeat = 1 end begin remote = Creative_RM-1500 button = Ok prog = mythtv config = Enter end begin remote = Creative_RM-1500 button = Mute prog = mythtv config = | end #Numer Codes begin remote = Creative_RM-1500 button = 1 prog = mythtv config = 1 end begin remote = Creative_RM-1500 button = 2 prog = mythtv config = 2 end begin remote = Creative_RM-1500 button = 3 prog = mythtv config = 3 end begin remote = Creative_RM-1500 button = 4 prog = mythtv config = 4 end begin remote = Creative_RM-1500 button = 5 prog = mythtv config = 5 end begin remote = Creative_RM-1500 button = 6 prog = mythtv config = 6 end begin remote = Creative_RM-1500 button = 7 prog = mythtv config = 7 end begin remote = Creative_RM-1500 button = 8 prog = mythtv config = 8 end begin remote = Creative_RM-1500 button = 9 prog = mythtv config = 9 end begin remote = Creative_RM-1500 button = 0 prog = mythtv config = 0 end #Show menu begin remote = Creative_RM-1500 button = Options prog = mythtv config = M end #Jump to bookmarked position begin remote = Creative_RM-1500 button = Return prog = mythtv config = K end #Cycle through aspect ratios begin remote = Creative_RM-1500 button = Display prog = mythtv config = W end #close/cancel/escape begin remote = Creative_RM-1500 button = Cancel prog = mythtv config = Esc repeat = 3 end #show teletext / captions begin remote = Creative_RM-1500 button = CMSS prog = mythtv config = T end #Show information (OK button is Enter) begin remote = Creative_RM-1500 button = Start prog = mythtv config = I end #adjust time stretch begin remote = Creative_RM-1500 button = Slow prog = mythtv config = A end #increase play speed begin remote = Creative_RM-1500 button = Step prog = mythtv config = U end #cycle through audio streams begin remote = Creative_RM-1500 button = EAX prog = mythtv config = + end begin remote = Creative_RM-1500 button = Power prog = mythtv config = Esc end begin remote = Creative_RM-1500 button = Rec prog = mythtv config = R end ##################################################### #Audacious Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Play prog = audacious config = PLAYPAUSE end begin remote = Creative_RM-1500 button = Stop prog = audacious config = STOP end begin remote = Creative_RM-1500 button = Options prog = audacious config = SHUFFLE end begin remote = Creative_RM-1500 button = Options prog = audacious config = SHUFFLE end begin remote = Creative_RM-1500 button = Return prog = audacious config = REPEAT end begin remote = Creative_RM-1500 button = Right prog = audacious config = FWD end begin remote = Creative_RM-1500 button = Left prog = audacious config = BWD end begin remote = Creative_RM-1500 button = Power prog = audacious config = QUIT end begin remote = Creative_RM-1500 button = Start prog = audacious config = LIST end begin remote = Creative_RM-1500 button = EAX prog = audacious config = PLAYLIST_ADD end begin remote = Creative_RM-1500 button = CMSS prog = audacious config = PLAYLIST_CLEAR end begin remote = Creative_RM-1500 button = Previous prog = audacious config = PREV end begin remote = Creative_RM-1500 button = Next prog = audacious config = NEXT endbegin remote = Creative_RM-1500 button = Vol_Down prog = audacious config = VOL_DOWN repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = audacious config = VOL_UP repeat = 1 end begin remote = Creative_RM-1500 button = Mute prog = audacious config = MUTE end ##################################################### #Banshee LiveDrive Configuration ##################################################### #Volume Down begin remote = LiveDrive button = vol- prog = banshee config = volume-down repeat = 1 end #Volume Up begin remote = LiveDrive button = vol+ prog = banshee config = volume-up repeat = 1 end #Mute begin remote = LiveDrive button = mute prog = banshee config = toggle-mute end # Play begin prog = banshee remote = LiveDrive button = cmss repeat = 0 delay = 0 config = play end ##################################################### #Banshee Creative RM-1500 Configuration ##################################################### begin remote = Creative_RM-1500 button = Stop prog = banshee config = stop end begin remote = Creative_RM-1500 button = Play prog = banshee config = play end begin remote = Creative_RM-1500 button = Previous prog = banshee config = previous end begin remote = Creative_RM-1500 button = Next prog = banshee config = next end begin remote = Creative_RM-1500 button = Vol_Down prog = banshee config = volume-down repeat = 1 end begin remote = Creative_RM-1500 button = Vol_Up prog = banshee config = volume-up repeat = 1 end begin remote = Creative_RM-1500 button = Mute prog = banshee config = toggle-mute end
Jak widzisz ten plik nie jest skomplikowany. Dla każdej funkcji, która ma być kontrolowana zdalnie, tworzysz wpis ograniczony słowami begin i end. Dla każdego z wpisów podajesz nazwę pilota, nazwę konkretnego przycisku, nazwę programu oraz jego funkcję, która ma być przypisana do poprzednio zdefiniowanego przycisku. Opcjonalnie możesz zdefiniować parametr: repeat jeśli funkcja ma być powtarzana kiedy wciśniesz i przytrzymasz przycisk. Ten ostatni parametr jest przydatny głownie do sterowania głośnością. Ilość dostępnych funkcji jest zależna od implementacji wsparcia dla lirca przez daną aplikację. Jak widzisz na powyższym przykładzie MythTV i Audacious mają dużą ilość dostępnych funkcji podczas gdy wsparcie dla lirca w Banshee jest bardzo podstawowe.
Niektóre z aplikacji zapewniają swoje własne wsparcie dla lirca. XBMC najlepiej wyglądające centrum multimedialne dostępne dla Linuxa jest przykładem takiej aplikacji. Aby wykorzystywało ono Lirca do zdalnego zarządzania musisz stworzyć plik mapujący Lirc w formacie xml i zapisać go w swoim katalogu domowym jako ~/.xbmc/userdata/Lircmap.xml. Poniżej możesz zobaczyć mój plik Lircmap.xml.
<lircmap> <remote device="LiveDrive"> <volumeplus>vol+</volumeplus> <volumeminus>vol-</volumeminus> <mute>mute</mute> <power>cmss</power> </remote> <remote device="Creative_RM-1500"> <power>Power</power> <one>1</one> <two>2</two> <three>3</three> <four>4</four> <five>5</five> <six>6</six> <seven>7</seven> <eight>8</eight> <nine>9</nine> <zero>0</zero> <info>CMSS</info> <menu>EAX</menu> <mute>Mute</mute> <volumeminus>Vol_Down</volumeminus> <volumeplus>Vol_Up</volumeplus> <up>Up</up> <left>Left</left> <select>Ok</select> <right>Right</right> <down>Down</down> <back>Return</back> <start>Start</start> <clear>Cancel</clear> <record>Rec</record> <title>Options</title> <display>Display</display> <skipminus>Previous</skipminus> <play>Play</play> <pageplus>Step</pageplus> <pause>Slow</pause> <stop>Stop</stop> <skipplus>Next</skipplus> </remote> </lircmap>
Ten plik wiąże przyciski moich pilotów z ciągami przycisków dostępnych w XBMC, które są zdefiniowane jako znaczniki xml. Pełną listę ciągów przycisków dostępnych w XBMC możesz znaleźć tutaj. Te przyciski są z kolei mapowane przez domyślną konfigurację XBMC na akcje centrum multimedialnego. Mógłbym utworzyć swój własny plik mapujący akcję ale uznałem to za zbędne, gdyż domyślna konfiguracja działa bardzo dobrze.
Drugą metodą na konfiguracje lirca w programach jest wykorzystanie wbudowanego w środowisko KDE narzędzia graficznej konfiguracji Lirc. To jest prawdopodobnie najprostszy możliwy sposób. Narzędzie KDE posiada bezpośrednie wsparcie i proste kreatory konfiguracji dla najpopularniejszych aplikacji KDE takich jak: odtwarzacz multimediów Kaffeine, przeglądarka internetowa Konqueror, mikser dźwięku KDE, odtwarzacz multimedialny VLC, odtwarzacz multimedialny Amarok, odtwarzacz audio CD KsCD, przeglądarkę dokumentów Okular i odtwarzacz multimedialny Dragon. Jeśli to nie wystarcza możesz wykorzystać zaawansowaną konfigurację pozwalającą na konfigurację programów wykorzystujących Linuxowy system przekazywania komunikatów DBus. W ten sposób mogłem zdalnie kontrolować dodatkowe programy jak na przykład odtwarzacz multimedialny Kmplayer. Przy użyciu tego narzędzia możesz także przypisać funkcje pilota do zdarzeń zamknięcia, uruchomienia ponownie, hibernowania czy uśpienia systemu. Ważną możliwością jest także możliwość definiowania akcji uruchamiających programy. To narzędzie jest tak proste w użyciu, że szkoda mi marnować mój czas aby tłumaczyć jak on działa. Możesz zobaczyć to narzędzie na niektórych zrzutach ekranu zamieszczonych poniżej.
Konfiguracja Lirca nie jest wcale trudna wymaga tylko czasu aby napisać wszystkie te pliki. Na szczęście większość z nich możesz znaleźć w internecie. Pakiet Lirc nie jest jedynym sposobem na zdalne kontrolowanie programów w twoim Linuxie. Używam także innych narzędzi, poniżej znajdziesz więcej informacji na ten temat.
Dodatkowe informacje
Poza pilotem na podczerwień posiadam też blutoothowy pad do gier Cordless Logitech Rumplepad 2. Używam go do zarządzania aplikacjami centrów multimedialnych MythTV i XBMC. Używam go także jako zdalnego urządzenia wskazującego. Aby zarządzać oboma centrami multimedialnymi musiałem skompilować je ze wsparciem dla obsługi joysticków. Dla MythTV dodatkowo musiałem utworzyć plik konfiguracyjny joysticka w moim katalogu domowym i zapisać go jako ~/.mythtv/joystickmenurc. Poniżej możesz zobaczyć plik konfiguracyjny joysticka stworzony dla mythtv.
devicename /dev/input/js0 button 0 Enter button 1 T button 2 P button 3 0 button 4 M button 5 K button 6 I button 7 A button 8 U button 9 Esc button 10 | button 11 Escape axis 1 -32767 0 Home axis 1 32767 0 End axis 2 32767 0 [ axis 2 -32767 0 ] axis 4 -32767 0 Right axis 4 0 32767 Left axis 5 -32767 0 Down axis 5 0 32767 Up
W tym pliku podaję węzeł urządzenia i mapuje przyciski oraz osie joysticka na funkcje MythTV.
Kontrolowanie XBMC przy użyciu mojego game pada nie wymagało żadnej dodatkowej konfiguracji, jako że XBMC posiada wbudowane wpsarcie dla kontrolera gier Logitech Cordless RumplePad 2. Mój pad do gier działał w XBMC natychmiast po zainstalowaniu centrum multimedialnego.
Aby wykorzystać mój pad do gier jako zdalne urządzenie wskazujące musiałem dodatkowo zainstalować program QJoyPad. Jest to program pozwalający użytkownikowi tłumaczyć zdarzenia generowane przez Joystick na akcje myszy i klawiatury w środowisku graficznym Linuxa. Program ten posiada prosty w użyciu kreator konfiguracji, który pomaga użytkownikowi tworzyć wiele układów konfiguracyjnych. Użytkownik może przełączać się miedzy zdefiniowanymi układami w czasie pracy.
Dowód, że to działa
Źródła
- Strona Projektu Lirc
- HowTo dotyczące Lirca na Gentoo Wiki
- MythTV Wiki
- HowTo opisujące konfigurację Lirc dla XBMC
- dokumentacja modułu kernela emu10k1
- man lircd
Here you can find screenshots showing Lirc devices and remotely controlled applications in KDE environment.
If larger picture is still to small for you click it to enlarge it.