Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 24th, 2011  |  syntax: Bash  |  size: 2.07 KB  |  views: 293  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. fullPage=6 # How many pages before a full refresh?
  4.  
  5. ### Do not edit below this line unless you know what you are doing ###
  6.  
  7. read cvmPid < /var/run/cvm.pid
  8. if [[ -z "$cvmPid" ]]; then
  9.         echo "cvm isn't running..."
  10.         exit 2
  11. fi
  12.  
  13. pCount=0
  14. fullPage="$(($fullPage-1))"
  15.  
  16. if [[ ! -e "/var/run/flashDis.pid" ]]; then
  17.         echo $$ > "/var/run/flashDis.pid"
  18. else
  19.         echo "Flash disabler is already running"
  20.         exit 1
  21. fi
  22.  
  23. trap "enableFlash ; rm /var/run/flashDis.pid ; exit" SIGINT SIGTERM
  24.  
  25. update() {
  26.         let pCount+=1
  27.         ## Do a bunch of refreshes
  28.         for i in 1 2 3 4 5 6 7 8 9 10 ; do
  29.                 usleep 150000
  30.                 echo 19 0 > /proc/eink_fb/update_display
  31.                 echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  32.                 echo 18 0 > /proc/eink_fb/update_display
  33.                 echo 1 > /sys/devices/platform/eink_fb.0/override_upd_mode
  34.                 echo 19 4 > /proc/eink_fb/update_display
  35.         done
  36.        
  37.         ## Sets the next page turn to be a full refresh
  38.         if [[ "$pCount" -ge "$fullPage" ]]; then
  39.                 echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  40.                 echo 19 0 > /proc/eink_fb/update_display
  41.                 pCount=0
  42.         fi     
  43. }
  44.  
  45. enableFlash() {
  46.         echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  47.         echo 19 0 > /proc/eink_fb/update_display
  48. }
  49.  
  50. bookCheck() {
  51.         ## Check if cvm has a open file descriptor for a file in /mnt/us/documents/
  52.         if [[ -n "$fd" -a -n "$book" ]]; then
  53.                 if [[ "$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)" == "$book" ]]; then
  54.                         if [[ "$bookType" != "BAD" ]]; then
  55.                                 update
  56.                         else
  57.                                 enableFlash
  58.                         fi
  59.                 else
  60.                         book=""
  61.                         bookType=""
  62.                         findBook
  63.                 fi
  64.         else
  65.                 findBook
  66.         fi
  67. }
  68.  
  69. findBook() {
  70.         enableFlash
  71.         fd="$(ls -l /proc/$cvmPid/fd/ | awk '/\/mnt\/us\/documents\// {print $9}')"
  72.         if [[ -n "$fd" ]]; then
  73.                 book="$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)"
  74.                 bookType="${book##*.}"
  75.                 case $bookType in
  76.                         [Mm][Oo][Bb][Ii]|[Pp][Dd][Ff]|[Pp][Rr][Cc]|[Aa][Zz][Ww]*|[Tt][Xx][Tt])
  77.                                 update
  78.                         ;;
  79.                         *)
  80.                                 bookType="BAD"
  81.                         ;;
  82.                 esac
  83.         fi
  84. }
  85.  
  86. ## Wait for page turn
  87. while :; do
  88.         case "$(waitforkey)" in
  89.                 191*|109*|104*|193*)
  90.                         bookCheck
  91.                 ;;
  92.         esac
  93.         usleep 100000
  94. done
clone this paste RAW Paste Data