Home of the Squeezebox™ & Transporter® network music players.
Page 23 of 23 FirstFirst ... 13212223
Results 221 to 223 of 223
  1. #221
    @LiFePO4

    with the deskpi Pro I routed a channel then slotted the 128x32 into it, had I been careful that should have been all I needed but ended up using some damping material to hold it secure and reduce the light bleed too

    easiest thing I've found for screw mounts is to solder the unit to perf-board large enough such that it can contain any circuitry but also with enough meat to drill fixing holes etc

    you can also get fancy with 3D printing and/or CNC
    As of 13-Jan-2021 my digitized collection is (25074 hours 42 minutes) + (19 seconds) or
    2.861 years in duration.

    Digitized thus far:

    Total Tracks: 161,783
    Total Albums: 14,808
    Total Artists: 21,054
    Total Genres: 751
    Total Playing Time: 25074:42:19


    With another ~2500 yet to be ripped...

  2. #222
    Lot of confusion :-)

    I offered the code, when there is any interest. You are interested, so here is the code with the lmsmonitor handling:

    Code:
    #!/bin/sh
    # --------------------------------------------------------------------------------------------------------------------------
    # Script polls "pcp mode" every 500 ms (1 second on Pi Zero) and sets a GPIO/lmsmonitor according to squeezelite play state.
    # Aki 9/2020 - Home: https://forums.slimdevices.com/showthread.php?110277-Feature-request-picoreplayer-Play-state-to-GPIO 
    # --------------------------------------------------------------------------------------------------------------------------
    # Vers 0.2: Cleanup of GPIO on exit. Reentrance cleared. -k kills running instance. Clear reaction on 'pcp mode' outages.
    # Vers 0.3: When no GPIO is given, green onboard LED led0 will be used.
    # Vers 0.4: Cosmetics.
    # Vers 0.5: 1/2021 LMSmonitor integration. Tested on pi 3b w. lmsmonitor (0.4.65 Dec 27 2020 19:33:28)
    
    BASE_GPIO_PATH=/sys/class/gpio
    BASE_LED0_PATH=/sys/class/leds/led0
    ScriptName=$(basename -- "$0")
    
    function UpTm () { # Returns UpTime sss.ms
      set `cat -- /proc/uptime`
      echo "$1"
    } # function UpTm
    
    function mySudo () { # Aufruf aus functions oder wg. background?
      echo $@ | sudo sh
    } # function mySudo
    
    function msg () {
      if [ $foreground ] || [ $verbose ]; then
        echo "$(UpTm) $ScriptName: $@"; #echo "$(date +"%T") $ScriptName: $@";
      fi # foreground
    } # function msg
    
    function err () {
      echo "$(UpTm) $ScriptName: Error: $1" >&2; exit 1 
    } # function err, not called from loop -therefore no need to cleanup?
    
    function KillMonitor () {
      while pid=$(pidof lmsmonitor); do     
        msg "LMSmonitor stopping pid $pid"  
        sudo killall -15 lmsmonitor #" #> /dev/null 2>&1"    
        sleep 1       
        msg "LMSmonitor stopped pid $pid"     
      done # Wait for end of kill
      oldMonitorState=0  
    } # function KillMonitor
    
    function StartMonitor () { 
      if pid=$(pidof lmsmonitor); then    
        KillMonitor      
      fi
      msg "LMSmonitor starting"             
      sudo /mnt/mmcblk0p2/tce/lmsmonitor -n $PNAME -z -s -c -f7 & # -c -f7
      #> /dev/null 2>&1 & # -z
      sleep 3
      msg "LMSmonitor started, pid $(pidof lmsmonitor)"
    } # function StartMonitor
    
    function cleanup () { 
      if [ $PlayGPIO = "0" ]; then # green onboard led0
        mySudo "echo mmc0 >$BASE_LED0_PATH/trigger" 
      else 
        if [ -e $BASE_GPIO_PATH/gpio$PlayGPIO ]; then # GPIO initialized    
          mySudo "echo $((!$PlayVal)) > $BASE_GPIO_PATH/gpio$PlayGPIO/value" # Set to off state
          mySudo "echo $PlayGPIO > $BASE_GPIO_PATH/unexport"
        fi # GPIO de-initialized
      fi # led0 or GPIO
      if $monitor; then    
        #StartMonitor 
        KillMonitor # Will not do a complete clean screen on reboot, but reboot is no normal operation
      fi 
      
      exit 0 
    } # on Exit
    
    function Usage () {
      echo ""
      echo "PlayMode to GPIO ($ScriptName) sets a GPIO when squeezelite is playing."
      echo "--------------------------------------------------------------------"
      echo "Usage: $0 [-g GPIO] [-s n] [-f] [-v] [-b] [-k] [-h]"
      echo ""
      echo "-g : GPIO-number play mode, if not given, green onboard (led0) will be used"
      echo "-s : GPIO-value for play mode [0,1], if not given [1] will be used"
      echo "-f : run in foreground with verbose output"
      echo "-v : verbose output from background"
      echo "-b : blink mode, GPIO is blinking when playing, on on pause"    
      echo "-m : lmsmonitor, handles lmsmonitor"
      echo "-k : Kill running $ScriptName" 
      echo "-h : Shows this help"
      echo ""
      echo "Examples:"
      echo "---------"
      echo "  $0             : Green onboard LED (led0) on when playing"
      echo "  $0 -b          : Green onboard LED (led0) blinking when playing, on when paused"
      echo "  $0 -g27        : Sets GPIO27 to 3V when playing"  
      echo "  $0 -g27 -b     : Sets GPIO27 to 3V, blinking when playing, on when pause"
      echo "  $0 -g4  -s0 -f : Sets GPIO4  to 0V when playing, running in foreground with output (debug)"
      echo "  $0 -g4  -s1 -v : Sets GPIO4  to 3V when playing, running in background with output (debug)"
      echo "  $0 -k          : Kills running $ScriptName"  
      echo ""
    exit 1
    } # function Usage
    
    function Loop () { 
      trap cleanup INT TERM # cleanup GPIO and Monitor on exit
      while true; do  
        MODE=`pcp mode 2> /dev/null`    
        if [ ! "$MODE" = "$OldMode" ]; then # MODE change
          if [ ! "$MODE" ]; then MODE="not available"; fi # no result, wget error
          msg "pcp mode is \"$MODE\"."
          if [ "$MODE" = "play" ] || [ "$MODE" = "pause" ] || [ "$MODE" = "stop" ] || [ "$MODE" = "not available" ]; then # valid or empty MODE
    
            # GPIO
            if [ "$MODE" = "play" ]; then 
              GPIOval=$PlayVal; # on
            elif $blink && [ "$MODE" = "pause" ]; then 
              GPIOval=$PlayVal # on
            else
              GPIOval=$((!$PlayVal)) # off
            fi # Set static GPIOval
    
            # LMSmonitor
            if $monitor; then
              if [ "$MODE" = "play" ] || [ "$MODE" = "pause" ]; then #
                MonitorState=1
                msg "MonitorState=1"
              else  
                MonitorState=0
                msg "MonitorState=0"
              fi
            fi
          else # unknown MODE
            msg "\"pcp mode\" results to unknown mode \"$MODE\", should be play, pause, stop"                 
          fi # valid/invalid MODE
          
          OldMode=$MODE
        fi # MODE change       
        
        # blink on play when -b
        if $blink && [ "$MODE" = "play" ]; then GPIOval="$((!$GPIOval))"; fi # invert, blinking                       
                
        if [ ! "$GPIOval" = "$oldGPIOval" ]; then # GPIO val change
          if ! $blink; then msg "Set GPIO$PlayGPIO to $GPIOval."; fi # Debug output only when no GPIO change for blinking
          if [ $PlayGPIO = "0" ]; then # led0
            mySudo "echo $GPIOval > $BASE_LED0_PATH/brightness"
          else # GPIO
            mySudo "echo $GPIOval > $BASE_GPIO_PATH/gpio$PlayGPIO/value"
          fi
          oldGPIOval=$GPIOval
        fi # GPIO val change 
        
        if [ ! "$MonitorState" = "$oldMonitorState" ]; then # Change Monitorstate, don't ask!
           if [ "$MonitorState" = "1" ]; then # needs some help :-)
             StartMonitor 
             if [ "$oldMonitorState" = "0" ]; then 
               StartMonitor
               StartMonitor
             fi # Kommt aus vorher gestopptem off-Status, braucht dann Nachhilfe
           else
             StartMonitor
             KillMonitor
           fi # dont ask :-)    
           oldMonitorState=$MonitorState
        fi # Change Monitorstate
        sleep 0.5 # Loop interval
      done # while true
    } # function Loop
    
    ############
    ### Main ###
    ############
    
    # Parameter
    # ---------
    # Defaults
    PlayGPIO=0 # Default: Green onboard led0
    PlayVal=1 # default active high
    foreground=false # no more need to foreground
    verbose=false # no output from loop when daemonized
    blink=false # stay active
    monitor=false # LMSmonitor nicht starten
    oldGPIOval=0
    oldMonitorState=-1 # LMSmonitor: 0=off 1=running -1=unknown/after start
    
    while getopts g:s:fvbmkh opt 
    do 
      case $opt in
        g ) # Check for valid Play GPIO
            if [ "$OPTARG" -ge 2 ] && [ "$OPTARG" -le 27 ] 
              then PlayGPIO=$OPTARG
              else err "Play GPIO \"$OPTARG\" is not a valid GPIO, please use 2 .. 27"; fi # Check for valid GPIO
          ;;
        s ) # Check parameter for setting GPIO to 0 or 1 when playing
            if [ $OPTARG ]; then # Set GPIO to 0 or 1 when playing
              if [ "$OPTARG" -eq 0 ] || [ "$OPTARG" -eq 1 ] 
                then PlayVal=$OPTARG 
                else err "Play-value \"$OPTARG\" is not a valid GPIO state, please use 0 or 1"; fi
            fi # Check parameter for setting GPIO to 0 or 1 when playing
          ;;
        f ) foreground=true;;
        v ) verbose=true;;
        b ) blink=true;;
        m ) monitor=true;;
        k ) msg "Killing running instance."; sudo killall -15 $ScriptName;;        
        h ) Usage;;
        [?]) Usage;;
      esac
    done
    
    # Kill old instance, if exists
    for pid in $(pidof $ScriptName); do    
      if [ ! $pid = $$ ]; then
        msg "Killing old instance (pid $pid) of $ScriptName"
        mySudo "kill -15 $pid"
        sleep 0.3 # Give the exit routine some time. on pi 3b+ 0.1s is enough
      fi # old instance found     
    done # Kill old instance
    
    # Init
    # ----
    # Wait for squeezelite to come online
    wt=0
    until pids=$(pidof squeezelite squeezelite-dsd); do
      sleep 1; wt=$(($wt+1))
      msg "Waited $wt seconds for for squeezelite ..." 
      if [ "$wt" -ge 60 ]; then err "Waited too long for squeezelite"; fi
    done
    
    # Init GPIO
    if [ $PlayGPIO = "0" ]; then # led0
      msg "Disable mmc0 trigger on led0"
      mySudo "echo none >$BASE_LED0_PATH/trigger"
    else # GPIO
      if [ ! -e $BASE_GPIO_PATH/gpio$PlayGPIO ]; then # Init GPIO
        msg "Export GPIO$PlayGPIO to userspace"
        mySudo "echo $PlayGPIO > $BASE_GPIO_PATH/export"
      fi # Init GPIO
      msg "Set GPIO$PlayGPIO as an output"
      mySudo "echo out > $BASE_GPIO_PATH/gpio$PlayGPIO/direction"
    fi # led0 or GPIO
    
    # This player Name (for LMSmonitor) 
    if $monitor; then
        PNAME=`cat /usr/local/sbin/config.cfg | grep "^NAME=" | cut -d'"' -f2` 
    fi
    
    # Call Loop
    # ----------
    if $foreground; then # foreground:
      msg "Foreground loop polling, with output. Stop with \"ctrl-c\"."
      Loop
    else # daemonize
      if $verbose; then # Background loop polling with output
        msg "Background loop polling with output. Stop with \"$0 -k\" or restart of script." 
        Loop &
      else # Background loop polling 
        msg "Background loop polling. Stop with \"sudo $0 -k\" or restart of script." 
        Loop > /dev/null 2>&1 &
      fi # Background loop polling
    fi # Start fore- or background loop polling
    exit
    # End of Program
    The lmsmontor part is a little crazy, slow and fragil, but found no other way. Beta but working. Don't do power on - off too fast :-)
    Last edited by Aki7; 2021-01-15 at 16:24.

  3. #223
    Junior Member
    Join Date
    Jan 2021
    Posts
    6
    Quote Originally Posted by shunte88 View Post
    @LiFePO4

    with the deskpi Pro I routed a channel then slotted the 128x32 into it, had I been careful that should have been all I needed but ended up using some damping material to hold it secure and reduce the light bleed too

    easiest thing I've found for screw mounts is to solder the unit to perf-board large enough such that it can contain any circuitry but also with enough meat to drill fixing holes etc

    you can also get fancy with 3D printing and/or CNC
    Nothing fancy for my use case. I was always planning on a headless setup, but noticed the Pirate Audio thread and thought that was pretty cool. But it's a bit heavy and I just want something a bit more simple. Sort of like running a Linux GUI desktop versus a minimalist Linux build. I rather just focus on a iPeng solution if I want that much functionality. Of course preference for OLED. So this is just icing, not really planned.

    Thanks for the suggestion, but this will be 100% custom build. I'm running power sensitive desktop RPi HATs and don't want wires sticking out and short circuiting so only certain non-standard cases work for my situation. Since these are desktop HATs not meant for portable, I have to abstract as much as possible. I'm also running a custom LiFePO4 battery since they provide the best audio performance, not a regular battery.

    I'm using something like this:

    Name:  UTB8JaUkfgnJXKJkSaelq6xUzXXa1.jpg
Views: 35
Size:  31.1 KB

    Since I will be using the case sideways, I like to attach an OLED on the side. I plan to put the OLED outside the case with mounting holes. The 128x32 would go well on the bottom, but there's no more room inside the case to drill holes. I only have room to drill holes on the clear section.

    Name:  UTB8u6GnyOaMiuJk43PTq6ySmXXaj.jpg
Views: 34
Size:  114.6 KB

    The OLED may work similarly to the case above with "12.4" above the word "Application" but I'm targeting the side of the case for now.

    Since this is the first prototype, adjustments like replacing with a 128x32 later on might work out. But for now the 128x64 will have to do... Crossing fingers....
    Last edited by LiFePO4; 2021-01-15 at 19:46.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •