Pastebin launched a little side project called HostCabi.net, check it out ;-)Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 25th, 2011  |  syntax: Bash  |  size: 2.36 KB  |  hits: 1,761  |  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=10 # How many pages before a full refresh?
  4.  
  5. ### Do not edit below this line unless you know what you are doing ###
  6.  
  7. ## Get cvm PID
  8. read cvmPid < /var/run/cvm.pid
  9. if [[ -z "$cvmPid" ]]; then
  10.         echo "cvm isn't running..."
  11.         exit 2
  12. fi
  13.  
  14. pCount=0
  15. fullPage="$(($fullPage-1))"
  16.  
  17. if [[ ! -e "/var/run/flashDis.pid" ]]; then
  18.         echo $$ > "/var/run/flashDis.pid"
  19. else
  20.         echo "Flash disabler is already running"
  21.         exit 1
  22. fi
  23.  
  24. trap "enableFlash ; rm /var/run/flashDis.pid ; exit" SIGINT SIGTERM
  25.  
  26. update() {
  27.         waitForEink
  28.         ## Do some fancy stuff to make the page look decent
  29.         echo 19 0 > /proc/eink_fb/update_display
  30.         echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  31.         echo 18 0 > /proc/eink_fb/update_display
  32.         echo 1 > /sys/devices/platform/eink_fb.0/override_upd_mode
  33.         echo 19 4 > /proc/eink_fb/update_display
  34.        
  35.         ## Sets the next page turn to be a full refresh
  36.         let pCount+=1
  37.         if [[ "$pCount" -ge "$fullPage" ]]; then
  38.                 echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  39.                 echo 19 0 > /proc/eink_fb/update_display
  40.                 pCount=0
  41.         fi     
  42. }
  43.  
  44. enableFlash() {
  45.         echo 0 > /sys/devices/platform/eink_fb.0/override_upd_mode
  46.         echo 19 0 > /proc/eink_fb/update_display
  47. }
  48.  
  49. ## Check if we need to look for a book/check if current book is open
  50. bookCheck() {
  51.         if [[ -n "$fd" -a -n "$book" ]]; then
  52.                 if [[ "$(realpath /proc/$cvmPid/fd/$fd 2> /dev/null)" == "$book" ]]; then
  53.                         if [[ "$bookType" != "BAD" ]]; then
  54.                                 update
  55.                         else
  56.                                 enableFlash
  57.                         fi
  58.                 else
  59.                         book=""
  60.                         bookType=""
  61.                         findBook
  62.                 fi
  63.         else
  64.                 findBook
  65.         fi
  66. }
  67.  
  68. ## Check if cvm has a file descriptor open in /mnt/us/documents
  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. ## Check if /var/log/messages has changed within the last second
  87. waitForEink() {
  88.         c=1
  89.         while [[ "$(stat -c %Y /var/log/messages)" -lt "$time" -a "$c" -lt "10" ]]; do
  90.                 let c+=1
  91.                 usleep 100000
  92.         done
  93. }
  94.  
  95. ## Wait for page turn
  96. while :; do
  97.         case "$(waitforkey)" in
  98.                 191*|109*|104*|193*)
  99.                         time="$(($(date +%s)-1))"
  100.                         bookCheck
  101.                 ;;
  102.         esac
  103.         usleep 100000
  104. done