Home of the Squeezebox™ & Transporter® network music players.
Page 4 of 4 FirstFirst ... 234
Results 31 to 37 of 37
  1. #31
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    3,359
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  2. #32
    Oops, that is a bit embarrassing!
    I have definitely seen and read your post but I forgot it because I didn't need it.
    Thanks, Paul. The "power" part is exactly what we need.

  3. #33
    @WadDad,

    you can try the following script:

    Code:
    #!/bin/sh
    
    # Enabling some useful piCorePlayer functions
    . /var/www/cgi-bin/pcp-functions
    . /var/www/cgi-bin/pcp-lms-functions
    
    WDIR=/home/tc/lux
    # if the measured value is below MIN_THRESHOLD then the display is set to MIN_BRIGHTNESS
    MIN_THRESHOLD=1
    MIN_BRIGHTNESS=20      # minimum display brightness if piCorePlayer is running
    MIN_BRIGHTNESS_OFF=10  # minimum display brightness if piCorePlayer is switched off
    # if the measured value is above MAX_THRESHOLD then the display is set to MAX_BRIGHTNESS
    MAX_THRESHOLD=400
    MAX_BRIGHTNESS=255      # maximum display brightness if piCorePlayer is running
    MAX_BRIGHTNESS_OFF=150  # maximum display brightness if piCorePlayer is switched off
    
    # Calculation of some variables
    # a) if piCorePlayer is running
    LUX_RANGE=$(echo "$MAX_THRESHOLD-$MIN_THRESHOLD" | bc)
    BRIGHTNESS_RANGE=$(echo "$MAX_BRIGHTNESS-$MIN_BRIGHTNESS" | bc)
    STEPSIZE=$(echo "scale=2 ; $LUX_RANGE/$BRIGHTNESS_RANGE" | bc -l | cut -f1 -d\.);
    # b) if piCorePlayer is switched off
    BRIGHTNESS_RANGE_OFF=$(echo "$MAX_BRIGHTNESS_OFF-$MIN_BRIGHTNESS_OFF" | bc)
    STEPSIZE_OFF=$(echo "scale=2 ; $LUX_RANGE/$BRIGHTNESS_RANGE_OFF" | bc -l | cut -f1 -d\.);
    
    # time interval between two measurements
    INTERVAL=5
    
    # Let's wait until pCP is up & running
    sleep 20
    
    
    while true; do
      # Measuring the current LUX value
      LUX=$($WDIR/lux)
    
      # Determining state of piCorePlayer (on/off)
      REQUEST=$(pcp_lms_build_request "$NAME" "status -")
      RESULT=$(pcp_lms_build_result result "power")
      PCP_STATE=$(pcp_lms_json_request)
    
      # Calculating the target brightness of the display
      # a) if piCorePlayer is running
      if [ $PCP_STATE -eq "1" ]; then
        if [ $LUX -lt $MIN_THRESHOLD ]; then
          TRGT=$MIN_BRIGHTNESS
        elif [ $LUX -gt $MAX_THRESHOLD ]; then
          TRGT=$MAX_BRIGHTNESS
        else
          TRGT=$(echo "$MIN_BRIGHTNESS+(($LUX-$MIN_THRESHOLD)/$STEPSIZE)" | bc -l | cut -f1 -d\.);
        fi
      # b) if piCorePlayer is switched off
      elif [ $PCP_STATE -eq "0" ]; then
        if [ $LUX -lt $MIN_THRESHOLD ]; then
          TRGT=$MIN_BRIGHTNESS_OFF
        elif [ $LUX -gt $MAX_THRESHOLD ]; then
          TRGT=$MAX_BRIGHTNESS_OFF
        else
          TRGT=$(echo "$MIN_BRIGHTNESS_OFF+(($LUX-$MIN_THRESHOLD)/$STEPSIZE_OFF)" | bc -l | cut -f1 -d\.);
        fi
      else
        # error
        exit 1
      fi
    
    
        # Setting the brightness value of the display
        echo $TRGT > /sys/class/backlight/rpi_backlight/brightness
    
    
        # Uncomment for debugging & testing
    #    echo $LUX
    #    echo $TRGT
    
    
        # Wait some seconds before the next calculation
        sleep $INTERVAL
    done
    The script defines new variables (ending with "_OFF") for the use case when pCP is switched off. These new variables are later used to calculate the display brightness when pCP is not running. Hence, you can play with these variables to get the result your are looking for.
    Last edited by jd68; 2020-08-05 at 00:43. Reason: fixing errors/typos in shell script

  4. #34
    Member
    Join Date
    Jul 2015
    Location
    Russia
    Posts
    61
    Sorry friends, but my English is not so good. I see one problem.
    Script not working now. No brightness changes.
    output if uncomment that two strings:
    Code:
    tc@piCorePlayer:~/lux$ ./display-control.sh
    ./display-control.sh: line 60: syntax error: unexpected "else" (expecting "fi")
    Last edited by WadDad; 2020-08-04 at 11:56. Reason: Google helps.

  5. #35
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    1,916
    That means there is a problem with your "if-else-elif-fi" statements.

  6. #36
    Sorry, my fault. I should have tested the script before posting it. I only tested that the check for the power state is working as expected.

    I have added the missing "fi" into the script and fixed a typo of a variable in my post #33.

  7. #37
    Member
    Join Date
    Jul 2015
    Location
    Russia
    Posts
    61
    Thank you very very much. Now all right.

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
  •