This should be straightforward.  You'll need a 'momentary' switch,
rather than a toggle switch, because the action associated with a button
is triggered when the gpio pin is earthed briefly.  You can set it up so
that the button issues the 'pause' command when it is pressed.  'Pause'
will pause the player if it is playing, and release the pause if it is
paused.

Pick a suitable gpio pin that isn't being used by anything else, such as
an audio hat.  In my example I'll use gpio24.  This is a cut down
version of the script that I use for a button board and a rotary encoder
- I've trimmed out most of the bits you don't need, but left it so that
you can add other buttons if you wish.

This particular version of the script will issue the 'pause' command
with a short press, and the 'stop' command with a press longer than half
a second (500 millisec).


Code:
--------------------
    #!/bin/sh
  
  # start pigpiod daemon
  pigpiod -t 0 -f -l -s 10
  
  # wait for pigpiod to initialize - indicated by 'pigs t' exit code of zero
  
  count=10 # approx time limit in seconds
  while ! pigs t >/dev/null 2>&1 ; do
        if [ $((count--)) -le 0 ]; then
                printf "\npigpiod failed to initialize within time limit\n"
                exit 1 
        fi
  #     printf "\nWaiting for pigpiod to initialize\n"
        sleep 1
  done
  printf "\npigpiod is running\n"
  
  # load uinput module - required to be able to send keystrokes
  # then set the permission to group writable, so you don't need to run sbpd 
with root permissions
  sudo modprobe uinput
  sudo chmod g+w /dev/uinput
  
  PLAYER_MAC=aa:bb:cc:dd:ee:ff
  
  # button SW1
  SW1=24                                                        # GPIO pin 
number
  SH1=PAUS                                              # command for SHORT 
press
  LO1=STOP                                              # command for LONG press
  LMS1=500                                              # milliseconds for long 
press
  
  sbpd -v -M $PLAYER_MAC -f /home/tc/sbpd_commands.cfg 
b,$SW1,$SH1,2,0,$LO1,$LMS1
--------------------


The button can control any player - if your father has more than one
player you can put its MAC address in the script so that it controls the
desired player.  If he only has one player, you can remove the -M option
from the command in the last line.

The commands should be defined in a file in your home directory called
sbpd_commands.cfg.  This is my version - I've left all the commands I
use in there, so feel free to experiment.


Code:
--------------------
    #                                                   
  #   <CODE>=<JSON Formatted lms cli command>         
  #                                                   
  #       CODE - MUST be a 4 character code, to be reference on command line 
when
  #                                                                             
 
  #       For commands reference the LMS cli documentation, commands are to be 
JSO
  #                                                                             
  
  # Default commands                                                            
  
  PAUS=["pause"]                                                                
  
  VOL-=["button","voldown"]
  VOL+=["button","volup"]  
  PREV=["button","rew"]    
  NEXT=["button","fwd"]    
  POWR=["power"]         
  MIX+=["mixer","volume","+5"]
  MIX-=["mixer","volume","-5"]
  VMAX=["mixer","volume","100"]
  MUTE=["mixer","volume","0"]  
  PLAY=["button","rew.single"] 
  STOP=["stop"]                
  SHUF=["button","shuffle.single"]
  RSRT=["restartserver"]  
  PRE1=["button","preset_1.single"]
  PRS1=["button","preset_1.hold"]
  PRE2=["button","preset_2.single"]
  PRE3=["button","preset_3.single"]               
  PRE4=["button","preset_4.single"]               
  PRE5=["button","preset_5.single"]               
  PRE6=["button","preset_6.single"]               
  PRE7=["button","preset_7.single"]
  
--------------------


You'll need to install the sbpd extension, and I'm not sure if that also
installs pigpio as a dependency - if not, install that too.

To use this:
1) wire your momentary switch so that it connects gpio24 (in this case)
to one of the GND pins.  
2) Put the above script into a file in your home folder, e.g.
sbpd-script.sh, and make it executable ('sudo chmod +x sbpd-script.sh').

3) Put '/home/tc/sbpd=script.sh' into one of the user commands on the
tweaks page.  
4) Put 'sbpd_commands.cfg' into your home folder.

Reboot and the button should work.


------------------------------------------------------------------------
chill's Profile: http://forums.slimdevices.com/member.php?userid=10839
View this thread: http://forums.slimdevices.com/showthread.php?t=114075

_______________________________________________
diy mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/diy

Reply via email to