@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_OF-$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\.);
  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.


------------------------------------------------------------------------
jd68's Profile: http://forums.slimdevices.com/member.php?userid=30795
View this thread: http://forums.slimdevices.com/showthread.php?t=112460

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to