User Tools

Site Tools


tutorials:cb1:customization:wireless_music_box

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:cb1:customization:wireless_music_box [2013/11/23 19:48]
soloforce [Kernel Configuration]
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)
Line 43: Line 43:
 0000070 c0d7 528c 273e 0004 0000 0000 0000 0000 0000070 c0d7 528c 273e 0004 0000 0000 0000 0000
 </​code>​ </​code>​
-Pay attention to digits such as "​0009",​ "​0015",​ yes, they are the remote keycode, and you'd better write them down.+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 ===== ===== Software Installation =====
 <​code>​ <​code>​
Line 50: Line 50:
  
 ===== LIRC Configuration ===== ===== 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
 +
 +# 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
 +
 + 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
 +
 +{{:​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>​
tutorials/cb1/customization/wireless_music_box.txt · Last modified: 2013/12/23 14:50 (external edit)