This shows you the differences between two versions of the page.
tutorials:cb1:customization:wireless_music_box [2013/11/23 19:19] soloforce created |
tutorials:cb1:customization:wireless_music_box [2013/12/23 14:50] (current) |
||
---|---|---|---|
Line 8: | Line 8: | ||
===== Abstract ===== | ===== Abstract ===== | ||
- | Cubieboard series have support for infra-read (IR) support and analog sound ouput. Together with mplayer, Cubieboard could be turned into a great music box. | + | Cubieboard series have support for infra-red (IR) support and analog sound ouput. Together with mplayer & LIRC, Cubieboard could be turned into a great music box. |
===== Prerequisite ===== | ===== Prerequisite ===== | ||
* A Cubieboard (1,2,3 are ok, theoretically) | * A Cubieboard (1,2,3 are ok, theoretically) | ||
- | * A remote (NEC compatible remote, like usual TV remote) | + | * An IR remote (NEC compatible remote, like usual TV remote) |
* Debian/Lubuntu Linux with IR support | * Debian/Lubuntu Linux with IR support | ||
===== Kernel Configuration ===== | ===== Kernel Configuration ===== | ||
+ | Select the sunxi IR support in kernel config, it's straightforward. | ||
+ | <file> | ||
+ | <*> Device Drivers ---> | ||
+ | <*> Input device support ---> | ||
+ | <*> Keyboards ---> | ||
+ | <*> sunxi IR support | ||
+ | </file> | ||
+ | If you compile the sunxi IR support as a module, it would be sunxi-ir.ko | ||
+ | ===== IR interface ===== | ||
+ | If your kernel has already support IR feature, you can test the IR device interface. | ||
+ | <code> | ||
+ | root@Cubieboard1:~# dmesg | grep -i sunxi-ir | ||
+ | [ 2.254701] input: sunxi-ir as /devices/virtual/input/input0 | ||
+ | </code> | ||
+ | If you see the above line, /dev/input/event0 should be the IR device interface. | ||
+ | ===== Keycode ===== | ||
+ | It is time to test your IR remote and get the keycodes. | ||
+ | root@Cubieboard1 ~# cat /dev/input/event0 | hexdump | ||
+ | Grasp your remote pointing to Cubieboad IR receiver and press a key, watch the output and last three columns, maybe like this | ||
+ | <code> | ||
+ | 0000000 c0d6 528c c81c 0000 0001 0009 0001 0000 | ||
+ | 0000010 c0d6 528c c830 0000 0000 0000 0000 0000 | ||
+ | 0000020 c0d6 528c 9c3f 0004 0001 0009 0000 0000 | ||
+ | 0000030 c0d6 528c 9c51 0004 0000 0000 0000 0000 | ||
+ | 0000040 c0d7 528c 3275 0001 0001 0015 0001 0000 | ||
+ | 0000050 c0d7 528c 3292 0001 0000 0000 0000 0000 | ||
+ | 0000060 c0d7 528c 272b 0004 0001 0015 0000 0000 | ||
+ | 0000070 c0d7 528c 273e 0004 0000 0000 0000 0000 | ||
+ | </code> | ||
+ | Pay attention to digits such as "0009", "0015", yes, they are the remote keycode, and you'd better write them down. Take notice that these keycodes are hexadecimal value. | ||
+ | ===== Software Installation ===== | ||
+ | <code> | ||
+ | root@Cubieboard1:~# apt-get install lirc mplayer | ||
+ | </code> | ||
+ | ===== LIRC Configuration ===== | ||
+ | LIRC is a package that allows you to decode and send infra-red signals of many (but not all) commonly used remote controls (http://www.lirc.org/). The configuration for Cubieboard is a little bit complicated, which involes 4 files. Let's do it step by step. | ||
+ | ==== udev rule file ==== | ||
+ | Create a udev rule file, like //* /etc/udev/rules.d/10-cubie-ir.rules *// whose content is as follows | ||
+ | <file> | ||
+ | SUBSYSTEM=="input", ACTION=="add", KERNEL=="event*", ATTRS{name}=="sunxi-ir", SYMLINK+="input/cubieir" | ||
+ | </file> | ||
+ | ==== IR interface file for LIRC ==== | ||
+ | Modify the //**/etc/lirc/hardware.conf**// now, modify the following lines | ||
+ | <file> | ||
+ | #Try to load appropriate kernel modules | ||
+ | LOAD_MODULES=true | ||
- | ===== IR interface & Keycode ===== | + | # Run "lircd --driver=help" for a list of supported drivers. |
+ | DRIVER="devinput" | ||
+ | # usually /dev/lirc0 is the correct setting for systems using udev | ||
+ | DEVICE="/dev/input/cubieir" | ||
+ | MODULES="sunxi-ir" | ||
+ | </file> | ||
+ | ==== LIRC keycode table ==== | ||
+ | Edit //**/etc/lirc/lircd.conf**// in your case. The **codes** section should be altered according to your own keycodes definitions, and they are in decimal form. | ||
+ | <file> | ||
+ | begin remote | ||
+ | name devinput | ||
+ | bits 16 | ||
+ | eps 30 | ||
+ | aeps 100 | ||
+ | pre_data_bits 16 | ||
+ | pre_data 0x0001 | ||
+ | post_data_bits 32 | ||
+ | post_data 0x00000001 | ||
+ | gap 132799 | ||
+ | toggle_bit 0 | ||
- | ===== Software Installation ===== | + | begin codes |
+ | POWER 69 | ||
+ | MUTE 71 | ||
+ | VOLUME+ 9 | ||
+ | VOLUME- 21 | ||
+ | MODE 70 | ||
+ | MOUSE 109 | ||
+ | HOME 108 | ||
+ | BACK 110 | ||
+ | LEFT 100 | ||
+ | RIGHT 101 | ||
+ | UP 102 | ||
+ | DOWN 103 | ||
+ | OK 105 | ||
+ | STOP 106 | ||
+ | PLAY 68 | ||
+ | SHUFFLE 25 | ||
+ | PREV 64 | ||
+ | NEXT 67 | ||
+ | RED 185 | ||
+ | GREEN 178 | ||
+ | YELLOW 173 | ||
+ | BLUE 172 | ||
+ | EQ 7 | ||
+ | 1 12 | ||
+ | 2 24 | ||
+ | 3 94 | ||
+ | 4 8 | ||
+ | 5 28 | ||
+ | 6 90 | ||
+ | 7 66 | ||
+ | 8 82 | ||
+ | 9 74 | ||
+ | 0 22 | ||
+ | AUDIO 168 | ||
+ | USD 13 | ||
+ | end codes | ||
+ | end remote | ||
+ | </file> | ||
+ | The above keycode definitions are for the IR remote like this | ||
- | ===== LIRC Configuration ===== | + | {{:tutorials:cb1:customization:2013-11-23-202655_433x296_scrot.png?400 |}} |
+ | ==== LIRC control file ==== | ||
+ | Edit //**/etc/lirc/lircrc.conf**// in your case. | ||
+ | <file> | ||
+ | begin | ||
+ | button = VOLUME+ | ||
+ | prog = mplayer | ||
+ | config = volume 1 | ||
+ | repeat = 1 | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = VOLUME- | ||
+ | prog = mplayer | ||
+ | config = volume -1 | ||
+ | repeat = 1 | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = PLAY | ||
+ | prog = mplayer | ||
+ | config = pause | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = MUTE | ||
+ | prog = mplayer | ||
+ | config = mute | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = POWER | ||
+ | prog = mplayer | ||
+ | config = stop | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = NEXT | ||
+ | prog = mplayer | ||
+ | config = pt_step +1 | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = PREV | ||
+ | prog = mplayer | ||
+ | config = pt_step -1 | ||
+ | end | ||
+ | |||
+ | #---------------------------- | ||
+ | |||
+ | begin | ||
+ | button = 0 | ||
+ | prog = irexec | ||
+ | config = start_mplayer.sh | ||
+ | end | ||
+ | |||
+ | begin | ||
+ | button = SHUFFLE | ||
+ | prog = irexec | ||
+ | config = start_mplayer.sh rescan | ||
+ | end | ||
+ | </file> | ||
===== Player Program ===== | ===== Player Program ===== | ||
+ | Mplayer has well support for LIRC, but we still need do some work to make it functional like a music box. We intend to make mplayer scan some specified directory (on Cubieboard or network-sharing directory), picking out those supported music files, like ape, flac, mp3, ogg etc., and play them in a shuffle way. Here goes the shell code snippet. | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | # start_mplayer.sh | ||
+ | |||
+ | # Set this line in your case. A play.list file will be created in this directory, so make it writable. | ||
+ | MUSIC_PATH="/data/share/music" | ||
+ | PLAY_LIST="play.list" | ||
+ | MUSIC_TYPES="mp3 wav ape ogg flac"; | ||
+ | |||
+ | if [ ! -e "${MUSIC_PATH}/${PLAY_LIST}" ] || ( [ $# -gt 0 ] && [ $1 == "rescan" ] ); then | ||
+ | echo "" > ${MUSIC_PATH}/${PLAY_LIST} | ||
+ | for music_type in $MUSIC_TYPES ; do | ||
+ | find ${MUSIC_PATH} -type f -iname "*.${music_type}" >> ${MUSIC_PATH}/${PLAY_LIST} | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | mplayer -lircconf /etc/lirc/lircrc.conf -vo null -shuffle -playlist ${MUSIC_PATH}/${PLAY_LIST} | ||
+ | </code> | ||
+ | Assign this script with an executable bit, and test it. | ||
+ | # chmod +x start_mplayer.sh | ||
+ | # ./start_mplayer.sh rescan | ||
+ | If mplayer is starting playing the music, good to go. | ||
+ | |||
+ | ===== Run LIRC with mplayer ===== | ||
+ | You can test LIRC with mplayer right now, with //**irexec**//, a convenient tool for running programs via LIRC. | ||
+ | # irexec -d /etc/lirc/lircrc.conf | ||
+ | Now, press your IR remote key, enjoy the music comes from Cubieboard. | ||
+ | If you would like the program running in a daemon style, add the fowlling line into //**/etc/rc.local**//, right before "exit 0". | ||
+ | <file> | ||
+ | sudo /usr/bin/irexec -d /etc/lirc/lircrc.conf | ||
+ | ## If there is no "sudo", irexec won't work, which is weird. | ||
+ | </file> | ||
<WRAP noprint> | <WRAP noprint> | ||
{{tag>Cubieboard Cubieboard2 IR remote music}} | {{tag>Cubieboard Cubieboard2 IR remote music}} | ||
</WRAP> | </WRAP> |